Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions website/src/components/Chat/ChatListBase.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "simplebar-react/dist/simplebar.min.css";

import { Box, CardProps, Flex } from "@chakra-ui/react";
import { Plus } from "lucide-react";
import { Box, Button, CardProps, Flex } from "@chakra-ui/react";
import { EyeOff, Plus } from "lucide-react";
import { useTranslation } from "next-i18next";
import { memo, useCallback, useState } from "react";
import SimpleBar from "simplebar-react";
Expand All @@ -11,6 +11,9 @@ import { ChatViewSelection } from "./ChatViewSelection";
import { CreateChatButton } from "./CreateChatButton";
import { InferencePoweredBy } from "./InferencePoweredBy";
import { ChatListViewSelection, useListChatPagination } from "./useListChatPagination";
import useSWRMutation from "swr/mutation";
import { API_ROUTES } from "src/lib/routes";
import { put } from "src/lib/api";

export const ChatListBase = memo(function ChatListBase({
allowViews,
Expand All @@ -23,6 +26,21 @@ export const ChatListBase = memo(function ChatListBase({

const { t } = useTranslation(["common", "chat"]);

const { trigger: triggerHideAll, isMutating: isHidingAll } = useSWRMutation(
API_ROUTES.UPDATE_CHAT(),
put
);

const handleHideAllChats = useCallback(async () => {
// Hide all visible chats
const hidePromises = chats.map((chat) =>
triggerHideAll({ chat_id: chat.id, hidden: true })
);
await Promise.all(hidePromises);
// Refresh the list
mutateChatResponses();
}, [chats, triggerHideAll, mutateChatResponses]);

const handleUpdateTitle = useCallback(
({ chatId, title }: { chatId: string; title: string }) => {
mutateChatResponses(
Expand Down Expand Up @@ -111,6 +129,20 @@ export const ChatListBase = memo(function ChatListBase({
<ChatViewSelection w={["full", "auto"]} onChange={(e) => setView(e.target.value as ChatListViewSelection)} />
)}
</Flex>
{chats.length > 0 && view === "visible" && (
<Flex px="2" pb="2">
<Button
leftIcon={<EyeOff size="16px" />}
variant="ghost"
size="sm"
onClick={handleHideAllChats}
isLoading={isHidingAll}
colorScheme="gray"
>
{t("chat:hide_all_chats")}
</Button>
</Flex>
)}
{noScrollbar ? (
content
) : (
Expand Down
Loading