Skip to content

Commit d226090

Browse files
authored
Merge pull request #346 from AprilNEA/reset
The Clear Data button on the Settings page is only clear for all dialog data.
2 parents 2d534bf + 0a60a87 commit d226090

File tree

8 files changed

+38
-28
lines changed

8 files changed

+38
-28
lines changed

app/api/openai/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ async function makeRequest(req: NextRequest) {
55
try {
66
const api = await requestOpenai(req);
77
const res = new NextResponse(api.body);
8-
res.headers.set('Content-Type', 'application/json');
8+
res.headers.set("Content-Type", "application/json");
99
return res;
1010
} catch (e) {
1111
console.error("[OpenAI] ", req.body, e);

app/components/home.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export function ChatList() {
108108
state.currentSessionIndex,
109109
state.selectSession,
110110
state.removeSession,
111-
]
111+
],
112112
);
113113

114114
return (
@@ -134,7 +134,7 @@ function useSubmitHandler() {
134134

135135
const shouldSubmit = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
136136
if (e.key !== "Enter") return false;
137-
if(e.key==='Enter' && e.nativeEvent.isComposing) return false
137+
if (e.key === "Enter" && e.nativeEvent.isComposing) return false;
138138
return (
139139
(config.submitKey === SubmitKey.AltEnter && e.altKey) ||
140140
(config.submitKey === SubmitKey.CtrlEnter && e.ctrlKey) ||
@@ -202,7 +202,7 @@ export function Chat(props: {
202202
setPromptHints(promptStore.search(text));
203203
},
204204
100,
205-
{ leading: true, trailing: true }
205+
{ leading: true, trailing: true },
206206
);
207207

208208
const onPromptSelect = (prompt: Prompt) => {
@@ -216,7 +216,7 @@ export function Chat(props: {
216216
if (!dom) return;
217217
const paddingBottomNum: number = parseInt(
218218
window.getComputedStyle(dom).paddingBottom,
219-
10
219+
10,
220220
);
221221
dom.scrollTop = dom.scrollHeight - dom.offsetHeight + paddingBottomNum;
222222
};
@@ -304,7 +304,7 @@ export function Chat(props: {
304304
preview: true,
305305
},
306306
]
307-
: []
307+
: [],
308308
)
309309
.concat(
310310
userInput.length > 0
@@ -316,7 +316,7 @@ export function Chat(props: {
316316
preview: true,
317317
},
318318
]
319-
: []
319+
: [],
320320
);
321321

322322
// auto scroll
@@ -354,7 +354,7 @@ export function Chat(props: {
354354
const newTopic = prompt(Locale.Chat.Rename, session.topic);
355355
if (newTopic && newTopic !== session.topic) {
356356
chatStore.updateCurrentSession(
357-
(session) => (session.topic = newTopic!)
357+
(session) => (session.topic = newTopic!),
358358
);
359359
}
360360
}}
@@ -603,7 +603,7 @@ export function Home() {
603603
state.newSession,
604604
state.currentSessionIndex,
605605
state.removeSession,
606-
]
606+
],
607607
);
608608
const loading = !useHasHydrated();
609609
const [showSideBar, setShowSideBar] = useState(true);

app/components/settings.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ function SettingItem(props: {
4949

5050
export function Settings(props: { closeSettings: () => void }) {
5151
const [showEmojiPicker, setShowEmojiPicker] = useState(false);
52-
const [config, updateConfig, resetConfig, clearAllData] = useChatStore(
53-
(state) => [
52+
const [config, updateConfig, resetConfig, clearAllData, clearSessions] =
53+
useChatStore((state) => [
5454
state.config,
5555
state.updateConfig,
5656
state.resetConfig,
5757
state.clearAllData,
58-
],
59-
);
58+
state.clearSessions,
59+
]);
6060

6161
const updateStore = useUpdateStore();
6262
const [checkingUpdate, setCheckingUpdate] = useState(false);
@@ -120,7 +120,7 @@ export function Settings(props: { closeSettings: () => void }) {
120120
<div className={styles["window-action-button"]}>
121121
<IconButton
122122
icon={<ClearIcon />}
123-
onClick={clearAllData}
123+
onClick={clearSessions}
124124
bordered
125125
title={Locale.Settings.Actions.ClearAll}
126126
/>

app/locales/es.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,14 @@ const es: LocaleType = {
143143
Summarize:
144144
"Resuma nuestra discusión brevemente en 50 caracteres o menos para usarlo como un recordatorio para futuros contextos.",
145145
},
146-
ConfirmClearAll: "¿Confirmar para borrar todos los datos de chat y configuración?",
146+
ConfirmClearAll:
147+
"¿Confirmar para borrar todos los datos de chat y configuración?",
147148
},
148149
Copy: {
149150
Success: "Copiado al portapapeles",
150-
Failed: "La copia falló, por favor concede permiso para acceder al portapapeles",
151+
Failed:
152+
"La copia falló, por favor concede permiso para acceder al portapapeles",
151153
},
152154
};
153155

154-
export default es;
156+
export default es;

app/locales/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@ export function changeLang(lang: Lang) {
5757
location.reload();
5858
}
5959

60-
export default { en: EN, cn: CN, tw: TW, es: ES }[getLang()];
60+
export default { en: EN, cn: CN, tw: TW, es: ES }[getLang()];

app/requests.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { filterConfig, Message, ModelConfig, useAccessStore } from "./store";
33
import Locale from "./locales";
44

55
if (!Array.prototype.at) {
6-
require('array.prototype.at/auto');
6+
require("array.prototype.at/auto");
77
}
88

99
const TIME_OUT_MS = 30000;
@@ -13,7 +13,7 @@ const makeRequestParam = (
1313
options?: {
1414
filterBot?: boolean;
1515
stream?: boolean;
16-
}
16+
},
1717
): ChatRequest => {
1818
let sendMessages = messages.map((v) => ({
1919
role: v.role,
@@ -74,7 +74,7 @@ export async function requestChat(messages: Message[]) {
7474

7575
export async function requestUsage() {
7676
const res = await requestOpenaiClient(
77-
"dashboard/billing/credit_grants?_vercel_no_cache=1"
77+
"dashboard/billing/credit_grants?_vercel_no_cache=1",
7878
)(null, "GET");
7979

8080
try {
@@ -97,7 +97,7 @@ export async function requestChatStream(
9797
onMessage: (message: string, done: boolean) => void;
9898
onError: (error: Error) => void;
9999
onController?: (controller: AbortController) => void;
100-
}
100+
},
101101
) {
102102
const req = makeRequestParam(messages, {
103103
stream: true,
@@ -192,7 +192,7 @@ export const ControllerPool = {
192192
addController(
193193
sessionIndex: number,
194194
messageIndex: number,
195-
controller: AbortController
195+
controller: AbortController,
196196
) {
197197
const key = this.key(sessionIndex, messageIndex);
198198
this.controllers[key] = controller;

app/store/app.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { trimTopic } from "../utils";
1212
import Locale from "../locales";
1313

1414
if (!Array.prototype.at) {
15-
require('array.prototype.at/auto');
15+
require("array.prototype.at/auto");
1616
}
1717

1818
export type Message = ChatCompletionResponseMessage & {
@@ -189,6 +189,7 @@ interface ChatStore {
189189
config: ChatConfig;
190190
sessions: ChatSession[];
191191
currentSessionIndex: number;
192+
clearSessions: () => void;
192193
removeSession: (index: number) => void;
193194
selectSession: (index: number) => void;
194195
newSession: () => void;
@@ -227,6 +228,13 @@ export const useChatStore = create<ChatStore>()(
227228
...DEFAULT_CONFIG,
228229
},
229230

231+
clearSessions() {
232+
set(() => ({
233+
sessions: [createEmptySession()],
234+
currentSessionIndex: 0,
235+
}));
236+
},
237+
230238
resetConfig() {
231239
set(() => ({ config: { ...DEFAULT_CONFIG } }));
232240
},

app/store/prompt.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,19 @@ export const usePromptStore = create<PromptStore>()(
9999
({
100100
title,
101101
content,
102-
} as Prompt)
102+
} as Prompt),
103103
);
104104
})
105105
.concat([...(state?.prompts?.values() ?? [])]);
106106

107107
const allPromptsForSearch = builtinPrompts.reduce(
108108
(pre, cur) => pre.concat(cur),
109-
[]
109+
[],
110110
);
111111
SearchService.count.builtin = res.en.length + res.cn.length;
112112
SearchService.init(allPromptsForSearch);
113113
});
114114
},
115-
}
116-
)
115+
},
116+
),
117117
);

0 commit comments

Comments
 (0)