aboutsummaryrefslogtreecommitdiffstats
path: root/apps/web/components/dashboard/lists/ListHeader.tsx
blob: 6796d4843cdbe613ed2cdc385c566c234bbdf3b9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"use client";

import { useRouter } from "next/navigation";
import { Button } from "@/components/ui/button";
import { MoreHorizontal } from "lucide-react";

import { api } from "@hoarder/shared-react/trpc";
import { ZBookmarkList } from "@hoarder/shared/types/lists";

import { ListOptions } from "./ListOptions";

export default function ListHeader({
  initialData,
}: {
  initialData: ZBookmarkList & { bookmarks: string[] };
}) {
  const router = useRouter();
  const { data: list, error } = api.lists.get.useQuery(
    {
      listId: initialData.id,
    },
    {
      initialData,
    },
  );

  if (error) {
    // This is usually exercised during list deletions.
    if (error.data?.code == "NOT_FOUND") {
      router.push("/dashboard/lists");
    }
  }

  return (
    <div className="flex justify-between">
      <span className="text-2xl">
        {list.icon} {list.name}
      </span>
      <ListOptions list={list}>
        <Button variant="ghost">
          <MoreHorizontal />
        </Button>
      </ListOptions>
    </div>
  );
}