Skip to content

Commit

Permalink
Filter history by model + Clear only model history (#544)
Browse files Browse the repository at this point in the history
* Filter history by model

* clear only model history
  • Loading branch information
Janaka-Steph authored Nov 15, 2023
1 parent 601b475 commit 9ccda26
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
17 changes: 5 additions & 12 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,11 +40,11 @@ const PremChatSidebar = ({
};

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

const filteredHistory = history.filter((item) => {
return item.title.toLowerCase().includes(search.toLowerCase());
return item.model === serviceId && item.title.toLowerCase().includes(search.toLowerCase());
});

const closeModal = () => {
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 9ccda26

Please sign in to comment.