added templates and fixed UX for virtual keyboard opening when opening a task
This commit is contained in:
@@ -27,6 +27,16 @@ export interface Task {
|
||||
updated: string; // ISO string from PB
|
||||
}
|
||||
|
||||
export interface TaskTemplate {
|
||||
id: string;
|
||||
name: string;
|
||||
title: string;
|
||||
priority: number;
|
||||
urgency: number;
|
||||
tags: string[];
|
||||
content: string;
|
||||
}
|
||||
|
||||
export interface Filter {
|
||||
query: string;
|
||||
tags: string[];
|
||||
@@ -43,6 +53,7 @@ interface TaskStore {
|
||||
matrixScaleDays: number;
|
||||
prefId?: string; // ID of the user_preferences record
|
||||
tagDefinitions?: Record<string, number>;
|
||||
templates?: TaskTemplate[];
|
||||
filter: Filter;
|
||||
}
|
||||
|
||||
@@ -53,6 +64,7 @@ export const [store, setStore] = createStore<TaskStore>({
|
||||
uWeight: 1.0,
|
||||
matrixScaleDays: 30,
|
||||
tagDefinitions: {}, // Map<Name, Value 0-10>
|
||||
templates: [],
|
||||
filter: {
|
||||
query: "",
|
||||
tags: [],
|
||||
@@ -190,6 +202,7 @@ export const initStore = async () => {
|
||||
uWeight: prefs.uWeight || 1.0,
|
||||
matrixScaleDays: prefs.matrixScaleDays || 30,
|
||||
tagDefinitions: prefs.tagDefinitions || {},
|
||||
templates: prefs.templates || [],
|
||||
prefId: userId // The ID to update is the User ID
|
||||
});
|
||||
}
|
||||
@@ -583,6 +596,63 @@ export const renameTagDefinition = async (oldName: string, newName: string) => {
|
||||
};
|
||||
|
||||
|
||||
// -- Templates --
|
||||
|
||||
const syncPreferences = async () => {
|
||||
const userId = pb.authStore.model?.id;
|
||||
if (!userId) return;
|
||||
|
||||
try {
|
||||
const prefs = {
|
||||
pWeight: store.pWeight,
|
||||
uWeight: store.uWeight,
|
||||
matrixScaleDays: store.matrixScaleDays,
|
||||
tagDefinitions: store.tagDefinitions,
|
||||
templates: store.templates
|
||||
};
|
||||
|
||||
await pb.collection('users').update(userId, {
|
||||
Taskgrid_pref: prefs
|
||||
}, { requestKey: null });
|
||||
} catch (e: any) {
|
||||
if (e.isAbort) return;
|
||||
console.error("Failed to sync preferences", e);
|
||||
}
|
||||
};
|
||||
|
||||
export const addTemplate = async (template: Omit<TaskTemplate, "id">) => {
|
||||
const newTemplate = { ...template, id: crypto.randomUUID() };
|
||||
setStore("templates", (prev) => [...(prev || []), newTemplate]);
|
||||
await syncPreferences();
|
||||
return newTemplate;
|
||||
};
|
||||
|
||||
export const updateTemplate = async (id: string, updates: Partial<TaskTemplate>) => {
|
||||
setStore("templates", (t) => t!.id === id, updates);
|
||||
await syncPreferences();
|
||||
};
|
||||
|
||||
export const removeTemplate = async (id: string) => {
|
||||
setStore("templates", (t) => t.filter(tmpl => tmpl.id !== id));
|
||||
await syncPreferences();
|
||||
};
|
||||
|
||||
export const saveTaskAsTemplate = async (taskId: string, name: string) => {
|
||||
const task = store.tasks.find(t => t.id === taskId);
|
||||
if (!task) return;
|
||||
|
||||
const template: Omit<TaskTemplate, "id"> = {
|
||||
name,
|
||||
title: task.title,
|
||||
priority: task.priority,
|
||||
urgency: calculateUrgencyFromDate(task.dueDate),
|
||||
tags: [...(task.tags || [])],
|
||||
content: task.content || ""
|
||||
};
|
||||
|
||||
return await addTemplate(template);
|
||||
};
|
||||
|
||||
export const setFilter = (update: Partial<Filter>) => {
|
||||
setStore("filter", (f) => ({ ...f, ...update }));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user