Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdBarho committed May 7, 2023
1 parent 9ad4062 commit 5b6292a
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 20 deletions.
1 change: 1 addition & 0 deletions website/public/locales/en/chat.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"remove_plugin": "Remove Plugin",
"repetition_penalty": "Repetition penalty",
"save": "Save",
"show_hidden": "Show hidden chats",
"temperature": "Temperature",
"top_k": "Top K",
"top_p": "Top P",
Expand Down
23 changes: 23 additions & 0 deletions website/src/components/Chat/ChatHiddenSwitch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { FormControl, FormLabel, Switch } from "@chakra-ui/react";
import { useTranslation } from "next-i18next";
import { ChangeEvent, useCallback } from "react";

export const ChatHiddenSwitch = ({ onChange }) => {
const { t } = useTranslation("chat");

const onClick = useCallback(
(event: ChangeEvent<HTMLInputElement>) => {
onChange?.(event.target.checked);
},
[onChange]
);

return (
<FormControl display="flex" alignItems="center" w="auto">
<FormLabel htmlFor="show-hidden-chats-switch" mb="0">
{t("show_hidden")}
</FormLabel>
<Switch id="show-hidden-chats-switch" onChange={onClick} />
</FormControl>
);
};
41 changes: 23 additions & 18 deletions website/src/components/Chat/ChatListBase.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import "simplebar-react/dist/simplebar.min.css";

import { Box, CardProps } from "@chakra-ui/react";
import { Box, CardProps, Flex } from "@chakra-ui/react";
import { Plus } from "lucide-react";
import { useTranslation } from "next-i18next";
import { memo, useCallback } from "react";
import SimpleBar from "simplebar-react";
import { GetChatsResponse } from "src/types/Chat";
import { useBoolean } from "usehooks-ts";

import { ChatHiddenSwitch } from "./ChatHiddenSwitch";
import { ChatListItem } from "./ChatListItem";
import { CreateChatButton } from "./CreateChatButton";
import { InferencePoweredBy } from "./InferencePoweredBy";
import { useListChatPagination } from "./useListChatPagination";

export const ChatListBase = memo(function ChatListBase({
initialChats, // TODO: can we remove this?
allowHiddenChats,
...props
}: CardProps & { initialChats?: GetChatsResponse }) {
const { loadMoreRef, responses, mutateChatResponses } = useListChatPagination(initialChats);
}: CardProps & { allowHiddenChats?: boolean }) {
const { value: includeHidden, setValue: setIncludeHidden } = useBoolean(false);
const { loadMoreRef, responses, mutateChatResponses } = useListChatPagination(includeHidden);
const chats = responses?.flatMap((response) => response.chats) || [];

const { t } = useTranslation(["common", "chat"]);
Expand Down Expand Up @@ -78,19 +80,22 @@ export const ChatListBase = memo(function ChatListBase({
}}
{...props}
>
<CreateChatButton
py="5"
leftIcon={<Plus size="16px"></Plus>}
variant="outline"
justifyContent="start"
colorScheme="blue"
borderRadius="lg"
mx="3"
mb="2"
onUpdated={handleCreateChat}
>
{t("create_chat")}
</CreateChatButton>
<Flex>
<CreateChatButton
py="5"
leftIcon={<Plus size="16px" />}
variant="outline"
justifyContent="start"
colorScheme="blue"
borderRadius="lg"
mx="3"
onUpdated={handleCreateChat}
flexGrow="1"
>
{t("create_chat")}
</CreateChatButton>
{allowHiddenChats && <ChatHiddenSwitch onChange={setIncludeHidden} />}
</Flex>
<SimpleBar
style={{ padding: "4px 0", maxHeight: "100%", height: "100%", minHeight: "0" }}
classNames={{
Expand Down
3 changes: 1 addition & 2 deletions website/src/components/Chat/useListChatPagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { get } from "src/lib/api";
import { GetChatsResponse } from "src/types/Chat";
import useSWRInfinite from "swr/infinite";

export function useListChatPagination(initialChats?: GetChatsResponse) {
export function useListChatPagination(includeHidden: boolean) {
const {
data: responses,
mutate: mutateChatResponses,
Expand All @@ -19,7 +19,6 @@ export function useListChatPagination(initialChats?: GetChatsResponse) {
{
keepPreviousData: true,
revalidateFirstPage: false,
fallbackData: initialChats ? [initialChats] : undefined,
}
);
const loadMoreRef = useRef(null);
Expand Down
1 change: 1 addition & 0 deletions website/src/pages/chat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const ChatList = () => {
<title>{t("chat")}</title>
</Head>
<ChatListBase
allowHiddenChats
className="max-w-5xl mx-auto"
pt="4"
px="4"
Expand Down

0 comments on commit 5b6292a

Please sign in to comment.