-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9942261
commit 8a7fa6a
Showing
7 changed files
with
97 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 27 additions & 7 deletions
34
tests/react-providerx-test-app/src/pages/HomePage/homePage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,40 @@ | ||
import { useProvider } from "react-providerx"; | ||
import { refresh, useProvider } from "react-providerx"; | ||
import { signOut } from "../../services/auth"; | ||
import { authStateProvider$ } from "../../shared/authState"; | ||
import { userDataPromiseProvider$ } from "../../shared/userData"; | ||
|
||
const SubComponent: React.FC = () => { | ||
const { isLoading, data: userData } = useProvider(userDataPromiseProvider$) | ||
if(isLoading) { | ||
return <div className="App"> | ||
Loading... | ||
</div> | ||
} | ||
return ( | ||
<div className="App"> | ||
{(userData as any).email} | ||
</div> | ||
); | ||
} | ||
|
||
export const HomePage: React.FC = () => { | ||
const { isLoading, data: user } = useProvider(authStateProvider$) | ||
const { isLoading, data: userData } = useProvider(userDataPromiseProvider$) | ||
if(isLoading) { | ||
return <div className="App"> | ||
Loading... | ||
</div> | ||
} | ||
return ( | ||
<div className="App"> | ||
{(user as any).displayName} | ||
<button onClick={signOut}> | ||
Click to Sign Out | ||
</button> | ||
{(userData as any).email} | ||
<div className="col"> | ||
<button onClick={() => refresh(userDataPromiseProvider$)}> | ||
Click to Refresh User Data | ||
</button> | ||
<button onClick={signOut}> | ||
Click to Sign Out | ||
</button> | ||
</div> | ||
<SubComponent /> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,10 @@ | ||
import { ObservableProvider } from "react-providerx"; | ||
import { authState } from 'rxfire/auth' | ||
import { map, tap } from 'rxjs/operators' | ||
import { map } from 'rxjs/operators' | ||
import { auth } from "../utils/firebase"; | ||
|
||
export const authStateProvider$ = new ObservableProvider(() => { | ||
return authState(auth).pipe( | ||
map(u => u === null ? 'not-logged-in': u), | ||
tap(result => { | ||
console.log('the value of result is') | ||
console.log(result) | ||
}) | ||
map(u => u === null ? 'not-logged-in': u) | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { ObservableProvider } from "react-providerx"; | ||
import { of } from "rxjs"; | ||
import { doc } from 'rxfire/firestore'; | ||
import { map, switchMap, tap } from "rxjs/operators"; | ||
import { db } from "../utils/firebase"; | ||
import { authStateProvider$ } from "./authState"; | ||
|
||
export const userDataPromiseProvider$ = new ObservableProvider(() => { | ||
const userDataObservable = authStateProvider$.observable.pipe( | ||
switchMap(result => { | ||
if(result === null || result === 'not-logged-in') { | ||
return of(null) | ||
} | ||
else { | ||
return doc(db.doc(`users/${result.uid}`)).pipe( | ||
map(ds => ds.data()), | ||
tap(userData => { | ||
console.log('Got userData: ') | ||
console.log(userData) | ||
}) | ||
) | ||
} | ||
}) | ||
) | ||
return userDataObservable | ||
}) |