mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-10-10 03:56:37 +08:00
Refactor "UI Page [Chats Prompt] (#20))"
[+] refactor(prompt.ts): simplify sorting logic in getUserPrompts method [+] feat(prompt.ts): add support for different languages in fetching prompts
This commit is contained in:
parent
fc4953f9a7
commit
49be21bef9
@ -124,7 +124,7 @@ export const usePromptStore = createPersistStore(
|
|||||||
|
|
||||||
search(text: string) {
|
search(text: string) {
|
||||||
if (text.length === 0) {
|
if (text.length === 0) {
|
||||||
// return all rompts
|
// return all prompts
|
||||||
return this.getUserPrompts().concat(SearchService.builtinPrompts);
|
return this.getUserPrompts().concat(SearchService.builtinPrompts);
|
||||||
}
|
}
|
||||||
return SearchService.search(text) as Prompt[];
|
return SearchService.search(text) as Prompt[];
|
||||||
@ -154,32 +154,38 @@ export const usePromptStore = createPersistStore(
|
|||||||
fetch(PROMPT_URL)
|
fetch(PROMPT_URL)
|
||||||
.then((res) => res.json())
|
.then((res) => res.json())
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
let fetchPrompts = [res.en, res.id, res.cn];
|
const lang = getLang();
|
||||||
if (getLang() === "cn") {
|
let fetchPrompts: PromptList;
|
||||||
fetchPrompts = fetchPrompts.reverse();
|
|
||||||
|
switch (lang) {
|
||||||
|
case "cn":
|
||||||
|
fetchPrompts = res.cn;
|
||||||
|
break;
|
||||||
|
case "id":
|
||||||
|
fetchPrompts = res.id;
|
||||||
|
break;
|
||||||
|
// Add cases for other languages here
|
||||||
|
default:
|
||||||
|
fetchPrompts = res.en;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (getLang() === "id") {
|
|
||||||
fetchPrompts = fetchPrompts.reverse();
|
const builtinPrompts = fetchPrompts.map(
|
||||||
}
|
([title, content]) =>
|
||||||
const builtinPrompts = fetchPrompts.map((promptList: PromptList) => {
|
({
|
||||||
return promptList.map(
|
id: nanoid(),
|
||||||
([title, content]) =>
|
title,
|
||||||
({
|
content,
|
||||||
id: nanoid(),
|
createdAt: Date.now(),
|
||||||
title,
|
}) as Prompt,
|
||||||
content,
|
);
|
||||||
createdAt: Date.now(),
|
|
||||||
}) as Prompt,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
const userPrompts = usePromptStore.getState().getUserPrompts() ?? [];
|
const userPrompts = usePromptStore.getState().getUserPrompts() ?? [];
|
||||||
|
|
||||||
const allPromptsForSearch = builtinPrompts
|
const allPromptsForSearch = builtinPrompts
|
||||||
.reduce((pre, cur) => pre.concat(cur), [])
|
.concat(userPrompts)
|
||||||
.filter((v) => !!v.title && !!v.content);
|
.filter((v) => !!v.title && !!v.content);
|
||||||
SearchService.count.builtin =
|
SearchService.count.builtin = fetchPrompts.length;
|
||||||
res.en.length + res.id.length + res.cn.length;
|
|
||||||
SearchService.init(allPromptsForSearch, userPrompts);
|
SearchService.init(allPromptsForSearch, userPrompts);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user