Delay item disappearance after check-off; add setting in Settings
Items on the lists page and dashboard widget now show as crossed-out for a configurable duration (default 3s) before vanishing. Unchecking within the window cancels the removal. The delay is stored in localStorage and configurable via Settings → Lists (options: 1s / 3s / 5s / 10s / 30s). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
8fda3e47dd
commit
2ad9521ef9
@@ -4,6 +4,7 @@ import { getEntityType } from "@/modules/_core/registry";
|
|||||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { ThemePicker } from "@/components/theme-picker";
|
import { ThemePicker } from "@/components/theme-picker";
|
||||||
|
import { CompletionDelaySetting } from "@/components/completion-delay-setting";
|
||||||
import { revokeShareLinkAction } from "./actions";
|
import { revokeShareLinkAction } from "./actions";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
|
||||||
@@ -28,6 +29,15 @@ export default async function SettingsPage() {
|
|||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Lists</CardTitle>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<CompletionDelaySetting />
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle>Active Share Links</CardTitle>
|
<CardTitle>Active Share Links</CardTitle>
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { DELAY_OPTIONS, useCompletionDelay } from "@/hooks/use-completion-delay";
|
||||||
|
|
||||||
|
export function CompletionDelaySetting() {
|
||||||
|
const { delay, setDelay } = useCompletionDelay();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex items-center justify-between gap-4">
|
||||||
|
<div>
|
||||||
|
<p className="text-sm font-medium">Completion delay</p>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
How long a checked-off item stays visible before disappearing from list cards and the
|
||||||
|
dashboard.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<select
|
||||||
|
value={delay}
|
||||||
|
onChange={(e) => setDelay(Number(e.target.value))}
|
||||||
|
className="rounded-md border border-input bg-background px-3 py-1.5 text-sm shadow-sm focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
|
||||||
|
>
|
||||||
|
{DELAY_OPTIONS.map((opt) => (
|
||||||
|
<option key={opt.value} value={opt.value}>
|
||||||
|
{opt.label}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
|
const STORAGE_KEY = "completion-delay-ms";
|
||||||
|
export const DEFAULT_DELAY_MS = 3000;
|
||||||
|
|
||||||
|
export const DELAY_OPTIONS = [
|
||||||
|
{ label: "1 second", value: 1000 },
|
||||||
|
{ label: "3 seconds", value: 3000 },
|
||||||
|
{ label: "5 seconds", value: 5000 },
|
||||||
|
{ label: "10 seconds", value: 10000 },
|
||||||
|
{ label: "30 seconds", value: 30000 },
|
||||||
|
];
|
||||||
|
|
||||||
|
function readDelay(): number {
|
||||||
|
if (typeof window === "undefined") return DEFAULT_DELAY_MS;
|
||||||
|
const raw = localStorage.getItem(STORAGE_KEY);
|
||||||
|
const parsed = raw ? parseInt(raw, 10) : NaN;
|
||||||
|
return Number.isFinite(parsed) ? parsed : DEFAULT_DELAY_MS;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useCompletionDelay() {
|
||||||
|
const [delay, setDelayState] = useState<number>(readDelay);
|
||||||
|
|
||||||
|
function setDelay(ms: number) {
|
||||||
|
setDelayState(ms);
|
||||||
|
localStorage.setItem(STORAGE_KEY, String(ms));
|
||||||
|
}
|
||||||
|
|
||||||
|
return { delay, setDelay };
|
||||||
|
}
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useOptimistic, useTransition } from "react";
|
import { useRef, useState, useTransition } from "react";
|
||||||
|
import { useCompletionDelay } from "@/hooks/use-completion-delay";
|
||||||
import { toggleItem } from "../server/actions";
|
import { toggleItem } from "../server/actions";
|
||||||
|
|
||||||
type WidgetItem = {
|
type WidgetItem = {
|
||||||
@@ -13,16 +14,34 @@ type WidgetItem = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function ListWidget({ initialItems }: { initialItems: WidgetItem[] }) {
|
export function ListWidget({ initialItems }: { initialItems: WidgetItem[] }) {
|
||||||
const [items, setOptimistic] = useOptimistic(
|
const [items, setItems] = useState<WidgetItem[]>(initialItems);
|
||||||
initialItems,
|
|
||||||
(current: WidgetItem[], { id, done }: { id: string; done: boolean }) =>
|
|
||||||
current.map((item) => (item.id === id ? { ...item, done } : item)),
|
|
||||||
);
|
|
||||||
const [, startTransition] = useTransition();
|
const [, startTransition] = useTransition();
|
||||||
|
const { delay } = useCompletionDelay();
|
||||||
|
const timers = useRef<Map<string, ReturnType<typeof setTimeout>>>(new Map());
|
||||||
|
|
||||||
function toggle(item: WidgetItem, done: boolean) {
|
function toggle(item: WidgetItem, done: boolean) {
|
||||||
|
if (done) {
|
||||||
|
setItems((current) =>
|
||||||
|
current.map((i) => (i.id === item.id ? { ...i, done: true } : i)),
|
||||||
|
);
|
||||||
|
|
||||||
|
const t = setTimeout(() => {
|
||||||
|
setItems((current) => current.filter((i) => i.id !== item.id));
|
||||||
|
timers.current.delete(item.id);
|
||||||
|
}, delay);
|
||||||
|
timers.current.set(item.id, t);
|
||||||
|
} else {
|
||||||
|
const existing = timers.current.get(item.id);
|
||||||
|
if (existing) {
|
||||||
|
clearTimeout(existing);
|
||||||
|
timers.current.delete(item.id);
|
||||||
|
}
|
||||||
|
setItems((current) =>
|
||||||
|
current.map((i) => (i.id === item.id ? { ...i, done: false } : i)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
startTransition(async () => {
|
startTransition(async () => {
|
||||||
setOptimistic({ id: item.id, done });
|
|
||||||
await toggleItem({ id: item.id, done });
|
await toggleItem({ id: item.id, done });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -44,7 +63,9 @@ export function ListWidget({ initialItems }: { initialItems: WidgetItem[] }) {
|
|||||||
/>
|
/>
|
||||||
<Link
|
<Link
|
||||||
href={`/lists/${item.listId}`}
|
href={`/lists/${item.listId}`}
|
||||||
className={`truncate hover:underline ${item.done ? "text-muted-foreground line-through" : ""}`}
|
className={`truncate hover:underline transition-colors ${
|
||||||
|
item.done ? "text-muted-foreground line-through" : ""
|
||||||
|
}`}
|
||||||
>
|
>
|
||||||
{item.text}
|
{item.text}
|
||||||
</Link>
|
</Link>
|
||||||
|
|||||||
@@ -2,10 +2,11 @@
|
|||||||
|
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { ChevronDown, ChevronRight, ExternalLink, Plus } from "lucide-react";
|
import { ChevronDown, ChevronRight, ExternalLink, Plus } from "lucide-react";
|
||||||
import { useMemo, useState, useTransition } from "react";
|
import { useMemo, useRef, useState, useTransition } from "react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
|
import { useCompletionDelay } from "@/hooks/use-completion-delay";
|
||||||
import type { ListIndexItem, ListWithItemsDto } from "../server/queries";
|
import type { ListIndexItem, ListWithItemsDto } from "../server/queries";
|
||||||
import { createList, toggleItem } from "../server/actions";
|
import { createList, toggleItem } from "../server/actions";
|
||||||
|
|
||||||
@@ -14,6 +15,8 @@ export function ListsIndex({ lists }: { lists: ListWithItemsDto[] }) {
|
|||||||
const [type, setType] = useState("shopping");
|
const [type, setType] = useState("shopping");
|
||||||
const [name, setName] = useState("");
|
const [name, setName] = useState("");
|
||||||
const [, startTransition] = useTransition();
|
const [, startTransition] = useTransition();
|
||||||
|
const { delay } = useCompletionDelay();
|
||||||
|
const timers = useRef<Map<string, ReturnType<typeof setTimeout>>>(new Map());
|
||||||
|
|
||||||
const grouped = useMemo(() => {
|
const grouped = useMemo(() => {
|
||||||
const groups = new Map<string, ListWithItemsDto[]>();
|
const groups = new Map<string, ListWithItemsDto[]>();
|
||||||
@@ -44,18 +47,55 @@ export function ListsIndex({ lists }: { lists: ListWithItemsDto[] }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleToggle(listId: string, item: ListIndexItem, done: boolean) {
|
function handleToggle(listId: string, item: ListIndexItem, done: boolean) {
|
||||||
setListRows((current) =>
|
const timerId = `${listId}:${item.id}`;
|
||||||
current.map((list) =>
|
|
||||||
list.id !== listId
|
if (done) {
|
||||||
? list
|
// Mark done immediately (strikethrough) and schedule removal
|
||||||
: {
|
setListRows((current) =>
|
||||||
...list,
|
current.map((list) =>
|
||||||
openCount: list.openCount + (done ? -1 : 1),
|
list.id !== listId
|
||||||
doneCount: list.doneCount + (done ? 1 : -1),
|
? list
|
||||||
items: list.items.filter((i) => i.id !== item.id),
|
: {
|
||||||
},
|
...list,
|
||||||
),
|
openCount: list.openCount - 1,
|
||||||
);
|
doneCount: list.doneCount + 1,
|
||||||
|
items: list.items.map((i) => (i.id === item.id ? { ...i, done: true } : i)),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
const t = setTimeout(() => {
|
||||||
|
setListRows((current) =>
|
||||||
|
current.map((list) =>
|
||||||
|
list.id !== listId
|
||||||
|
? list
|
||||||
|
: { ...list, items: list.items.filter((i) => i.id !== item.id) },
|
||||||
|
),
|
||||||
|
);
|
||||||
|
timers.current.delete(timerId);
|
||||||
|
}, delay);
|
||||||
|
timers.current.set(timerId, t);
|
||||||
|
} else {
|
||||||
|
// Cancel pending removal and restore item
|
||||||
|
const existing = timers.current.get(timerId);
|
||||||
|
if (existing) {
|
||||||
|
clearTimeout(existing);
|
||||||
|
timers.current.delete(timerId);
|
||||||
|
}
|
||||||
|
setListRows((current) =>
|
||||||
|
current.map((list) =>
|
||||||
|
list.id !== listId
|
||||||
|
? list
|
||||||
|
: {
|
||||||
|
...list,
|
||||||
|
openCount: list.openCount + 1,
|
||||||
|
doneCount: list.doneCount - 1,
|
||||||
|
items: list.items.map((i) => (i.id === item.id ? { ...i, done: false } : i)),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
startTransition(async () => {
|
startTransition(async () => {
|
||||||
await toggleItem({ id: item.id, done });
|
await toggleItem({ id: item.id, done });
|
||||||
});
|
});
|
||||||
@@ -162,16 +202,22 @@ function ListCard({
|
|||||||
checked={item.done}
|
checked={item.done}
|
||||||
onChange={(e) => onToggle(list.id, item, e.target.checked)}
|
onChange={(e) => onToggle(list.id, item, e.target.checked)}
|
||||||
/>
|
/>
|
||||||
<span className="text-sm truncate">{item.text}</span>
|
<span
|
||||||
|
className={`text-sm truncate transition-colors ${
|
||||||
|
item.done ? "text-muted-foreground line-through" : ""
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{item.text}
|
||||||
|
</span>
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
{list.openCount > list.items.length && (
|
{list.openCount > list.items.filter((i) => !i.done).length && (
|
||||||
<li className="px-4 py-2">
|
<li className="px-4 py-2">
|
||||||
<Link
|
<Link
|
||||||
href={`/lists/${list.id}`}
|
href={`/lists/${list.id}`}
|
||||||
className="text-xs text-muted-foreground hover:text-foreground transition-colors"
|
className="text-xs text-muted-foreground hover:text-foreground transition-colors"
|
||||||
>
|
>
|
||||||
+{list.openCount - list.items.length} more — open list
|
+{list.openCount - list.items.filter((i) => !i.done).length} more — open list
|
||||||
</Link>
|
</Link>
|
||||||
</li>
|
</li>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user