-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from Robert-M-Lucas/dev-SCRUM-64
Dev scrum 64
- Loading branch information
Showing
12 changed files
with
420 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="Emulator Deploy" type="ShConfigurationType"> | ||
<option name="SCRIPT_TEXT" value="firebase emulators:start --project=budget-19" /> | ||
<option name="INDEPENDENT_SCRIPT_PATH" value="true" /> | ||
<option name="SCRIPT_PATH" value="" /> | ||
<option name="SCRIPT_OPTIONS" value="" /> | ||
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" /> | ||
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$" /> | ||
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" /> | ||
<option name="INTERPRETER_PATH" value="/usr/bin/zsh" /> | ||
<option name="INTERPRETER_OPTIONS" value="" /> | ||
<option name="EXECUTE_IN_TERMINAL" value="false" /> | ||
<option name="EXECUTE_SCRIPT_FILE" value="false" /> | ||
<envs> | ||
<env name="FIREBASE_AUTH_EMULATOR_HOST" value="127.0.0.1" /> | ||
</envs> | ||
<method v="2" /> | ||
</configuration> | ||
</component> |
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,7 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="Emulator Run Dev" type="CompoundRunConfigurationType"> | ||
<toRun name="dev" type="js.build_tools.npm" /> | ||
<toRun name="Emulator Deploy" type="ShConfigurationType" /> | ||
<method v="2" /> | ||
</configuration> | ||
</component> |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
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,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<Transaction[]>([]); | ||
const [balance, setBalance] = useState(0); | ||
const [update ,setUpdate] = useState(0); | ||
|
||
if (!authResolved) { | ||
auth.authStateReady().then(() => setAuthResolved(true)); | ||
return <> | ||
<FullscreenCenter> | ||
<div className="text-center"> | ||
<h1>Waiting for Auth</h1> | ||
</div> | ||
</FullscreenCenter> | ||
</>; | ||
} | ||
|
||
if (auth.currentUser === null) { | ||
return <> | ||
<Header/> | ||
<FullscreenCenter> | ||
<div className="text-center"> | ||
<h1>Not Logged In</h1> | ||
<button type="button" className="login-with-google-btn" onClick={signInWithGoogle}> | ||
Sign in with Google | ||
</button> | ||
</div> | ||
</FullscreenCenter> | ||
</>; | ||
} | ||
|
||
getTransactionsFilterOrderBy(auth.currentUser, orderBy("dateTime", "desc")).then((t) => setTransactions(t)); | ||
getCurrentBalance(auth.currentUser).then((b) => setBalance(b)); | ||
|
||
return ( | ||
<> | ||
<Header/> | ||
<div className="text-center"> | ||
<h1>Logged In - {auth.currentUser.uid} - {auth.currentUser.displayName}</h1> | ||
<button type="button" className="login-with-google-btn" onClick={signInWithGoogle}> | ||
Sign in with Google | ||
</button> | ||
</div> | ||
<button onClick={() => { | ||
writeSampleData(); | ||
setUpdate(update + 1); | ||
}}>Add Sample Transaction | ||
</button> | ||
<p> | ||
Balance: {balance} | ||
</p> | ||
<p> | ||
Transactions: <br/> | ||
</p> | ||
{ | ||
transactions.map((t) => <div className="mb-4" key={t.forceGetDocName()}> | ||
<p className="m-0">{new Date(t.dateTime).toISOString()}</p> | ||
<textarea readOnly={true} style={{width: "100%", height: "320px"}} value={JSON.stringify(t, null, 4)}/> | ||
<button onClick={() => {deleteTransaction(t.forceGetDocName()).then(() => setUpdate(update + 1))}}>Delete</button> | ||
<button onClick={() => { | ||
if (auth.currentUser != null) { | ||
t.dateTime = new Date(Date.now()).valueOf(); | ||
overwriteTransaction(auth.currentUser, t.forceGetDocName(), t).then(() => setUpdate(update + 1)); | ||
} | ||
}}>Set Time To Now</button> | ||
</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
Oops, something went wrong.