Skip to content

Commit

Permalink
clear only model history
Browse files Browse the repository at this point in the history
  • Loading branch information
Janaka-Steph committed Nov 10, 2023
1 parent bc315f9 commit 46da8fc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
15 changes: 4 additions & 11 deletions src/modules/prem-chat/components/PremChatSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import NoPrompts from "shared/components/NoPrompts";
import WarningIcon from "shared/components/WarningIcon";
import usePremChatStore from "shared/store/prem-chat";
import type { HamburgerMenuProps } from "shared/types";
import { shallow } from "zustand/shallow";

import LeftSidebar from "../../../shared/components/LeftSidebar";

Expand All @@ -25,15 +24,9 @@ const PremChatSidebar = ({
serviceType,
historyId,
}: HamburgerMenuProps) => {
// TODO: shallow will only check for reference equality, not deep equality
const { history, deleteHistory, clearHistory } = usePremChatStore(
(state) => ({
history: state.history,
deleteHistory: state.deleteHistory,
clearHistory: state.clearHistory,
}),
shallow,
);
const history = usePremChatStore((state) => state.history);
const deleteHistory = usePremChatStore((state) => state.deleteHistory);
const clearHistory = usePremChatStore((state) => state.clearHistory);

const [search, setSearch] = useState("");
const navigate = useNavigate();
Expand All @@ -47,7 +40,7 @@ const PremChatSidebar = ({
};

const onClearClick = () => {
clearHistory();
clearHistory(serviceId);
};

const filteredHistory = history.filter((item) => {
Expand Down
5 changes: 4 additions & 1 deletion src/shared/store/prem-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ const usePremChatStore = create<PremChatStore>()(
persist(
(set) => ({
history: [],
clearHistory: () => set(() => ({ history: [] })),
clearHistory: (serviceId: string) =>
set((state) => ({
history: state.history.filter((_history) => _history.model !== serviceId),
})),
addHistory: (newHistory: PremChatHistory) =>
set((state) => ({ history: [...state.history, newHistory] })),
updateHistoryMessages: (id, messages) =>
Expand Down
2 changes: 1 addition & 1 deletion src/shared/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export type ModalProps = {

export type PremChatStore = {
history: PremChatHistory[];
clearHistory: () => void;
clearHistory: (serviceId: string) => void;
addHistory: (newHistory: PremChatHistory) => void;
updateHistoryMessages: (id: string, messages: Message[]) => void;
deleteHistory: (id: string) => void;
Expand Down

0 comments on commit 46da8fc

Please sign in to comment.