share mode toggle added. Partial note task linkage change (stable)

This commit is contained in:
2026-03-23 12:03:15 -05:00
parent de8cea7d2e
commit 8e4eae92f8
3 changed files with 168 additions and 7 deletions
+69 -2
View File
@@ -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<TagPickerProps> = (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<TagPickerProps> = (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<TagPickerProps> = (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<TagPickerProps> = (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<TagPickerProps> = (props) => {
</select>
</div>
{selectedTagName().trim().startsWith("@") && (
<div class="space-y-1.5">
<label class="text-[0.625rem] font-bold uppercase tracking-wider text-muted-foreground">Share Mode</label>
<div class="bg-background border border-border p-1 rounded-xl flex items-center shadow-sm relative min-w-[160px] h-10">
<div
class={cn(
"absolute top-1 bottom-1 w-[calc(50%-4px)] bg-primary rounded-lg shadow-sm transition-transform duration-200 ease-out z-0",
shareMode() === "handoff" ? "translate-x-0" : "translate-x-[calc(100%+0px)]"
)}
/>
<button
type="button"
class={cn(
"flex-1 h-8 text-[0.7rem] font-bold uppercase tracking-widest z-10 transition-colors duration-200 flex items-center justify-center rounded-lg",
shareMode() === "handoff" ? "text-primary-foreground" : "text-muted-foreground hover:text-foreground"
)}
onClick={() => setShareMode("handoff")}
>
Handoff
</button>
<button
type="button"
class={cn(
"flex-1 h-8 text-[0.7rem] font-bold uppercase tracking-widest z-10 transition-colors duration-200 flex items-center justify-center rounded-lg",
shareMode() === "collaborative" ? "text-primary-foreground" : "text-muted-foreground hover:text-foreground"
)}
onClick={() => setShareMode("collaborative")}
>
Collaborate
</button>
</div>
</div>
)}
<Button size="sm" class="w-full mt-1" onClick={handleApply}>
<Plus size={14} class="mr-2" />
{store.tagDefinitions.find(d => d.name === selectedTagName().trim()) ? "Update & Add" : "Create & Add"}