mobile task add better view handling and fixed dup templates

This commit is contained in:
2026-02-06 11:21:51 -06:00
parent 779feade9f
commit 6192a1dc32
2 changed files with 33 additions and 26 deletions
+9 -1
View File
@@ -371,6 +371,10 @@ export const subscribeToRealtime = async () => {
// Check if it's a template
const isTemplate = e.record.tags?.includes("__template__");
if (isTemplate) {
// Check if template already exists (from optimistic update)
const templateExists = store.templates?.some(t => t.id === e.record.id);
if (templateExists) return;
let meta: any = {};
try { meta = JSON.parse(e.record.content || "{}"); } catch (e) { }
const newTemplate: TaskTemplate = {
@@ -1070,7 +1074,11 @@ export const addTemplate = async (template: Omit<TaskTemplate, "id">) => {
});
const newTemplate = { ...template, id: record.id };
setStore("templates", (prev) => [...(prev || []), newTemplate]);
// Check if already added by realtime subscription
setStore("templates", (prev) => {
if (prev?.some(t => t.id === record.id)) return prev;
return [...(prev || []), newTemplate];
});
return newTemplate;
} catch (err) {
console.error("Failed to add template:", err);