Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix for non-updating chat list #2527

Merged
merged 3 commits into from
Apr 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Hide chats in the frontend
  • Loading branch information
yk committed Apr 14, 2023
commit 4cfb54b1cd3fbf55e214d5450cac8b0c187e08dc
2 changes: 1 addition & 1 deletion inference/server/oasst_inference_server/routes/chats.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ async def handle_update_title(
@router.put("/{chat_id}/hide")
async def update_visibility(
chat_id: str,
hidden: bool,
hidden: bool = True,
ucr: UserChatRepository = Depends(deps.create_user_chat_repository),
):
await ucr.update_visibility(chat_id, hidden)
Expand Down
1 change: 1 addition & 0 deletions website/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"faq": "FAQ",
"guidelines": "Guidelines",
"github": "GitHub",
"hide": "Hide",
"leaderboard": "Leaderboard",
"legal": "Legal",
"light_mode": "Light Mode",
Expand Down
15 changes: 14 additions & 1 deletion website/src/components/Chat/ChatListBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ export const ChatListBase = memo(function ChatListBase({
[mutateChatResponse]
);

const handleHide = useCallback(
({ chatId }: { chatId: string; hidden: boolean }) => {
mutateChatResponse(
(chatResponse) => ({
...chatResponse,
chats: chatResponse?.chats.filter((chat) => chat.id !== chatId) || [],
}),
false
);
},
[mutateChatResponse]
);

return (
<Card
py="3"
Expand Down Expand Up @@ -90,7 +103,7 @@ export const ChatListBase = memo(function ChatListBase({
}}
>
{response?.chats.map((chat) => (
<ChatListItem key={chat.id} chat={chat} onUpdateTitle={handleUpdateTitle}></ChatListItem>
<ChatListItem key={chat.id} chat={chat} onUpdateTitle={handleUpdateTitle} onHide={handleHide}></ChatListItem>
))}
</SimpleBar>
</Card>
Expand Down
18 changes: 10 additions & 8 deletions website/src/components/Chat/ChatListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Box, Button, CircularProgress, Flex, Input, Tooltip, useBoolean, useOutsideClick } from "@chakra-ui/react";
import { Check, LucideIcon, Pencil, Trash2, X } from "lucide-react";
import { Check, LucideIcon, Pencil, EyeOff, X } from "lucide-react";
import Link from "next/link";
import { useRouter } from "next/router";
import { useTranslation } from "next-i18next";
Expand All @@ -12,9 +12,11 @@ import useSWRMutation from "swr/mutation";
export const ChatListItem = ({
chat,
onUpdateTitle,
onHide,
}: {
chat: ChatItem;
onUpdateTitle: (params: { chatId: string; title: string }) => void;
onHide: (params: { chatId: string }) => void;
}) => {
const { query } = useRouter();
const { t } = useTranslation("chat");
Expand Down Expand Up @@ -128,7 +130,7 @@ export const ChatListItem = ({
{!isEditing && (
<>
<EditChatButton onClick={setIsEditing.on} />
<DeleteChatButton chatId={chat.id} />
<HideChatButton chatId={chat.id} onHide={onHide} />
</>
)}
</Flex>
Expand All @@ -142,17 +144,17 @@ const EditChatButton = ({ onClick }: { onClick: () => void }) => {
return <ChatListItemIconButton label={t("edit")} icon={Pencil} onClick={onClick}></ChatListItemIconButton>;
};

const DeleteChatButton = ({ chatId, onDelete }: { chatId: string; onDelete?: () => unknown }) => {
const { trigger: triggerDelete } = useSWRMutation(`/api/chat?chat_id=${chatId}`, del);
const HideChatButton = ({ chatId, onHide }: { chatId: string; onHide?: (params: { chatId: string }) => void }) => {
const { trigger: triggerHide } = useSWRMutation(API_ROUTES.HIDE_CHAT(chatId), put);

const onClick = useCallback(async () => {
await triggerDelete();
onDelete?.();
}, [onDelete, triggerDelete]);
await triggerHide({ chat_id: chatId });
onHide?.({ chatId });
}, [onHide, triggerHide, chatId]);

const { t } = useTranslation("common");

return <ChatListItemIconButton label={t("delete")} icon={Trash2} onClick={onClick} />;
return <ChatListItemIconButton label={t("hide")} icon={EyeOff} onClick={onClick} />;
};

type ChatListItemIconButtonProps = {
Expand Down
4 changes: 4 additions & 0 deletions website/src/lib/oasst_inference_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ export class OasstInferenceClient {
update_chat_title({ chat_id, title }: { chat_id: string; title: string }) {
return this.request(`/chats/${chat_id}/title`, { method: "PUT", data: { title } });
}

hide_chat({ chat_id }: { chat_id: string }) {
return this.request(`/chats/${chat_id}/hide`, { method: "PUT", data: { hidden: false } });
}
}

export const createInferenceClient = (jwt: JWT) => {
Expand Down
1 change: 1 addition & 0 deletions website/src/lib/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ export const API_ROUTES = {
createRoute(`/api/chat/events`, { chat_id, message_id }),
GET_CHAT_MODELS: "/api/chat/models",
UPDATE_CHAT_TITLE: (id: string) => `/api/chat/title`,
HIDE_CHAT: (id: string) => `/api/chat/hide`,
};
17 changes: 17 additions & 0 deletions website/src/pages/api/chat/hide.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { withoutRole } from "src/lib/auth";
import { isChatEnable } from "src/lib/isChatEnable";
import { createInferenceClient } from "src/lib/oasst_inference_client";

const handler = withoutRole("banned", async (req, res, token) => {
if (!isChatEnable()) {
return res.status(404).end();
}
const client = createInferenceClient(token);
const { chat_id } = req.body as { chat_id: string };

await client.hide_chat({ chat_id });

res.status(200).end();
});

export default handler;
1 change: 1 addition & 0 deletions website/src/types/Chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface ChatItem {

// those are not available when you first create a chat
title?: string;
hidden?: boolean;
}

export interface InferenceMessage {
Expand Down