Improved filtering and layout
This commit is contained in:
+99
-3
@@ -269,7 +269,7 @@ interface TaskStore {
|
||||
notes: Note[];
|
||||
isNotepadMode: boolean;
|
||||
quickloadTasks: string[];
|
||||
noteFilter: { tags: string[]; ownedByMe: boolean };
|
||||
noteFilter: Filter;
|
||||
}
|
||||
|
||||
// Initial empty state
|
||||
@@ -297,7 +297,15 @@ export const [store, setStore] = createStore<TaskStore>({
|
||||
notes: [],
|
||||
isNotepadMode: false,
|
||||
quickloadTasks: [],
|
||||
noteFilter: { tags: [], ownedByMe: false }
|
||||
noteFilter: {
|
||||
query: "",
|
||||
tags: [],
|
||||
priorityMin: 1,
|
||||
priorityMax: 10,
|
||||
urgencyMin: 1,
|
||||
urgencyMax: 10,
|
||||
editedToday: false
|
||||
}
|
||||
});
|
||||
|
||||
export const matchesFilter = (task: Task) => {
|
||||
@@ -1138,7 +1146,15 @@ export const initStore = async () => {
|
||||
prefId: userId,
|
||||
subscribedBuckets: user.subscribedBuckets || [],
|
||||
quickloadTasks: prefs.quickloadTasks || [],
|
||||
noteFilter: prefs.noteFilter || { tags: [], ownedByMe: false }
|
||||
noteFilter: prefs.noteFilter || {
|
||||
query: "",
|
||||
tags: [],
|
||||
priorityMin: 1,
|
||||
priorityMax: 10,
|
||||
urgencyMin: 1,
|
||||
urgencyMax: 10,
|
||||
editedToday: false
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (prefErr) {
|
||||
@@ -2692,6 +2708,86 @@ export const clearFilter = () => {
|
||||
});
|
||||
};
|
||||
|
||||
export const setNoteFilter = (update: Partial<Filter>) => {
|
||||
setStore("noteFilter", (f) => ({ ...f, ...update }));
|
||||
};
|
||||
|
||||
const NOTE_FILTER_TEMPLATES_COLLECTION = 'TasGrid_NoteFilterTemplates';
|
||||
|
||||
export const loadNoteFilterTemplates = async () => {
|
||||
if (!pb.authStore.isValid) return;
|
||||
try {
|
||||
const records = await pb.collection(NOTE_FILTER_TEMPLATES_COLLECTION).getFullList({
|
||||
filter: `user = "${pb.authStore.model?.id}"`,
|
||||
requestKey: null
|
||||
});
|
||||
const templates: FilterTemplate[] = records.map(r => ({
|
||||
id: r.id,
|
||||
name: r.name,
|
||||
filter: r.filter as Filter
|
||||
}));
|
||||
setStore("filterTemplates", templates);
|
||||
} catch (err) {
|
||||
console.error("Failed to load note filter templates:", err);
|
||||
}
|
||||
};
|
||||
|
||||
export const saveNoteFilterTemplate = async (name: string) => {
|
||||
if (!pb.authStore.isValid) return;
|
||||
try {
|
||||
const record = await pb.collection(NOTE_FILTER_TEMPLATES_COLLECTION).create({
|
||||
user: pb.authStore.model?.id,
|
||||
name,
|
||||
filter: store.noteFilter
|
||||
}, { requestKey: null });
|
||||
|
||||
const newTemplate: FilterTemplate = {
|
||||
id: record.id,
|
||||
name: record.name,
|
||||
filter: record.filter as Filter
|
||||
};
|
||||
|
||||
setStore("filterTemplates", prev => [...prev, newTemplate]);
|
||||
toast.success(`Note filter template "${name}" saved`);
|
||||
} catch (err) {
|
||||
console.error("Failed to save note filter template:", err);
|
||||
toast.error("Failed to save note filter template.");
|
||||
}
|
||||
};
|
||||
|
||||
export const applyNoteFilterTemplate = (id: string) => {
|
||||
const template = store.filterTemplates.find(t => t.id === id);
|
||||
if (template) {
|
||||
setNoteFilter(template.filter);
|
||||
toast.success(`Applied note filter: ${template.name}`);
|
||||
}
|
||||
};
|
||||
|
||||
export const removeNoteFilterTemplate = async (id: string) => {
|
||||
if (!pb.authStore.isValid) return;
|
||||
try {
|
||||
await pb.collection(NOTE_FILTER_TEMPLATES_COLLECTION).delete(id);
|
||||
setStore("filterTemplates", prev => prev.filter(t => t.id !== id));
|
||||
toast.success("Note filter template deleted");
|
||||
} catch (err) {
|
||||
console.error("Failed to delete note filter template:", err);
|
||||
toast.error("Failed to delete note filter template.");
|
||||
}
|
||||
};
|
||||
|
||||
export const clearNoteFilter = () => {
|
||||
setStore("noteFilter", {
|
||||
query: "",
|
||||
tags: [],
|
||||
priorityMin: 1,
|
||||
priorityMax: 10,
|
||||
urgencyMin: 1,
|
||||
urgencyMax: 10,
|
||||
editedToday: false
|
||||
});
|
||||
syncPreferences();
|
||||
};
|
||||
|
||||
// Legacy cleanup - We don't need local storage persistence setup anymore
|
||||
export const setupPersistence = () => {
|
||||
// Moved logic to initStore which is called on auth.
|
||||
|
||||
Reference in New Issue
Block a user