diff --git a/src/components/TagPicker.tsx b/src/components/TagPicker.tsx index d57b37f..ef6cecd 100644 --- a/src/components/TagPicker.tsx +++ b/src/components/TagPicker.tsx @@ -1,11 +1,12 @@ import { type Component, createSignal, For, createEffect } from "solid-js"; -import { store, upsertTagDefinition, isCurrentUserContextTag } from "@/store"; +import { store, upsertTagDefinition, isCurrentUserContextTag, setContextPolicy } from "@/store"; import { useTheme } from "./ThemeProvider"; import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; import { Button } from "@/components/ui/button"; import { Tag, Plus } from "lucide-solid"; import { toast } from "solid-sonner"; import { buildNoteTag, buildShareTag, normalizeContextKey, normalizeNoteKey } from "@/lib/tags"; +import { cn } from "@/lib/utils"; interface TagPickerProps { selectedTags: string[]; @@ -17,6 +18,7 @@ export const TagPicker: Component = (props) => { const [open, setOpen] = createSignal(false); const [selectedTagName, setSelectedTagName] = createSignal(""); const [valueScore, setValueScore] = createSignal(5); + const [shareMode, setShareMode] = createSignal<"handoff" | "collaborative">("handoff"); // Filter tags for the "Name" part const localTagNames = () => { @@ -40,6 +42,19 @@ export const TagPicker: Component = (props) => { return allTagNames(); }; + const selectedShareContext = () => { + const name = selectedTagName().trim(); + if (!name.startsWith("@")) return null; + + const normalized = normalizeContextKey(name); + return store.contexts.find(context => + !context.deletedAt && ( + context.key === normalized || + normalizeContextKey(context.displayName) === normalized + ) + ) || null; + }; + // When a tag name is selected, update the value score to match its current definition createEffect(() => { const name = selectedTagName().trim(); @@ -51,10 +66,23 @@ export const TagPicker: Component = (props) => { } }); - const handleApply = () => { + createEffect(() => { + const context = selectedShareContext(); + if (context) { + setShareMode(context.policy); + return; + } + if (selectedTagName().trim().startsWith("@")) { + setShareMode("handoff"); + } + }); + + const handleApply = async () => { const name = selectedTagName().trim(); if (!name) return; + const context = selectedShareContext(); + if (name.startsWith("@")) { const normalized = normalizeContextKey(name); const exists = store.contexts.some(context => @@ -67,6 +95,11 @@ export const TagPicker: Component = (props) => { toast.error("Create the shared context first before tagging tasks with it."); return; } + + if (context && context.policy !== shareMode()) { + const updated = await setContextPolicy(context.id, shareMode()); + if (!updated) return; + } } if (name.startsWith("#")) { @@ -134,6 +167,40 @@ export const TagPicker: Component = (props) => { + {selectedTagName().trim().startsWith("@") && ( +
+ +
+
+ + +
+
+ )} +