From d1126e5ec6f6480a5c781b096187f4c69a725e13 Mon Sep 17 00:00:00 2001 From: ah7255703 Date: Tue, 28 Nov 2023 10:43:50 +0200 Subject: [PATCH 1/2] switch `/` path to SSR, fetch copilots on the server and send html to client, to handle large lists --- .../app/(main)/_parts/CopilotsContainer.tsx | 22 ++++++------------- dashboard/app/(main)/page.tsx | 7 +++++- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/dashboard/app/(main)/_parts/CopilotsContainer.tsx b/dashboard/app/(main)/_parts/CopilotsContainer.tsx index 8fe958f83..f9a4581aa 100644 --- a/dashboard/app/(main)/_parts/CopilotsContainer.tsx +++ b/dashboard/app/(main)/_parts/CopilotsContainer.tsx @@ -1,4 +1,4 @@ -"use client"; +'use client'; import React from "react"; import { BotIcon, Terminal } from "lucide-react"; import { Link } from "@/lib/router-events"; @@ -8,16 +8,14 @@ import { TooltipProvider, TooltipTrigger, } from "@/components/ui/tooltip"; -import useSwr from "swr"; -import { CopilotType, listCopilots } from "@/data/copilot"; -import Loading from "../loading"; +import { CopilotType } from "@/data/copilot"; import { Filter } from "./Search"; import _ from "lodash"; import { EmptyBlock } from "@/components/domain/EmptyBlock"; import { filterAtom } from "./Search"; import { useAtomValue } from "jotai"; -import { Button } from "@/components/ui/button"; import { format } from "timeago.js"; +import { Button } from "@/components/ui/button"; function customSort(list: CopilotType[], sortBy: Filter["sort"]) { if (sortBy === "last-viewed") { @@ -32,18 +30,12 @@ function customSort(list: CopilotType[], sortBy: Filter["sort"]) { } } -export function CopilotsContainer() { - const { data: copilots, isLoading } = useSwr("copilotsList", listCopilots); +export function CopilotsContainer({ copilots }: { + copilots: CopilotType[] +}) { const { sort, query } = useAtomValue(filterAtom); - - if (isLoading && !copilots) - return ( -
- -
- ); const $copilots = customSort( - _.filter(copilots?.data, (item) => item.name.toLowerCase().includes(query)), + _.filter(copilots, (item) => item.name.toLowerCase().includes(query)), sort, ); return _.isEmpty($copilots) ? ( diff --git a/dashboard/app/(main)/page.tsx b/dashboard/app/(main)/page.tsx index 4ca8c2dcf..ae717e106 100644 --- a/dashboard/app/(main)/page.tsx +++ b/dashboard/app/(main)/page.tsx @@ -10,8 +10,13 @@ import { HeaderShell } from "@/components/domain/HeaderShell"; import { Search } from "./_parts/Search"; import { Link } from "@/lib/router-events"; import { CopilotsContainer } from "./_parts/CopilotsContainer"; +import { listCopilots } from "@/data/copilot"; + +export const dynamic = 'force-dynamic' +export const revalidate = 0; export default async function HomePage() { + const { data: copilots } = await listCopilots(); return (
@@ -52,7 +57,7 @@ export default async function HomePage() { - +
); From 8145e9b2fb8ba8ff48e01cc63f9cbf419ae39af0 Mon Sep 17 00:00:00 2001 From: ah7255703 Date: Tue, 28 Nov 2023 10:44:08 +0200 Subject: [PATCH 2/2] Fix copilot delete redirect issue --- dashboard/app/(copilot)/copilot/[copilot_id]/settings/page.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dashboard/app/(copilot)/copilot/[copilot_id]/settings/page.tsx b/dashboard/app/(copilot)/copilot/[copilot_id]/settings/page.tsx index fd1a2e32d..e12de26cc 100644 --- a/dashboard/app/(copilot)/copilot/[copilot_id]/settings/page.tsx +++ b/dashboard/app/(copilot)/copilot/[copilot_id]/settings/page.tsx @@ -32,7 +32,7 @@ export default function GeneralSettingsPage() { title: "Copilot deleted", description: "Your copilot has been deleted successfully.", }); - _.delay(() => replace("/"), 1000); + replace("/") } } const [Name, setName] = React.useState(copilotName);