diff --git a/src/pages/test firestore/TestFirestore.tsx b/src/pages/test firestore/TestFirestore.tsx
index c569717..ba10d12 100644
--- a/src/pages/test firestore/TestFirestore.tsx
+++ b/src/pages/test firestore/TestFirestore.tsx
@@ -3,7 +3,7 @@ import {auth} from "../../utils/firebase.ts";
import {useState} from "react";
import {
deleteTransaction,
- getTransactions,
+ getTransactionsFilterOrderBy,
overwriteTransaction,
Transaction,
writeNewTransaction
@@ -12,6 +12,7 @@ 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) {
@@ -25,7 +26,7 @@ function writeSampleData() {
parseFloat(faker.finance.amount({min: -1000, max: 1000})),
faker.word.noun(),
faker.finance.currency().code,
- faker.date.past().toISOString(),
+ faker.date.past().valueOf(),
faker.lorem.sentence(),
faker.internet.emoji(),
faker.word.noun(),
@@ -68,7 +69,7 @@ export function TestFirestorePage() {
>;
}
- getTransactions(auth.currentUser).then((t) => setTransactions(t));
+ getTransactionsFilterOrderBy(auth.currentUser, orderBy("dateTime", "desc")).then((t) => setTransactions(t));
getCurrentBalance(auth.currentUser).then((b) => setBalance(b));
return (
@@ -92,12 +93,13 @@ export function TestFirestorePage() {
Transactions:
{new Date(t.dateTime).toISOString()}
diff --git a/src/utils/firestore.ts b/src/utils/firestore.ts index 3af4479..5692c80 100644 --- a/src/utils/firestore.ts +++ b/src/utils/firestore.ts @@ -1,5 +1,6 @@ import {collection, - deleteDoc, doc, DocumentSnapshot, getDocs, limit, query, QueryFieldFilterConstraint, setDoc, SnapshotOptions, + deleteDoc, doc, DocumentSnapshot, getDocs, limit, query, + QueryConstraint, setDoc, SnapshotOptions, startAfter, where, writeBatch} from "firebase/firestore"; import {User} from "firebase/auth"; import {db} from "./firebase.ts"; @@ -11,14 +12,14 @@ export class Transaction { public amount: number; public category: string; public currency: string; - public dateTime: string; + public dateTime: number; public description: string; public emoji: string; public name: string; public notes: string; public readonly uid: string; - constructor (address: string, amount: number, category: string, currency: string, dateTime: string, description: string, emoji: string, name: string, notes: string, uid: string) { + constructor (address: string, amount: number, category: string, currency: string, dateTime: number, description: string, emoji: string, name: string, notes: string, uid: string) { this.address = address; this.amount = amount; this.category = category; @@ -123,7 +124,7 @@ export async function getTransactionsByDocName(user: User, docName: string): Pro } // Returns all transactions for the given `user` with the `filters` applied -export async function getTransactionsFilterOrderBy(user: User, ...filters: QueryFieldFilterConstraint[]): Promise