From 47c0405012e2110c3f05a648bb20a2b1d51fbaeb Mon Sep 17 00:00:00 2001 From: Robert Lucas <100799838+Robert-M-Lucas@users.noreply.github.com> Date: Thu, 25 Apr 2024 12:23:41 +0100 Subject: [PATCH] Added a test page for UserPrefs --- src/pages/test firestore/TestFirestore.tsx | 64 ++++++++++++++++------ src/utils/user_prefs.ts | 3 +- 2 files changed, 47 insertions(+), 20 deletions(-) diff --git a/src/pages/test firestore/TestFirestore.tsx b/src/pages/test firestore/TestFirestore.tsx index a92d27f..434b0f4 100644 --- a/src/pages/test firestore/TestFirestore.tsx +++ b/src/pages/test firestore/TestFirestore.tsx @@ -13,6 +13,8 @@ import {getCurrentBalance} from "../../utils/transaction_utils.ts"; import {signInWithGoogle} from "../../utils/authentication.ts"; import {Header} from "../../components/Header.tsx"; import { orderBy } from "firebase/firestore"; +import {User} from "firebase/auth"; +import {getUserPrefs, setUserPrefs, UserPrefs} from "../../utils/user_prefs.ts"; function writeSampleData() { if (auth.currentUser === null) { @@ -43,6 +45,8 @@ export function TestFirestorePage() { const [transactions, setTransactions] = useState([]); const [balance, setBalance] = useState(0); const [update ,setUpdate] = useState(0); + const [user, setUser] = useState(undefined); + const [userPrefs, _setUserPrefs] = useState(null); if (!authResolved) { auth.authStateReady().then(() => setAuthResolved(true)); @@ -56,6 +60,11 @@ export function TestFirestorePage() { } if (auth.currentUser === null) { + auth.onAuthStateChanged((new_user: User | null) => { + if (new_user !== null && new_user.uid !== user) { + setUser(new_user.uid) + } + }); return <>
@@ -71,6 +80,7 @@ export function TestFirestorePage() { getTransactionsFilterOrderBy(auth.currentUser, orderBy("dateTime", "desc")).then((t) => setTransactions(t)); getCurrentBalance(auth.currentUser).then((b) => setBalance(b)); + getUserPrefs(auth.currentUser).then((up) => _setUserPrefs(up)); return ( <> @@ -81,30 +91,48 @@ export function TestFirestorePage() { Sign in with Google - + :

Loading

+ } + +

+ Transactions +

+

+ Balance: {balance} +

+ -

- Balance: {balance} -

-

- Transactions:
-

{ transactions.map((t) =>
-

{new Date(t.dateTime).toISOString()}

-