This repository has been archived by the owner on Sep 15, 2024. It is now read-only.
forked from ChatGPTNextWeb/NextChat
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify CodeBase to avoid stupid complexity overhead (#267)
* Feat [Utility] [Storage Helper] "debounce" - [+] feat(storageHelper.ts): add debouncedSave function - [+] refactor(storageHelper.ts): import debounce from lodash - [+] feat(storageHelper.ts): add check for input starting with ChatCommandPrefix * Refactor [UI/UX] [Front End] [Chat List] "debouncedSave" - [+] refactor(chat.tsx): move debouncedSave function to storageHelper module
- Loading branch information
1 parent
fe2f09e
commit 868bbff
Showing
2 changed files
with
12 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,19 @@ | ||
// easy maintain unlike stupid complexity | ||
import { debounce } from "lodash"; | ||
import { UNFINISHED_INPUT } from "../constant"; | ||
import { ChatCommandPrefix } from "../command"; | ||
|
||
// 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); | ||
}; | ||
|
||
// Initialize the debounced function outside of the useCallback. | ||
export const debouncedSave = debounce((input, key) => { | ||
if (input && !input.startsWith(ChatCommandPrefix)) { | ||
localStorage.setItem(key, input); | ||
} else { | ||
localStorage.removeItem(key); | ||
} | ||
}, 500); |