diff --git a/.run/Emulator Deploy.run.xml b/.run/Emulator Deploy.run.xml new file mode 100644 index 0000000..63dd083 --- /dev/null +++ b/.run/Emulator Deploy.run.xml @@ -0,0 +1,19 @@ + + + + \ No newline at end of file diff --git a/.run/Emulator Run Dev.run.xml b/.run/Emulator Run Dev.run.xml new file mode 100644 index 0000000..b25fcbb --- /dev/null +++ b/.run/Emulator Run Dev.run.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/firebase.json b/firebase.json index cac788e..5fc39b9 100644 --- a/firebase.json +++ b/firebase.json @@ -20,6 +20,12 @@ "ui": { "enabled": true }, - "singleProjectMode": true + "singleProjectMode": true, + "auth": { + "port": 9099 + }, + "firestore": { + "port": 8080 + } } } diff --git a/package-lock.json b/package-lock.json index a5481bb..eae137a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "dependencies": { "@types/papaparse": "^5.3.14", "bootstrap": "^5.3.3", - "firebase": "^10.6.0", + "firebase": "^10.11.0", "papaparse": "^5.4.1", "react": "^18.2.0", "react-bootstrap": "^2.10.2", @@ -21,6 +21,7 @@ "sass": "^1.72.0" }, "devDependencies": { + "@faker-js/faker": "^8.4.1", "@types/react": "^18.2.66", "@types/react-dom": "^18.2.22", "@typescript-eslint/eslint-plugin": "^7.2.0", @@ -499,6 +500,22 @@ "node": "^12.22.0 || ^14.17.0 || >=16.0.0" } }, + "node_modules/@faker-js/faker": { + "version": "8.4.1", + "resolved": "https://registry.npmjs.org/@faker-js/faker/-/faker-8.4.1.tgz", + "integrity": "sha512-XQ3cU+Q8Uqmrbf2e0cIC/QN43sTBSC8KF12u29Mb47tWrt2hAgBXSgpZMj4Ao8Uk0iJcU99QsOCaIL8934obCg==", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/fakerjs" + } + ], + "engines": { + "node": "^14.17.0 || ^16.13.0 || >=18.0.0", + "npm": ">=6.14.13" + } + }, "node_modules/@fastify/busboy": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.1.1.tgz", diff --git a/package.json b/package.json index 183c1fb..4801037 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "dependencies": { "@types/papaparse": "^5.3.14", "bootstrap": "^5.3.3", - "firebase": "^10.6.0", + "firebase": "^10.11.0", "papaparse": "^5.4.1", "react": "^18.2.0", "react-bootstrap": "^2.10.2", @@ -23,6 +23,7 @@ "sass": "^1.72.0" }, "devDependencies": { + "@faker-js/faker": "^8.4.1", "@types/react": "^18.2.66", "@types/react-dom": "^18.2.22", "@typescript-eslint/eslint-plugin": "^7.2.0", diff --git a/src/components/Header.tsx b/src/components/Header.tsx index 28b7cb5..1daa3e5 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -1,5 +1,6 @@ import useWindowDimensions from "../hooks/WindowDimensionsHook.tsx"; import "../assets/css/Header.css" +import {Link} from "react-router-dom"; interface Props { user?: string @@ -18,15 +19,17 @@ export function Header({user} : Props) { {/*Pages*/} - ; } \ No newline at end of file diff --git a/src/main.tsx b/src/main.tsx index a300453..a1fb6fd 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -1,6 +1,7 @@ import React from 'react' import ReactDOM from 'react-dom/client' import './utils/firebase.ts' +import './utils/firestore.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 new file mode 100644 index 0000000..ba10d12 --- /dev/null +++ b/src/pages/test firestore/TestFirestore.tsx @@ -0,0 +1,110 @@ +import {FullscreenCenter} from "../../components/FullscreenCenter.tsx"; +import {auth} from "../../utils/firebase.ts"; +import {useState} from "react"; +import { + deleteTransaction, + getTransactionsFilterOrderBy, + overwriteTransaction, + Transaction, + writeNewTransaction +} from "../../utils/firestore.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"; + +function writeSampleData() { + if (auth.currentUser === null) { + console.log("No User"); + return; + } + + console.log("Adding sample data"); + const t = new Transaction( + fakerEN_GB.location.streetAddress() + ", " + fakerEN_GB.location.city() + ", " + fakerEN_GB.location.zipCode(), + parseFloat(faker.finance.amount({min: -1000, max: 1000})), + faker.word.noun(), + faker.finance.currency().code, + faker.date.past().valueOf(), + faker.lorem.sentence(), + faker.internet.emoji(), + faker.word.noun(), + faker.lorem.sentence(), + auth.currentUser.uid + ); + + writeNewTransaction(auth.currentUser, t).then((t) => {console.log("Added sample data:"); console.log(t);}) +} + + +export function TestFirestorePage() { + const [authResolved, setAuthResolved] = useState(false); + const [transactions, setTransactions] = useState([]); + const [balance, setBalance] = useState(0); + const [update ,setUpdate] = useState(0); + + if (!authResolved) { + auth.authStateReady().then(() => setAuthResolved(true)); + return <> + +
+

Waiting for Auth

+
+
+ ; + } + + if (auth.currentUser === null) { + return <> +
+ +
+

Not Logged In

+ +
+
+ ; + } + + getTransactionsFilterOrderBy(auth.currentUser, orderBy("dateTime", "desc")).then((t) => setTransactions(t)); + getCurrentBalance(auth.currentUser).then((b) => setBalance(b)); + + return ( + <> +
+
+

Logged In - {auth.currentUser.uid} - {auth.currentUser.displayName}

+ +
+ +

+ Balance: {balance} +

+

+ Transactions:
+

+ { + transactions.map((t) =>
+

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

+