Skip to content
This repository has been archived by the owner on Sep 15, 2024. It is now read-only.

Commit

Permalink
Implement Local Storage Helper (#266)
Browse files Browse the repository at this point in the history
* Feat [Utility] [Storage Helper] "clearUnfinishedInputForSession"

- [+] feat(storageHelper.ts): add utility function to clear unfinished input for a session

* Feat [UI/UX] [Front End] [Chat List] "clearUnfinishedInputForSession"

- [+] feat(chat-list.tsx): add clearUnfinishedInputForSession functionality on session deletion
  • Loading branch information
H0llyW00dzZ authored Feb 8, 2024
1 parent b33d507 commit fe2f09e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/components/chat-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Mask } from "../store/mask";
import { useRef, useEffect, useState } from "react";
import { showConfirm, SearchInput } from "./ui-lib";
import { useMobileScreen } from "../utils";
import { clearUnfinishedInputForSession } from "../utils/storageHelper";

export function ChatItem(props: {
onClick?: () => void;
Expand Down Expand Up @@ -174,7 +175,9 @@ export function ChatList(props: { narrow?: boolean; search: string }) {
(!props.narrow && !isMobileScreen) ||
(await showConfirm(Locale.Home.DeleteChat))
) {
const sessionIdToDelete = item.id;
chatStore.deleteSession(i);
clearUnfinishedInputForSession(sessionIdToDelete); // Use the session ID of the item being deleted
}
}}
narrow={props.narrow}
Expand Down
8 changes: 8 additions & 0 deletions app/utils/storageHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// easy maintain unlike stupid complexity
import { UNFINISHED_INPUT } from "../constant";

// Function to clear unfinished input from local storage for a given session ID
export const clearUnfinishedInputForSession = (sessionId: string) => {
const key = UNFINISHED_INPUT(sessionId);
localStorage.removeItem(key);
};

0 comments on commit fe2f09e

Please sign in to comment.