Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
13d9e667
Commit
13d9e667
authored
Jan 06, 2024
by
Timothy J. Baek
Browse files
feat: chat history incognito mode
parent
77a4c4ce
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
327 additions
and
257 deletions
+327
-257
src/lib/components/chat/SettingsModal.svelte
src/lib/components/chat/SettingsModal.svelte
+5
-0
src/lib/components/layout/Sidebar.svelte
src/lib/components/layout/Sidebar.svelte
+280
-231
src/routes/(app)/+page.svelte
src/routes/(app)/+page.svelte
+36
-26
src/routes/(app)/c/[id]/+page.svelte
src/routes/(app)/c/[id]/+page.svelte
+6
-0
No files found.
src/lib/components/chat/SettingsModal.svelte
View file @
13d9e667
...
@@ -238,6 +238,11 @@
...
@@ -238,6 +238,11 @@
const toggleSaveChatHistory = async () => {
const toggleSaveChatHistory = async () => {
saveChatHistory = !saveChatHistory;
saveChatHistory = !saveChatHistory;
console.log(saveChatHistory);
if (saveChatHistory === false) {
await goto('/');
}
saveSettings({ saveChatHistory: saveChatHistory });
saveSettings({ saveChatHistory: saveChatHistory });
};
};
...
...
src/lib/components/layout/Sidebar.svelte
View file @
13d9e667
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
import { goto, invalidateAll } from '$app/navigation';
import { goto, invalidateAll } from '$app/navigation';
import { page } from '$app/stores';
import { page } from '$app/stores';
import { user, chats, showSettings, chatId } from '$lib/stores';
import { user, chats,
settings,
showSettings, chatId } from '$lib/stores';
import { onMount } from 'svelte';
import { onMount } from 'svelte';
import { deleteChatById, getChatList, updateChatById } from '$lib/apis/chats';
import { deleteChatById, getChatList, updateChatById } from '$lib/apis/chats';
...
@@ -49,6 +49,12 @@
...
@@ -49,6 +49,12 @@
await deleteChatById(localStorage.token, id);
await deleteChatById(localStorage.token, id);
await chats.set(await getChatList(localStorage.token));
await chats.set(await getChatList(localStorage.token));
};
};
const saveSettings = async (updated) => {
await settings.set({ ...$settings, ...updated });
localStorage.setItem('settings', JSON.stringify($settings));
location.href = '/';
};
</script>
</script>
<div
<div
...
@@ -159,6 +165,48 @@
...
@@ -159,6 +165,48 @@
</div>
</div>
{/if}
{/if}
<div class="relative flex flex-col flex-1 overflow-y-auto">
{#if !($settings.saveChatHistory ?? true)}
<div class="absolute z-40 w-full h-full bg-black/90 flex justify-center">
<div class=" text-left px-5 py-2">
<div class=" font-medium">Chat History is off for this browser.</div>
<div class="text-xs mt-2">
When history is turned off, new chats on this browser won't appear in your history on
any of your devices. <span class=" font-semibold"
>This setting does not sync across browsers or devices.</span
>
</div>
<div class="mt-3">
<button
class="flex justify-center items-center space-x-1.5 px-3 py-2.5 rounded-lg text-xs bg-gray-200 hover:bg-gray-300 transition text-gray-800 font-medium w-full"
type="button"
on:click={() => {
saveSettings({
saveChatHistory: true
});
}}
>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 16 16"
fill="currentColor"
class="w-3 h-3"
>
<path
fill-rule="evenodd"
d="M8 1a.75.75 0 0 1 .75.75v6.5a.75.75 0 0 1-1.5 0v-6.5A.75.75 0 0 1 8 1ZM4.11 3.05a.75.75 0 0 1 0 1.06 5.5 5.5 0 1 0 7.78 0 .75.75 0 0 1 1.06-1.06 7 7 0 1 1-9.9 0 .75.75 0 0 1 1.06 0Z"
clip-rule="evenodd"
/>
</svg>
<div>Enable Chat History</div>
</button>
</div>
</div>
</div>
{/if}
<div class="px-2.5 mt-1 mb-2 flex justify-center space-x-2">
<div class="px-2.5 mt-1 mb-2 flex justify-center space-x-2">
<div class="flex w-full" id="chat-search">
<div class="flex w-full" id="chat-search">
<div class="self-center pl-3 py-2 rounded-l bg-gray-950">
<div class="self-center pl-3 py-2 rounded-l bg-gray-950">
...
@@ -407,6 +455,7 @@
...
@@ -407,6 +455,7 @@
</div>
</div>
{/each}
{/each}
</div>
</div>
</div>
<div class="px-2.5">
<div class="px-2.5">
<hr class=" border-gray-900 mb-1 w-full" />
<hr class=" border-gray-900 mb-1 w-full" />
...
...
src/routes/(app)/+page.svelte
View file @
13d9e667
...
@@ -280,12 +280,14 @@
...
@@ -280,12 +280,14 @@
}
}
if ($chatId == _chatId) {
if ($chatId == _chatId) {
if ($settings.saveChatHistory ?? true) {
chat = await updateChatById(localStorage.token, _chatId, {
chat = await updateChatById(localStorage.token, _chatId, {
messages: messages,
messages: messages,
history: history
history: history
});
});
await chats.set(await getChatList(localStorage.token));
await chats.set(await getChatList(localStorage.token));
}
}
}
} else {
} else {
if (res !== null) {
if (res !== null) {
const error = await res.json();
const error = await res.json();
...
@@ -444,12 +446,14 @@
...
@@ -444,12 +446,14 @@
}
}
if ($chatId == _chatId) {
if ($chatId == _chatId) {
if ($settings.saveChatHistory ?? true) {
chat = await updateChatById(localStorage.token, _chatId, {
chat = await updateChatById(localStorage.token, _chatId, {
messages: messages,
messages: messages,
history: history
history: history
});
});
await chats.set(await getChatList(localStorage.token));
await chats.set(await getChatList(localStorage.token));
}
}
}
} else {
} else {
if (res !== null) {
if (res !== null) {
const error = await res.json();
const error = await res.json();
...
@@ -527,6 +531,7 @@
...
@@ -527,6 +531,7 @@
// Create new chat if only one message in messages
// Create new chat if only one message in messages
if (messages.length == 1) {
if (messages.length == 1) {
if ($settings.saveChatHistory ?? true) {
chat = await createNewChat(localStorage.token, {
chat = await createNewChat(localStorage.token, {
id: $chatId,
id: $chatId,
title: 'New Chat',
title: 'New Chat',
...
@@ -541,6 +546,9 @@
...
@@ -541,6 +546,9 @@
});
});
await chats.set(await getChatList(localStorage.token));
await chats.set(await getChatList(localStorage.token));
await chatId.set(chat.id);
await chatId.set(chat.id);
} else {
await chatId.set('local');
}
await tick();
await tick();
}
}
...
@@ -592,8 +600,10 @@
...
@@ -592,8 +600,10 @@
title = _title;
title = _title;
}
}
if ($settings.saveChatHistory ?? true) {
chat = await updateChatById(localStorage.token, _chatId, { title: _title });
chat = await updateChatById(localStorage.token, _chatId, { title: _title });
await chats.set(await getChatList(localStorage.token));
await chats.set(await getChatList(localStorage.token));
}
};
};
</script>
</script>
...
...
src/routes/(app)/c/[id]/+page.svelte
View file @
13d9e667
...
@@ -609,6 +609,12 @@
...
@@ -609,6 +609,12 @@
chat = await updateChatById(localStorage.token, _chatId, { title: _title });
chat = await updateChatById(localStorage.token, _chatId, { title: _title });
await chats.set(await getChatList(localStorage.token));
await chats.set(await getChatList(localStorage.token));
};
};
onMount(async () => {
if (!($settings.saveChatHistory ?? true)) {
await goto('/');
}
});
</script>
</script>
<svelte:window
<svelte:window
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment