diff --git a/src/components/Chats.tsx b/src/components/Chats.tsx index 9ebfddb..5f15bf0 100644 --- a/src/components/Chats.tsx +++ b/src/components/Chats.tsx @@ -2,21 +2,30 @@ import { ActionIcon, Flex, Menu } from "@mantine/core"; import { IconDotsVertical, IconMessages } from "@tabler/icons-react"; import { Link } from "@tanstack/react-location"; import { useLiveQuery } from "dexie-react-hooks"; +import { useMemo } from "react"; import { db } from "../db"; import { useChatId } from "../hooks/useChatId"; import { DeleteChatModal } from "./DeleteChatModal"; import { EditChatModal } from "./EditChatModal"; import { MainLink } from "./MainLink"; -export function Chats() { +export function Chats({ search }: { search: string }) { const chatId = useChatId(); const chats = useLiveQuery(() => db.chats.orderBy("createdAt").reverse().toArray() ); + const filteredChats = useMemo( + () => + (chats ?? []).filter((chat) => { + if (!search) return true; + return chat.description.toLowerCase().includes(search); + }), + [chats, search] + ); return ( <> - {chats?.map((chat) => ( + {filteredChats.map((chat) => ( { if (!chatId) return null; @@ -145,9 +149,40 @@ export function Layout() { {tab === "Prompts" && } + ({ + padding: rem(4), + background: + theme.colorScheme === "dark" + ? theme.colors.dark[7] + : theme.white, + borderBottom: border, + })} + > + + setSearch(event.currentTarget.value.toLowerCase()) + } + sx={{ paddingInline: 4 }} + icon={} + rightSection={ + !!search && ( + setSearch("")}> + {" "} + + ) + } + /> + - {tab === "Chats" && } - {tab === "Prompts" && setTab("Chats")} />} + {tab === "Chats" && } + {tab === "Prompts" && ( + setTab("Chats")} /> + )}
diff --git a/src/components/Prompts.tsx b/src/components/Prompts.tsx index 344b3c4..b2fa622 100644 --- a/src/components/Prompts.tsx +++ b/src/components/Prompts.tsx @@ -3,23 +3,41 @@ import { IconPlayerPlay } from "@tabler/icons-react"; import { useNavigate } from "@tanstack/react-location"; import { useLiveQuery } from "dexie-react-hooks"; import { nanoid } from "nanoid"; +import { useMemo } from "react"; import { db } from "../db"; import { createChatCompletion } from "../utils/openai"; import { DeletePromptModal } from "./DeletePromptModal"; import { EditPromptModal } from "./EditPromptModal"; -export function Prompts({ onPlay }: { onPlay: () => void }) { +export function Prompts({ + onPlay, + search, +}: { + onPlay: () => void; + search: string; +}) { const navigate = useNavigate(); const prompts = useLiveQuery(() => db.prompts.orderBy("createdAt").reverse().toArray() ); + const filteredPrompts = useMemo( + () => + (prompts ?? []).filter((prompt) => { + if (!search) return true; + return ( + prompt.title.toLowerCase().includes(search) || + prompt.content.toLowerCase().includes(search) + ); + }), + [prompts, search] + ); const apiKey = useLiveQuery(async () => { return (await db.settings.where({ id: "general" }).first())?.openAiApiKey; }); return ( <> - {prompts?.map((prompt) => ( + {filteredPrompts.map((prompt) => ( ({