ui changes, fixes

This commit is contained in:
ivic00
2024-12-24 13:03:42 +01:00
parent fb9be26e04
commit 5c6915c23d
10 changed files with 86 additions and 52 deletions

View File

@ -12,6 +12,8 @@ export const useCreateNote = () => {
mutationKey: ["createNote"],
mutationFn: async (note: Partial<IBrainDump>) => {
try {
const timestamp = firestore.FieldValue.serverTimestamp();
if (note.id) {
const snapshot = await firestore()
.collection("BrainDumps")
@ -27,16 +29,22 @@ export const useCreateNote = () => {
{
...note,
creatorId: currentUser?.uid,
updatedAt: timestamp
},
{ merge: true }
);
return;
}
}
const newDoc = firestore().collection("BrainDumps").doc();
await firestore()
.collection("BrainDumps")
.add({ ...note, id: newDoc.id, creatorId: currentUser?.uid });
await newDoc.set({
...note,
id: newDoc.id,
creatorId: currentUser?.uid,
updatedAt: timestamp,
createdAt: timestamp
});
} catch (e) {
console.error(e);
}

View File

@ -18,6 +18,9 @@ export const useGetNotes = () => {
return snapshot.docs.map((doc) => ({
...doc.data(),
id: doc.id,
createdAt: doc.data().createdAt,
updatedAt: doc.data().updatedAt,
})) as IBrainDump[];
} catch (error) {
console.error("Error fetching braindumps:", error);