Skip to content

Commit 0c59128

Browse files
committed
Use url state for task panel and showing deleted
1 parent 10f312d commit 0c59128

6 files changed

Lines changed: 38 additions & 9 deletions

File tree

app/(dashboard)/[tenant]/projects/[projectId]/tasklists/[tasklistId]/page.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@ import { toStartOfDay } from "@/lib/utils/date";
1515
import { useTRPC } from "@/trpc/client";
1616
import { useQueries } from "@tanstack/react-query";
1717
import { useParams } from "next/navigation";
18+
import { parseAsBoolean, useQueryState } from "nuqs";
1819

1920
export default function TaskLists() {
2021
const { projectId, tasklistId } = useParams();
22+
const [showDeleted, setShowDeleted] = useQueryState(
23+
"showDeleted",
24+
parseAsBoolean.withDefault(false),
25+
);
2126

2227
const trpc = useTRPC();
2328
const [{ data: list }, { data: timezone }, { data: project }] = useQueries({
@@ -127,6 +132,8 @@ export default function TaskLists() {
127132
id={list.id}
128133
hideHeader
129134
canEdit={project.canEdit}
135+
showDeleted={showDeleted}
136+
onShowDeletedChange={setShowDeleted}
130137
/>
131138
</TasksProvider>
132139

components/core/panel.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use client";
22

33
import * as Dialog from "@radix-ui/react-dialog";
4+
import { VisuallyHidden } from "@radix-ui/react-visually-hidden";
45
import { memo } from "react";
56
import { useIsMobile } from "@/hooks/use-mobile";
67
import { cn } from "@/lib/utils";
@@ -10,11 +11,13 @@ export const Panel = memo(function Panel({
1011
setOpen,
1112
children,
1213
className,
14+
title = "Panel",
1315
}: {
1416
open: boolean;
1517
setOpen?: (open: boolean) => void;
1618
children: React.ReactNode;
1719
className?: string;
20+
title?: string;
1821
}) {
1922
const isMobile = useIsMobile();
2023

@@ -31,6 +34,9 @@ export const Panel = memo(function Panel({
3134
className,
3235
)}
3336
>
37+
<VisuallyHidden>
38+
<Dialog.Title>{title}</Dialog.Title>
39+
</VisuallyHidden>
3440
{children}
3541
</Dialog.Content>
3642
</Dialog.Portal>

components/project/tasklist/task/task-item.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import { Close, Title } from "@radix-ui/react-dialog";
66
import { useQueries } from "@tanstack/react-query";
77
import { AlignJustifyIcon, CalendarClock, FileIcon, X } from "lucide-react";
88
import { useParams } from "next/navigation";
9-
import { useMemo, useState } from "react";
9+
import { parseAsInteger, useQueryState } from "nuqs";
10+
import { useMemo } from "react";
1011
import { toast } from "sonner";
1112
import { Panel } from "@/components/core/panel";
1213
import { ConfirmButton } from "@/components/form/button";
@@ -44,7 +45,11 @@ export const TaskItem = ({
4445
canEdit?: boolean;
4546
}) => {
4647
const { projectId } = useParams();
47-
const [detailsOpen, setDetailsOpen] = useState(false);
48+
const [selectedTaskId, setSelectedTaskId] = useQueryState(
49+
"task",
50+
parseAsInteger,
51+
);
52+
const detailsOpen = selectedTaskId === task.id;
4853
const { attributes, listeners, setNodeRef, transform, transition } =
4954
useSortable({ id: task.id });
5055

@@ -113,7 +118,7 @@ export const TaskItem = ({
113118
creating ? "text-muted-foreground" : "",
114119
)}
115120
onClick={() => {
116-
if (!creating) setDetailsOpen(true);
121+
if (!creating) setSelectedTaskId(task.id);
117122
}}
118123
>
119124
<div
@@ -155,7 +160,12 @@ export const TaskItem = ({
155160
) : null}
156161
</div>
157162

158-
<Panel open={detailsOpen} setOpen={setDetailsOpen}>
163+
<Panel
164+
open={detailsOpen}
165+
setOpen={(open) => {
166+
if (!open) setSelectedTaskId(null);
167+
}}
168+
>
159169
<Title>
160170
<div className="flex items-center px-4 h-14 border-b">
161171
<div className="flex items-center flex-1">
@@ -372,7 +382,7 @@ export const TaskItem = ({
372382
"Error while copying, please try again.",
373383
},
374384
);
375-
setDetailsOpen(false);
385+
setSelectedTaskId(null);
376386
}}
377387
>
378388
<button

components/project/tasklist/tasklist.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,15 @@ export const TaskListItem = ({
3131
hideHeader = false,
3232
compact = false,
3333
canEdit = true,
34+
showDeleted,
35+
onShowDeletedChange,
3436
}: {
3537
id: number;
3638
hideHeader?: boolean;
3739
compact?: boolean;
3840
canEdit?: boolean;
41+
showDeleted?: boolean;
42+
onShowDeletedChange?: (showDeleted: boolean) => void;
3943
}) => {
4044
const trpc = useTRPC();
4145
const { data: taskList, isLoading } = useQuery(
@@ -63,7 +67,6 @@ export const TaskListItem = ({
6367
[taskList?.tasks],
6468
);
6569

66-
const [showDeleted, setShowDeleted] = useState(false);
6770
const deletedItems = useMemo(
6871
() =>
6972
taskList?.tasks.filter((task) => task.status === TaskStatus.DELETED) ??
@@ -204,7 +207,7 @@ export const TaskListItem = ({
204207
<Button
205208
variant="ghost"
206209
size="sm"
207-
onClick={() => setShowDeleted((x) => !x)}
210+
onClick={() => onShowDeletedChange?.(!showDeleted)}
208211
>
209212
{showDeleted ? "Hide" : "Show"}
210213
</Button>

lib/utils/mentionNotifications.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ interface MentionContext {
88
type: "project" | "task" | "tasklist" | "event" | "comment" | "post";
99
entityName: string;
1010
entityId: number;
11-
projectId?: number; // For linking back to project
11+
projectId?: number;
12+
taskListId?: number;
1213
orgSlug: string;
1314
fromUserId: string;
1415
}
@@ -47,7 +48,7 @@ export async function sendMentionNotifications(
4748

4849
case "task":
4950
message = `${fromUserName} mentioned you in task "${context.entityName}"`;
50-
target = `/${context.orgSlug}/projects/${context.projectId}`;
51+
target = `/${context.orgSlug}/projects/${context.projectId}/tasklists/${context.taskListId}?task=${context.entityId}`;
5152
break;
5253

5354
case "tasklist":

trpc/routers/tasks.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ export const tasksRouter = createTRPCRouter({
331331
entityName: input.name || "Untitled Task",
332332
entityId: createdTask[0].id,
333333
projectId: taskListDetails.projectId,
334+
taskListId: input.taskListId,
334335
orgSlug: ctx.orgSlug,
335336
fromUserId: ctx.userId,
336337
});
@@ -447,6 +448,7 @@ export const tasksRouter = createTRPCRouter({
447448
entityName: oldTask.name,
448449
entityId: input.id,
449450
projectId: oldTask.taskList.projectId,
451+
taskListId: oldTask.taskListId,
450452
orgSlug: ctx.orgSlug,
451453
fromUserId: ctx.userId,
452454
});

0 commit comments

Comments
 (0)