auto create new chatStore if there any params in URL
This commit is contained in:
32
src/app.tsx
32
src/app.tsx
@@ -89,13 +89,7 @@ export function App() {
|
|||||||
_setChatStore(getChatStoreByIndex(selectedChatIndex));
|
_setChatStore(getChatStoreByIndex(selectedChatIndex));
|
||||||
}, [selectedChatIndex]);
|
}, [selectedChatIndex]);
|
||||||
|
|
||||||
return (
|
const handleNewChatStore = () => {
|
||||||
<div className="flex text-sm h-full bg-slate-200 dark:bg-slate-800 dark:text-white">
|
|
||||||
<div className="flex flex-col h-full p-2 border-r-indigo-500 border-2 dark:border-slate-800 dark:border-r-indigo-500 dark:text-black">
|
|
||||||
<div className="grow overflow-scroll">
|
|
||||||
<button
|
|
||||||
className="bg-violet-300 p-1 rounded hover:bg-violet-400"
|
|
||||||
onClick={() => {
|
|
||||||
const max = Math.max(...allChatStoreIndexes);
|
const max = Math.max(...allChatStoreIndexes);
|
||||||
const next = max + 1;
|
const next = max + 1;
|
||||||
console.log("save next chat", next);
|
console.log("save next chat", next);
|
||||||
@@ -113,7 +107,27 @@ export function App() {
|
|||||||
allChatStoreIndexes.push(next);
|
allChatStoreIndexes.push(next);
|
||||||
setAllChatStoreIndexes([...allChatStoreIndexes]);
|
setAllChatStoreIndexes([...allChatStoreIndexes]);
|
||||||
setSelectedChatIndex(next);
|
setSelectedChatIndex(next);
|
||||||
}}
|
};
|
||||||
|
|
||||||
|
// if there are any params in URL, create a new chatStore
|
||||||
|
useEffect(() => {
|
||||||
|
if (
|
||||||
|
getDefaultParams("api", "") ||
|
||||||
|
getDefaultParams("key", "") ||
|
||||||
|
getDefaultParams("mode", "") ||
|
||||||
|
getDefaultParams("sys", "")
|
||||||
|
) {
|
||||||
|
handleNewChatStore();
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex text-sm h-full bg-slate-200 dark:bg-slate-800 dark:text-white">
|
||||||
|
<div className="flex flex-col h-full p-2 border-r-indigo-500 border-2 dark:border-slate-800 dark:border-r-indigo-500 dark:text-black">
|
||||||
|
<div className="grow overflow-scroll">
|
||||||
|
<button
|
||||||
|
className="bg-violet-300 p-1 rounded hover:bg-violet-400"
|
||||||
|
onClick={handleNewChatStore}
|
||||||
>
|
>
|
||||||
NEW
|
NEW
|
||||||
</button>
|
</button>
|
||||||
@@ -126,7 +140,7 @@ export function App() {
|
|||||||
return (
|
return (
|
||||||
<li>
|
<li>
|
||||||
<button
|
<button
|
||||||
className={`w-full my-1 p-1 rounded hover:bg-blue-300 ${
|
className={`w-full my-1 p-1 rounded hover:bg-blue-500 ${
|
||||||
i === selectedChatIndex ? "bg-blue-500" : "bg-blue-200"
|
i === selectedChatIndex ? "bg-blue-500" : "bg-blue-200"
|
||||||
}`}
|
}`}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
|||||||
@@ -191,6 +191,10 @@ export default function ChatBOX(props: {
|
|||||||
<p className="opacity-60 p-6 rounded bg-white my-3 text-left dark:text-black">
|
<p className="opacity-60 p-6 rounded bg-white my-3 text-left dark:text-black">
|
||||||
暂无历史对话记录
|
暂无历史对话记录
|
||||||
<br />
|
<br />
|
||||||
|
⚙Key: {chatStore.apiKey}
|
||||||
|
<br />
|
||||||
|
⚙Endpoint: {chatStore.apiEndpoint}
|
||||||
|
<br />
|
||||||
⬆点击上方更改此对话的参数
|
⬆点击上方更改此对话的参数
|
||||||
<br />
|
<br />
|
||||||
↖点击左上角 NEW 新建对话
|
↖点击左上角 NEW 新建对话
|
||||||
|
|||||||
Reference in New Issue
Block a user