Skip to content

Commit

Permalink
Merge pull request #314 from openchatai/dashboard/virtual-lists
Browse files Browse the repository at this point in the history
  • Loading branch information
faltawy authored Nov 28, 2023
2 parents b1b3c9c + 8145e9b commit d4e6f0f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 7 additions & 15 deletions dashboard/app/(main)/_parts/CopilotsContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"use client";
'use client';
import React from "react";
import { BotIcon, Terminal } from "lucide-react";
import { Link } from "@/lib/router-events";
Expand All @@ -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") {
Expand All @@ -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 (
<div className="flex-center py-4">
<Loading />
</div>
);
const $copilots = customSort(
_.filter(copilots?.data, (item) => item.name.toLowerCase().includes(query)),
_.filter(copilots, (item) => item.name.toLowerCase().includes(query)),
sort,
);
return _.isEmpty($copilots) ? (
Expand Down
7 changes: 6 additions & 1 deletion dashboard/app/(main)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className="flex h-full w-full flex-col overflow-hidden">
<HeaderShell>
Expand Down Expand Up @@ -52,7 +57,7 @@ export default async function HomePage() {
</ClosableDiv>
</ClosableDivProvider>
<Search />
<CopilotsContainer />
<CopilotsContainer copilots={copilots} />
</div>
</div>
);
Expand Down

0 comments on commit d4e6f0f

Please sign in to comment.