From ccacfec918dede1906d72f9366c973e3de96178b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BB=87=E6=A2=A6=E4=BA=BA?= Date: Thu, 5 Sep 2024 21:19:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E8=81=8A=E5=A4=A9?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=EF=BC=8C=E4=BD=BF=E6=94=AF=E6=8C=81=E5=A4=8D?= =?UTF-8?q?=E5=88=B6=E4=BC=9A=E8=AF=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/command.ts | 1 + app/components/chat.tsx | 1 + app/locales/cn.ts | 1 + app/locales/en.ts | 1 + app/store/chat.ts | 22 ++++++++++++++++++++++ 5 files changed, 26 insertions(+) diff --git a/app/command.ts b/app/command.ts index bea4e06f3..0e4bba85a 100644 --- a/app/command.ts +++ b/app/command.ts @@ -35,6 +35,7 @@ export function useCommand(commands: Commands = {}) { interface ChatCommands { new?: Command; newm?: Command; + copy?: Command; next?: Command; prev?: Command; clear?: Command; diff --git a/app/components/chat.tsx b/app/components/chat.tsx index a2eaba36f..b25675ac5 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -894,6 +894,7 @@ function _Chat() { const chatCommands = useChatCommand({ new: () => chatStore.newSession(), newm: () => navigate(Path.NewChat), + copy: () => chatStore.copySession(), prev: () => chatStore.nextSession(-1), next: () => chatStore.nextSession(1), clear: () => diff --git a/app/locales/cn.ts b/app/locales/cn.ts index edc087ef1..dcb8f1295 100644 --- a/app/locales/cn.ts +++ b/app/locales/cn.ts @@ -47,6 +47,7 @@ const cn = { Commands: { new: "新建聊天", newm: "从面具新建聊天", + copy: "复制当前聊天", next: "下一个聊天", prev: "上一个聊天", clear: "清除上下文", diff --git a/app/locales/en.ts b/app/locales/en.ts index d19fc76a0..4843f3977 100644 --- a/app/locales/en.ts +++ b/app/locales/en.ts @@ -49,6 +49,7 @@ const en: LocaleType = { Commands: { new: "Start a new chat", newm: "Start a new chat with mask", + copy: "Copy the current Chat", next: "Next Chat", prev: "Previous Chat", clear: "Clear Context", diff --git a/app/store/chat.ts b/app/store/chat.ts index 5db48d2c9..59fedcfef 100644 --- a/app/store/chat.ts +++ b/app/store/chat.ts @@ -208,6 +208,28 @@ export const useChatStore = createPersistStore( }); }, + copySession() { + set((state) => { + const { sessions, currentSessionIndex } = state; + const emptySession = createEmptySession(); + + // copy the session + const curSession = JSON.parse( + JSON.stringify(sessions[currentSessionIndex]), + ); + curSession.id = emptySession.id; + curSession.lastUpdate = emptySession.lastUpdate; + + const newSessions = [...sessions]; + newSessions.splice(0, 0, curSession); + + return { + currentSessionIndex: 0, + sessions: newSessions, + }; + }); + }, + moveSession(from: number, to: number) { set((state) => { const { sessions, currentSessionIndex: oldIndex } = state;