update tags and add description editor to add-task
This commit is contained in:
+53
-11
@@ -186,7 +186,7 @@ export const initStore = async () => {
|
||||
|
||||
// -- Actions --
|
||||
|
||||
export const addTask = async (title: string, options?: { dueDate?: Date | string, priority?: number, tags?: string[] }) => {
|
||||
export const addTask = async (title: string, options?: { dueDate?: Date | string, priority?: number, tags?: string[], content?: string }) => {
|
||||
if (!pb.authStore.isValid) return;
|
||||
|
||||
// Default to ~24h from now if no date provided
|
||||
@@ -198,6 +198,7 @@ export const addTask = async (title: string, options?: { dueDate?: Date | string
|
||||
const startDate = new Date().toISOString();
|
||||
const priority = options?.priority ?? 5;
|
||||
const tags = options?.tags ?? ["work"];
|
||||
const content = options?.content ?? "";
|
||||
|
||||
const tempId = "temp-" + Date.now();
|
||||
const newTask: Task = {
|
||||
@@ -207,7 +208,8 @@ export const addTask = async (title: string, options?: { dueDate?: Date | string
|
||||
dueDate,
|
||||
priority,
|
||||
completed: false,
|
||||
tags
|
||||
tags,
|
||||
content
|
||||
};
|
||||
|
||||
// Optimistic UI update
|
||||
@@ -221,7 +223,8 @@ export const addTask = async (title: string, options?: { dueDate?: Date | string
|
||||
dueDate,
|
||||
priority,
|
||||
completed: false,
|
||||
tags
|
||||
tags,
|
||||
content
|
||||
});
|
||||
|
||||
// Replace temp task with real record
|
||||
@@ -234,6 +237,21 @@ export const addTask = async (title: string, options?: { dueDate?: Date | string
|
||||
}
|
||||
};
|
||||
|
||||
export const copyTask = async (id: string) => {
|
||||
const original = store.tasks.find(t => t.id === id);
|
||||
if (!original) return;
|
||||
|
||||
// Create a new task based on the original
|
||||
await addTask(`${original.title} (Copy)`, {
|
||||
priority: original.priority,
|
||||
dueDate: original.dueDate,
|
||||
tags: [...(original.tags || [])],
|
||||
content: original.content
|
||||
});
|
||||
|
||||
toast.success("Task duplicated");
|
||||
};
|
||||
|
||||
export const updateTask = async (id: string, updates: Partial<Task>) => {
|
||||
if (!pb.authStore.isValid) return;
|
||||
|
||||
@@ -380,12 +398,6 @@ export const upsertTagDefinition = async (name: string, value: number) => {
|
||||
const userId = pb.authStore.model?.id;
|
||||
if (userId) {
|
||||
try {
|
||||
// Need to fetch user record first? Or iterate local?
|
||||
// Pocketbase update can take partial JSON?
|
||||
// "Taskgrid_pref" is a JSON field. We usually need to send the whole object or merge it manually if the backend doesn't merge.
|
||||
// But here we rely on store state having everything.
|
||||
|
||||
// Re-construct full prefs object
|
||||
const prefs = {
|
||||
pWeight: store.pWeight,
|
||||
uWeight: store.uWeight,
|
||||
@@ -395,14 +407,44 @@ export const upsertTagDefinition = async (name: string, value: number) => {
|
||||
|
||||
await pb.collection('users').update(userId, {
|
||||
Taskgrid_pref: prefs
|
||||
});
|
||||
} catch (e) {
|
||||
}, { requestKey: null });
|
||||
} catch (e: any) {
|
||||
// Ignore abort errors
|
||||
if (e.isAbort) return;
|
||||
console.error("Failed to persist tag definition", e);
|
||||
toast.error("Failed to save tag definition");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const upsertMultipleTagDefinitions = async (updates: Record<string, number>) => {
|
||||
// Optimistic update
|
||||
setStore("tagDefinitions", (defs) => ({ ...(defs || {}), ...updates }));
|
||||
|
||||
// Persist
|
||||
const map = { ...store.tagDefinitions };
|
||||
const userId = pb.authStore.model?.id;
|
||||
if (userId) {
|
||||
try {
|
||||
const prefs = {
|
||||
pWeight: store.pWeight,
|
||||
uWeight: store.uWeight,
|
||||
matrixScaleDays: store.matrixScaleDays,
|
||||
tagDefinitions: map
|
||||
};
|
||||
|
||||
await pb.collection('users').update(userId, {
|
||||
Taskgrid_pref: prefs
|
||||
}, { requestKey: null });
|
||||
} catch (e: any) {
|
||||
// Ignore abort errors
|
||||
if (e.isAbort) return;
|
||||
console.error("Failed to persist tag definitions", e);
|
||||
toast.error("Failed to save tag definitions");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const removeTagDefinition = async (name: string) => {
|
||||
// 1. Remove from all tasks
|
||||
const tasksWithTag = store.tasks.filter(t => t.tags?.includes(name));
|
||||
|
||||
Reference in New Issue
Block a user