feat: 优化聊天窗口,使支持复制会话
This commit is contained in:
parent
2fdb35bcc8
commit
ccacfec918
|
@ -35,6 +35,7 @@ export function useCommand(commands: Commands = {}) {
|
||||||
interface ChatCommands {
|
interface ChatCommands {
|
||||||
new?: Command;
|
new?: Command;
|
||||||
newm?: Command;
|
newm?: Command;
|
||||||
|
copy?: Command;
|
||||||
next?: Command;
|
next?: Command;
|
||||||
prev?: Command;
|
prev?: Command;
|
||||||
clear?: Command;
|
clear?: Command;
|
||||||
|
|
|
@ -894,6 +894,7 @@ function _Chat() {
|
||||||
const chatCommands = useChatCommand({
|
const chatCommands = useChatCommand({
|
||||||
new: () => chatStore.newSession(),
|
new: () => chatStore.newSession(),
|
||||||
newm: () => navigate(Path.NewChat),
|
newm: () => navigate(Path.NewChat),
|
||||||
|
copy: () => chatStore.copySession(),
|
||||||
prev: () => chatStore.nextSession(-1),
|
prev: () => chatStore.nextSession(-1),
|
||||||
next: () => chatStore.nextSession(1),
|
next: () => chatStore.nextSession(1),
|
||||||
clear: () =>
|
clear: () =>
|
||||||
|
|
|
@ -47,6 +47,7 @@ const cn = {
|
||||||
Commands: {
|
Commands: {
|
||||||
new: "新建聊天",
|
new: "新建聊天",
|
||||||
newm: "从面具新建聊天",
|
newm: "从面具新建聊天",
|
||||||
|
copy: "复制当前聊天",
|
||||||
next: "下一个聊天",
|
next: "下一个聊天",
|
||||||
prev: "上一个聊天",
|
prev: "上一个聊天",
|
||||||
clear: "清除上下文",
|
clear: "清除上下文",
|
||||||
|
|
|
@ -49,6 +49,7 @@ const en: LocaleType = {
|
||||||
Commands: {
|
Commands: {
|
||||||
new: "Start a new chat",
|
new: "Start a new chat",
|
||||||
newm: "Start a new chat with mask",
|
newm: "Start a new chat with mask",
|
||||||
|
copy: "Copy the current Chat",
|
||||||
next: "Next Chat",
|
next: "Next Chat",
|
||||||
prev: "Previous Chat",
|
prev: "Previous Chat",
|
||||||
clear: "Clear Context",
|
clear: "Clear Context",
|
||||||
|
|
|
@ -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) {
|
moveSession(from: number, to: number) {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
const { sessions, currentSessionIndex: oldIndex } = state;
|
const { sessions, currentSessionIndex: oldIndex } = state;
|
||||||
|
|
Loading…
Reference in New Issue