refac: chat input object localStorage -> sessionStorage

This commit is contained in:
Timothy Jaeryang Baek 2025-06-18 16:02:29 +04:00
parent 34440f95dc
commit 1547235d47
4 changed files with 17 additions and 13 deletions

View File

@ -347,6 +347,8 @@ export const userSignOut = async () => {
if (error) {
throw error;
}
sessionStorage.clear();
return res;
};

View File

@ -153,10 +153,10 @@
webSearchEnabled = false;
imageGenerationEnabled = false;
if (localStorage.getItem(`chat-input${chatIdProp ? `-${chatIdProp}` : ''}`)) {
if (sessionStorage.getItem(`chat-input${chatIdProp ? `-${chatIdProp}` : ''}`)) {
try {
const input = JSON.parse(
localStorage.getItem(`chat-input${chatIdProp ? `-${chatIdProp}` : ''}`)
sessionStorage.getItem(`chat-input${chatIdProp ? `-${chatIdProp}` : ''}`)
);
if (!$temporaryChatEnabled) {
@ -446,7 +446,7 @@
}
});
if (localStorage.getItem(`chat-input${chatIdProp ? `-${chatIdProp}` : ''}`)) {
if (sessionStorage.getItem(`chat-input${chatIdProp ? `-${chatIdProp}` : ''}`)) {
prompt = '';
files = [];
selectedToolIds = [];
@ -457,7 +457,7 @@
try {
const input = JSON.parse(
localStorage.getItem(`chat-input${chatIdProp ? `-${chatIdProp}` : ''}`)
sessionStorage.getItem(`chat-input${chatIdProp ? `-${chatIdProp}` : ''}`)
);
if (!$temporaryChatEnabled) {
@ -2120,12 +2120,12 @@
onChange={(input) => {
if (!$temporaryChatEnabled) {
if (input.prompt !== null) {
localStorage.setItem(
sessionStorage.setItem(
`chat-input${$chatId ? `-${$chatId}` : ''}`,
JSON.stringify(input)
);
} else {
localStorage.removeItem(`chat-input${$chatId ? `-${$chatId}` : ''}`);
sessionStorage.removeItem(`chat-input${$chatId ? `-${$chatId}` : ''}`);
}
}
}}

View File

@ -164,7 +164,9 @@
<Tooltip
className=" w-fit"
content={marked.parse(
sanitizeResponseContent(models[selectedModelIdx]?.info?.meta?.description ?? '').replaceAll('\n', '<br>')
sanitizeResponseContent(
models[selectedModelIdx]?.info?.meta?.description ?? ''
).replaceAll('\n', '<br>')
)}
placement="top"
>
@ -172,7 +174,9 @@
class="mt-0.5 px-2 text-sm font-normal text-gray-500 dark:text-gray-400 line-clamp-2 max-w-xl markdown"
>
{@html marked.parse(
sanitizeResponseContent(models[selectedModelIdx]?.info?.meta?.description ?? '').replaceAll('\n', '<br>')
sanitizeResponseContent(
models[selectedModelIdx]?.info?.meta?.description ?? ''
).replaceAll('\n', '<br>')
)}
</div>
</Tooltip>
@ -218,9 +222,9 @@
onChange={(input) => {
if (!$temporaryChatEnabled) {
if (input.prompt !== null) {
localStorage.setItem(`chat-input`, JSON.stringify(input));
sessionStorage.setItem(`chat-input`, JSON.stringify(input));
} else {
localStorage.removeItem(`chat-input`);
sessionStorage.removeItem(`chat-input`);
}
}
}}

View File

@ -78,9 +78,7 @@
// IndexedDB Not Found
}
const chatInputKeys = Object.keys(localStorage).filter((key) =>
key.startsWith('chat-input-')
);
const chatInputKeys = Object.keys(localStorage).filter((key) => key.startsWith('chat-input'));
if (chatInputKeys.length > 0) {
chatInputKeys.forEach((key) => {
localStorage.removeItem(key);