Implement tasks 25, 26 + completion visibility setting
Task 25: Multiple dashboards — dashboards table + migration, /d/[slug] route, root redirect, dashboard tabs in nav with create/rename/delete/ set-default. Task 26: Editable dashboard — react-grid-layout drag/resize editor, widget picker modal with per-widget configurator auto-generated from default config, save/reset server actions with Zod validation. Completion visibility: server-side per-user setting (hours) replaces localStorage timer; queries filter completed items by updatedAt cutoff; Settings page dropdown persists preference via server action. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
2ad9521ef9
commit
d5a8bf9d95
@@ -1,8 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { useRef, useState, useTransition } from "react";
|
||||
import { useCompletionDelay } from "@/hooks/use-completion-delay";
|
||||
import { useState, useTransition } from "react";
|
||||
import { toggleItem } from "../server/actions";
|
||||
|
||||
type WidgetItem = {
|
||||
@@ -16,31 +15,9 @@ type WidgetItem = {
|
||||
export function ListWidget({ initialItems }: { initialItems: WidgetItem[] }) {
|
||||
const [items, setItems] = useState<WidgetItem[]>(initialItems);
|
||||
const [, startTransition] = useTransition();
|
||||
const { delay } = useCompletionDelay();
|
||||
const timers = useRef<Map<string, ReturnType<typeof setTimeout>>>(new Map());
|
||||
|
||||
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)),
|
||||
);
|
||||
}
|
||||
|
||||
setItems((current) => current.map((i) => (i.id === item.id ? { ...i, done } : i)));
|
||||
startTransition(async () => {
|
||||
await toggleItem({ id: item.id, done });
|
||||
});
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
|
||||
import Link from "next/link";
|
||||
import { ChevronDown, ChevronRight, ExternalLink, Plus } from "lucide-react";
|
||||
import { useMemo, useRef, useState, useTransition } from "react";
|
||||
import { useMemo, useState, useTransition } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { useCompletionDelay } from "@/hooks/use-completion-delay";
|
||||
import type { ListIndexItem, ListWithItemsDto } from "../server/queries";
|
||||
import { createList, toggleItem } from "../server/actions";
|
||||
|
||||
@@ -15,8 +14,6 @@ export function ListsIndex({ lists }: { lists: ListWithItemsDto[] }) {
|
||||
const [type, setType] = useState("shopping");
|
||||
const [name, setName] = useState("");
|
||||
const [, startTransition] = useTransition();
|
||||
const { delay } = useCompletionDelay();
|
||||
const timers = useRef<Map<string, ReturnType<typeof setTimeout>>>(new Map());
|
||||
|
||||
const grouped = useMemo(() => {
|
||||
const groups = new Map<string, ListWithItemsDto[]>();
|
||||
@@ -47,55 +44,18 @@ export function ListsIndex({ lists }: { lists: ListWithItemsDto[] }) {
|
||||
}
|
||||
|
||||
function handleToggle(listId: string, item: ListIndexItem, done: boolean) {
|
||||
const timerId = `${listId}:${item.id}`;
|
||||
|
||||
if (done) {
|
||||
// Mark done immediately (strikethrough) and schedule removal
|
||||
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: 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)),
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
setListRows((current) =>
|
||||
current.map((list) =>
|
||||
list.id !== listId
|
||||
? list
|
||||
: {
|
||||
...list,
|
||||
openCount: list.openCount + (done ? -1 : 1),
|
||||
doneCount: list.doneCount + (done ? 1 : -1),
|
||||
items: list.items.map((i) => (i.id === item.id ? { ...i, done } : i)),
|
||||
},
|
||||
),
|
||||
);
|
||||
startTransition(async () => {
|
||||
await toggleItem({ id: item.id, done });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user