forked from XiaoMo/ChatGPT-Next-Web
fix: #613 show all prompts when input /
This commit is contained in:
parent
13035ecb0d
commit
637cda5b4c
@ -417,9 +417,6 @@ export function Chat(props: {
|
|||||||
// check if need to trigger auto completion
|
// check if need to trigger auto completion
|
||||||
if (text.startsWith("/")) {
|
if (text.startsWith("/")) {
|
||||||
let searchText = text.slice(1);
|
let searchText = text.slice(1);
|
||||||
if (searchText.length === 0) {
|
|
||||||
searchText = " ";
|
|
||||||
}
|
|
||||||
onSearch(searchText);
|
onSearch(searchText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,11 +21,11 @@ const cn = {
|
|||||||
Rename: "重命名对话",
|
Rename: "重命名对话",
|
||||||
Typing: "正在输入…",
|
Typing: "正在输入…",
|
||||||
Input: (submitKey: string) => {
|
Input: (submitKey: string) => {
|
||||||
var inputHints = `输入消息,${submitKey} 发送`;
|
var inputHints = `${submitKey} 发送`;
|
||||||
if (submitKey === String(SubmitKey.Enter)) {
|
if (submitKey === String(SubmitKey.Enter)) {
|
||||||
inputHints += ",Shift + Enter 换行";
|
inputHints += ",Shift + Enter 换行";
|
||||||
}
|
}
|
||||||
return inputHints;
|
return inputHints + ",/ 触发补全";
|
||||||
},
|
},
|
||||||
Send: "发送",
|
Send: "发送",
|
||||||
},
|
},
|
||||||
|
@ -23,11 +23,11 @@ const en: LocaleType = {
|
|||||||
Rename: "Rename Chat",
|
Rename: "Rename Chat",
|
||||||
Typing: "Typing…",
|
Typing: "Typing…",
|
||||||
Input: (submitKey: string) => {
|
Input: (submitKey: string) => {
|
||||||
var inputHints = `Type something and press ${submitKey} to send`;
|
var inputHints = `${submitKey} to send`;
|
||||||
if (submitKey === String(SubmitKey.Enter)) {
|
if (submitKey === String(SubmitKey.Enter)) {
|
||||||
inputHints += ", press Shift + Enter to newline";
|
inputHints += ", Shift + Enter to wrap";
|
||||||
}
|
}
|
||||||
return inputHints;
|
return inputHints + ", / to search prompts";
|
||||||
},
|
},
|
||||||
Send: "Send",
|
Send: "Send",
|
||||||
},
|
},
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
import { persist } from "zustand/middleware";
|
import { persist } from "zustand/middleware";
|
||||||
import Fuse from "fuse.js";
|
import Fuse from "fuse.js";
|
||||||
|
import { getLang } from "../locales";
|
||||||
|
|
||||||
export interface Prompt {
|
export interface Prompt {
|
||||||
id?: number;
|
id?: number;
|
||||||
@ -25,11 +26,13 @@ export const SearchService = {
|
|||||||
count: {
|
count: {
|
||||||
builtin: 0,
|
builtin: 0,
|
||||||
},
|
},
|
||||||
|
allBuiltInPrompts: [] as Prompt[],
|
||||||
|
|
||||||
init(prompts: Prompt[]) {
|
init(prompts: Prompt[]) {
|
||||||
if (this.ready) {
|
if (this.ready) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.allBuiltInPrompts = prompts;
|
||||||
this.engine.setCollection(prompts);
|
this.engine.setCollection(prompts);
|
||||||
this.ready = true;
|
this.ready = true;
|
||||||
},
|
},
|
||||||
@ -78,6 +81,11 @@ export const usePromptStore = create<PromptStore>()(
|
|||||||
},
|
},
|
||||||
|
|
||||||
search(text) {
|
search(text) {
|
||||||
|
if (text.length === 0) {
|
||||||
|
// return all prompts
|
||||||
|
const userPrompts = get().prompts?.values?.() ?? [];
|
||||||
|
return SearchService.allBuiltInPrompts.concat([...userPrompts]);
|
||||||
|
}
|
||||||
return SearchService.search(text) as Prompt[];
|
return SearchService.search(text) as Prompt[];
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
@ -92,7 +100,11 @@ export const usePromptStore = create<PromptStore>()(
|
|||||||
fetch(PROMPT_URL)
|
fetch(PROMPT_URL)
|
||||||
.then((res) => res.json())
|
.then((res) => res.json())
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
const builtinPrompts = [res.en, res.cn]
|
let fetchPrompts = [res.en, res.cn];
|
||||||
|
if (getLang() === "cn") {
|
||||||
|
fetchPrompts = fetchPrompts.reverse();
|
||||||
|
}
|
||||||
|
const builtinPrompts = fetchPrompts
|
||||||
.map((promptList: PromptList) => {
|
.map((promptList: PromptList) => {
|
||||||
return promptList.map(
|
return promptList.map(
|
||||||
([title, content]) =>
|
([title, content]) =>
|
||||||
|
Loading…
Reference in New Issue
Block a user