Skip to content

Commit

Permalink
Merge pull request #346 from AprilNEA/reset
Browse files Browse the repository at this point in the history
The Clear Data button on the Settings page is only clear for all dialog data.
  • Loading branch information
Yidadaa authored Apr 2, 2023
2 parents 2d534bf + 0a60a87 commit d226090
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 28 deletions.
2 changes: 1 addition & 1 deletion app/api/openai/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ async function makeRequest(req: NextRequest) {
try {
const api = await requestOpenai(req);
const res = new NextResponse(api.body);
res.headers.set('Content-Type', 'application/json');
res.headers.set("Content-Type", "application/json");
return res;
} catch (e) {
console.error("[OpenAI] ", req.body, e);
Expand Down
16 changes: 8 additions & 8 deletions app/components/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export function ChatList() {
state.currentSessionIndex,
state.selectSession,
state.removeSession,
]
],
);

return (
Expand All @@ -134,7 +134,7 @@ function useSubmitHandler() {

const shouldSubmit = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
if (e.key !== "Enter") return false;
if(e.key==='Enter' && e.nativeEvent.isComposing) return false
if (e.key === "Enter" && e.nativeEvent.isComposing) return false;
return (
(config.submitKey === SubmitKey.AltEnter && e.altKey) ||
(config.submitKey === SubmitKey.CtrlEnter && e.ctrlKey) ||
Expand Down Expand Up @@ -202,7 +202,7 @@ export function Chat(props: {
setPromptHints(promptStore.search(text));
},
100,
{ leading: true, trailing: true }
{ leading: true, trailing: true },
);

const onPromptSelect = (prompt: Prompt) => {
Expand All @@ -216,7 +216,7 @@ export function Chat(props: {
if (!dom) return;
const paddingBottomNum: number = parseInt(
window.getComputedStyle(dom).paddingBottom,
10
10,
);
dom.scrollTop = dom.scrollHeight - dom.offsetHeight + paddingBottomNum;
};
Expand Down Expand Up @@ -304,7 +304,7 @@ export function Chat(props: {
preview: true,
},
]
: []
: [],
)
.concat(
userInput.length > 0
Expand All @@ -316,7 +316,7 @@ export function Chat(props: {
preview: true,
},
]
: []
: [],
);

// auto scroll
Expand Down Expand Up @@ -354,7 +354,7 @@ export function Chat(props: {
const newTopic = prompt(Locale.Chat.Rename, session.topic);
if (newTopic && newTopic !== session.topic) {
chatStore.updateCurrentSession(
(session) => (session.topic = newTopic!)
(session) => (session.topic = newTopic!),
);
}
}}
Expand Down Expand Up @@ -603,7 +603,7 @@ export function Home() {
state.newSession,
state.currentSessionIndex,
state.removeSession,
]
],
);
const loading = !useHasHydrated();
const [showSideBar, setShowSideBar] = useState(true);
Expand Down
10 changes: 5 additions & 5 deletions app/components/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ function SettingItem(props: {

export function Settings(props: { closeSettings: () => void }) {
const [showEmojiPicker, setShowEmojiPicker] = useState(false);
const [config, updateConfig, resetConfig, clearAllData] = useChatStore(
(state) => [
const [config, updateConfig, resetConfig, clearAllData, clearSessions] =
useChatStore((state) => [
state.config,
state.updateConfig,
state.resetConfig,
state.clearAllData,
],
);
state.clearSessions,
]);

const updateStore = useUpdateStore();
const [checkingUpdate, setCheckingUpdate] = useState(false);
Expand Down Expand Up @@ -120,7 +120,7 @@ export function Settings(props: { closeSettings: () => void }) {
<div className={styles["window-action-button"]}>
<IconButton
icon={<ClearIcon />}
onClick={clearAllData}
onClick={clearSessions}
bordered
title={Locale.Settings.Actions.ClearAll}
/>
Expand Down
8 changes: 5 additions & 3 deletions app/locales/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,14 @@ const es: LocaleType = {
Summarize:
"Resuma nuestra discusión brevemente en 50 caracteres o menos para usarlo como un recordatorio para futuros contextos.",
},
ConfirmClearAll: "¿Confirmar para borrar todos los datos de chat y configuración?",
ConfirmClearAll:
"¿Confirmar para borrar todos los datos de chat y configuración?",
},
Copy: {
Success: "Copiado al portapapeles",
Failed: "La copia falló, por favor concede permiso para acceder al portapapeles",
Failed:
"La copia falló, por favor concede permiso para acceder al portapapeles",
},
};

export default es;
export default es;
2 changes: 1 addition & 1 deletion app/locales/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ export function changeLang(lang: Lang) {
location.reload();
}

export default { en: EN, cn: CN, tw: TW, es: ES }[getLang()];
export default { en: EN, cn: CN, tw: TW, es: ES }[getLang()];
10 changes: 5 additions & 5 deletions app/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { filterConfig, Message, ModelConfig, useAccessStore } from "./store";
import Locale from "./locales";

if (!Array.prototype.at) {
require('array.prototype.at/auto');
require("array.prototype.at/auto");
}

const TIME_OUT_MS = 30000;
Expand All @@ -13,7 +13,7 @@ const makeRequestParam = (
options?: {
filterBot?: boolean;
stream?: boolean;
}
},
): ChatRequest => {
let sendMessages = messages.map((v) => ({
role: v.role,
Expand Down Expand Up @@ -74,7 +74,7 @@ export async function requestChat(messages: Message[]) {

export async function requestUsage() {
const res = await requestOpenaiClient(
"dashboard/billing/credit_grants?_vercel_no_cache=1"
"dashboard/billing/credit_grants?_vercel_no_cache=1",
)(null, "GET");

try {
Expand All @@ -97,7 +97,7 @@ export async function requestChatStream(
onMessage: (message: string, done: boolean) => void;
onError: (error: Error) => void;
onController?: (controller: AbortController) => void;
}
},
) {
const req = makeRequestParam(messages, {
stream: true,
Expand Down Expand Up @@ -192,7 +192,7 @@ export const ControllerPool = {
addController(
sessionIndex: number,
messageIndex: number,
controller: AbortController
controller: AbortController,
) {
const key = this.key(sessionIndex, messageIndex);
this.controllers[key] = controller;
Expand Down
10 changes: 9 additions & 1 deletion app/store/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { trimTopic } from "../utils";
import Locale from "../locales";

if (!Array.prototype.at) {
require('array.prototype.at/auto');
require("array.prototype.at/auto");
}

export type Message = ChatCompletionResponseMessage & {
Expand Down Expand Up @@ -189,6 +189,7 @@ interface ChatStore {
config: ChatConfig;
sessions: ChatSession[];
currentSessionIndex: number;
clearSessions: () => void;
removeSession: (index: number) => void;
selectSession: (index: number) => void;
newSession: () => void;
Expand Down Expand Up @@ -227,6 +228,13 @@ export const useChatStore = create<ChatStore>()(
...DEFAULT_CONFIG,
},

clearSessions() {
set(() => ({
sessions: [createEmptySession()],
currentSessionIndex: 0,
}));
},

resetConfig() {
set(() => ({ config: { ...DEFAULT_CONFIG } }));
},
Expand Down
8 changes: 4 additions & 4 deletions app/store/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,19 @@ export const usePromptStore = create<PromptStore>()(
({
title,
content,
} as Prompt)
} as Prompt),
);
})
.concat([...(state?.prompts?.values() ?? [])]);

const allPromptsForSearch = builtinPrompts.reduce(
(pre, cur) => pre.concat(cur),
[]
[],
);
SearchService.count.builtin = res.en.length + res.cn.length;
SearchService.init(allPromptsForSearch);
});
},
}
)
},
),
);

1 comment on commit d226090

@vercel
Copy link

@vercel vercel bot commented on d226090 Apr 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.