Notes layout improvements and soft delete

This commit is contained in:
2026-03-04 17:44:24 -06:00
parent 391f52af23
commit 9cbe7dcb12
4 changed files with 198 additions and 75 deletions
+54 -1
View File
@@ -146,6 +146,7 @@ export interface Note {
tasks: string[]; // List of related task IDs
created: string;
updated: string;
deletedAt?: number | null; // Timestamp of soft delete or null if restored
}
export interface FilterTag {
@@ -522,7 +523,8 @@ const mapRecordToNote = (r: any): Note => {
user: r.user,
tasks: r.tasks || [],
created: r.created,
updated: r.updated
updated: r.updated,
deletedAt: r.deletedAt ? new Date(r.deletedAt).getTime() : undefined
};
};
@@ -1648,6 +1650,57 @@ export const removeTagDefinition = async (name: string) => {
}
};
export const updateNote = async (id: string, updates: Partial<Note>) => {
if (!pb.authStore.isValid) return;
// Optimistic update
const optimisticUpdates = {
...updates,
updated: new Date().toISOString()
};
setStore("notes", (n) => n.id === id, optimisticUpdates);
try {
const pbUpdates: any = { ...updates };
if ("deletedAt" in updates) {
if (updates.deletedAt) {
pbUpdates.deletedAt = new Date(updates.deletedAt).toISOString();
} else {
pbUpdates.deletedAt = null;
}
}
await pb.collection(NOTES_COLLECTION).update(id, pbUpdates, { requestKey: null });
} catch (err) {
console.error("Note update failed", err);
toast.error("Failed to update note.");
}
};
export const removeNote = (id: string) => {
const nowTs = Date.now();
updateNote(id, { deletedAt: nowTs });
};
export const restoreNote = (id: string) => {
updateNote(id, { deletedAt: null });
};
export const deleteNotePermanently = async (id: string) => {
if (!pb.authStore.isValid) return;
// Optimistic
setStore("notes", (n) => n.filter((n) => n.id !== id));
try {
await pb.collection(NOTES_COLLECTION).delete(id);
} catch (err) {
console.error("Note delete failed", err);
toast.error("Failed to delete note.");
}
};
export const syncSystemTagsAndRules = async () => {