aboutsummaryrefslogtreecommitdiffstats
path: root/packages/web/app/dashboard/bookmarks/components/Bookmarks.tsx
blob: d7e3f1f3a8ac53fde96d140e940c1d9cf7aee611 (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
import { redirect } from "next/navigation";
import BookmarksGrid from "./BookmarksGrid";
import { ZGetBookmarksRequest } from "@/lib/types/api/bookmarks";
import { api } from "@/server/api/client";
import { getServerAuthSession } from "@/server/auth";

export default async function Bookmarks({
  favourited,
  archived,
  title,
}: ZGetBookmarksRequest & { title: string }) {
  const session = await getServerAuthSession();
  if (!session) {
    redirect("/");
  }

  // TODO: Migrate to a server side call in trpc instead
  const bookmarks = await api.bookmarks.getBookmarks({
    favourited,
    archived,
  });

  if (bookmarks.bookmarks.length == 0) {
    // TODO: This needs to be polished
    return (
      <>
        <div className="container pb-4 text-2xl">{title}</div>
        <div className="container">No bookmarks</div>
      </>
    );
  }

  return (
    <>
      <div className="container pb-4 text-2xl">{title}</div>
      <BookmarksGrid bookmarks={bookmarks.bookmarks} />
    </>
  );
}