mirror of
https://github.com/Yidadaa/ChatGPT-Next-Web.git
synced 2025-08-08 11:50:33 +08:00
perf: improve prompt list performance
This commit is contained in:
@@ -17,11 +17,12 @@ export interface PromptStore {
|
||||
prompts: Record<number, Prompt>;
|
||||
|
||||
add: (prompt: Prompt) => number;
|
||||
get: (id: number) => Prompt | undefined;
|
||||
remove: (id: number) => void;
|
||||
search: (text: string) => Prompt[];
|
||||
update: (id: number, updater: (prompt: Prompt) => void) => void;
|
||||
|
||||
getUserPrompts: () => Prompt[];
|
||||
updateUserPrompts: (id: number, updater: (prompt: Prompt) => void) => void;
|
||||
}
|
||||
|
||||
export const SearchService = {
|
||||
@@ -81,6 +82,16 @@ export const usePromptStore = create<PromptStore>()(
|
||||
return prompt.id!;
|
||||
},
|
||||
|
||||
get(id) {
|
||||
const targetPrompt = get().prompts[id];
|
||||
|
||||
if (!targetPrompt) {
|
||||
return SearchService.builtinPrompts.find((v) => v.id === id);
|
||||
}
|
||||
|
||||
return targetPrompt;
|
||||
},
|
||||
|
||||
remove(id) {
|
||||
const prompts = get().prompts;
|
||||
delete prompts[id];
|
||||
@@ -98,7 +109,7 @@ export const usePromptStore = create<PromptStore>()(
|
||||
return userPrompts;
|
||||
},
|
||||
|
||||
updateUserPrompts(id: number, updater) {
|
||||
update(id: number, updater) {
|
||||
const prompt = get().prompts[id] ?? {
|
||||
title: "",
|
||||
content: "",
|
||||
|
Reference in New Issue
Block a user