diff --git a/src/main.tsx b/src/main.tsx index a1fb6fd..084976b 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -1,7 +1,7 @@ import React from 'react' import ReactDOM from 'react-dom/client' import './utils/firebase.ts' -import './utils/firestore.ts' +import './utils/transaction.ts' import {RouterProvider} from "react-router-dom"; import {router} from "./router.tsx"; diff --git a/src/pages/test firestore/TestFirestore.tsx b/src/pages/test firestore/TestFirestore.tsx index ba10d12..434b0f4 100644 --- a/src/pages/test firestore/TestFirestore.tsx +++ b/src/pages/test firestore/TestFirestore.tsx @@ -7,12 +7,14 @@ import { overwriteTransaction, Transaction, writeNewTransaction -} from "../../utils/firestore.ts"; +} from "../../utils/transaction.ts"; import {faker, fakerEN_GB} from "@faker-js/faker"; 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()}

-