Skip to content

Commit fb224f9

Browse files
committed
PR comments
1 parent bf4fe56 commit fb224f9

File tree

4 files changed

+22
-30
lines changed

4 files changed

+22
-30
lines changed

apps/web/src/app/(app)/@appSidebar/_components/app-sidebar-pages.tsx

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,33 @@ import {
1515
SidebarMenuSub,
1616
useSidebar,
1717
} from "~/components/ui/sidebar";
18-
import { PAGES_INFINITE_QUERY_CONFIG } from "~/lib/pages-config";
1918
import { useTRPC } from "~/trpc/react";
2019
import { AppSidebarPageItem } from "./app-sidebar-page-item";
2120
import { CreatePageButton } from "./create-page-button";
2221

2322
type AppSidebarPagesProps = {
24-
initialPagesData: {
25-
items: Page[];
26-
nextCursor: string | undefined;
23+
infinitePagesQueryOptions: {
24+
direction: "forward" | "backward";
25+
limit: number;
2726
};
2827
defaultOpen?: boolean;
2928
};
3029

3130
export const AppSidebarPages = ({
32-
initialPagesData,
31+
infinitePagesQueryOptions,
3332
defaultOpen = true,
3433
}: AppSidebarPagesProps) => {
3534
const trpc = useTRPC();
3635
const { state, setOpen } = useSidebar();
37-
36+
const queryOptions = trpc.pages.getInfinite.infiniteQueryOptions(
37+
infinitePagesQueryOptions,
38+
);
3839
const { data, fetchNextPage, isFetchingNextPage, hasNextPage } =
3940
useInfiniteQuery({
40-
...trpc.pages.getInfinite.infiniteQueryOptions(
41-
PAGES_INFINITE_QUERY_CONFIG,
42-
),
41+
...queryOptions,
4342
getNextPageParam: ({ nextCursor }) => {
4443
return nextCursor;
4544
},
46-
initialData: {
47-
pageParams: [null], // null represents "no cursor" for the first page
48-
pages: [initialPagesData],
49-
},
5045
});
5146

5247
const pages = data?.pages?.flatMap((page) => page.items) ?? [];

apps/web/src/app/(app)/@appSidebar/default.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,26 @@ import {
1111
} from "~/components/ui/sidebar";
1212
import { Skeleton } from "~/components/ui/skeleton";
1313
import { env } from "~/env";
14-
import { PAGES_INFINITE_QUERY_CONFIG } from "~/lib/pages-config";
15-
import { api } from "~/trpc/server";
14+
import { prefetch, trpc } from "~/trpc/server";
1615
import { DynamicAppSidebarDevtools } from "./_components/app-sidebar-devtools.dynamic";
1716
import { AppSidebarNavigation } from "./_components/app-sidebar-main";
1817
import { AppSidebarPages } from "./_components/app-sidebar-pages";
1918
import { AppSidebarPagesSkeleton } from "./_components/app-sidebar-pages-skeleton";
2019
import { AppSidebarUser } from "./_components/app-sidebar-user";
2120
import { AppSidebarUserSkeleton } from "./_components/app-sidebar-user-skeleton";
2221

22+
export const infinitePagesQueryOptions = {
23+
direction: "forward" as const,
24+
limit: 25,
25+
} as const;
26+
2327
async function SuspendedAppSidebarPages() {
24-
const pagesData = await api.pages.getInfinite(PAGES_INFINITE_QUERY_CONFIG);
25-
return <AppSidebarPages initialPagesData={pagesData} />;
28+
prefetch(
29+
trpc.pages.getInfinite.infiniteQueryOptions(infinitePagesQueryOptions),
30+
);
31+
return (
32+
<AppSidebarPages infinitePagesQueryOptions={infinitePagesQueryOptions} />
33+
);
2634
}
2735

2836
export default function AppSidebar() {

apps/web/src/app/(app)/pages/_components/page-title-textarea.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { useState } from "react";
66
import { useDebouncedCallback } from "use-debounce";
77
import { FullHeightTextarea } from "~/components/ui/full-height-textarea";
88
import { cn } from "~/components/utils";
9-
import { PAGES_INFINITE_QUERY_CONFIG } from "~/lib/pages-config";
109
import { useTRPC } from "~/trpc/react";
10+
import { infinitePagesQueryOptions } from "../../@appSidebar/default";
1111

1212
const DEFAULT_PLACEHOLDER = "New page";
1313
const DEFAULT_DEBOUNCE_TIME = 150;
@@ -55,7 +55,7 @@ export function PageTitleTextarea({
5555

5656
// Update the pages.getInfinite query cache from sidebar
5757
queryClient.setQueryData(
58-
trpc.pages.getInfinite.infiniteQueryOptions(PAGES_INFINITE_QUERY_CONFIG)
58+
trpc.pages.getInfinite.infiniteQueryOptions(infinitePagesQueryOptions)
5959
.queryKey,
6060
(old) => {
6161
if (!old) return old;

apps/web/src/lib/pages-config.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)