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
7ba98ad4
Commit
7ba98ad4
authored
Jun 14, 2024
by
Timothy J. Baek
Browse files
feat: chat item shift shorcut
parent
aba2ca39
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
119 additions
and
48 deletions
+119
-48
src/lib/components/chat/Chat.svelte
src/lib/components/chat/Chat.svelte
+7
-2
src/lib/components/layout/Sidebar.svelte
src/lib/components/layout/Sidebar.svelte
+22
-0
src/lib/components/layout/Sidebar/ChatItem.svelte
src/lib/components/layout/Sidebar/ChatItem.svelte
+90
-46
No files found.
src/lib/components/chat/Chat.svelte
View file @
7ba98ad4
...
@@ -111,7 +111,8 @@
...
@@ -111,7 +111,8 @@
$: if (chatIdProp) {
$: if (chatIdProp) {
(async () => {
(async () => {
if (await loadChat()) {
console.log(chatIdProp);
if (chatIdProp && (await loadChat())) {
await tick();
await tick();
loaded = true;
loaded = true;
...
@@ -126,7 +127,11 @@
...
@@ -126,7 +127,11 @@
onMount(async () => {
onMount(async () => {
if (!$chatId) {
if (!$chatId) {
chatId.subscribe(async (value) => {
if (!value) {
await initNewChat();
await initNewChat();
}
});
} else {
} else {
if (!($settings.saveChatHistory ?? true)) {
if (!($settings.saveChatHistory ?? true)) {
await goto('/');
await goto('/');
...
...
src/lib/components/layout/Sidebar.svelte
View file @
7ba98ad4
...
@@ -38,7 +38,10 @@
...
@@ -38,7 +38,10 @@
let navElement;
let navElement;
let search = '';
let search = '';
let shiftKey = false;
let selectedChatId = null;
let selectedChatId = null;
let showDropdown = false;
let showDropdown = false;
let filteredChatList = [];
let filteredChatList = [];
...
@@ -102,10 +105,28 @@
...
@@ -102,10 +105,28 @@
checkDirection();
checkDirection();
};
};
const onKeyDown = (e) => {
if (e.key === 'Shift') {
shiftKey = true;
}
};
const onKeyUp = (e) => {
if (e.key === 'Shift') {
shiftKey = false;
}
};
document.addEventListener('keydown', onKeyDown);
document.addEventListener('keyup', onKeyUp);
window.addEventListener('touchstart', onTouchStart);
window.addEventListener('touchstart', onTouchStart);
window.addEventListener('touchend', onTouchEnd);
window.addEventListener('touchend', onTouchEnd);
return () => {
return () => {
window.removeEventListener('keydown', onKeyDown);
window.removeEventListener('keyup', onKeyUp);
window.removeEventListener('touchstart', onTouchStart);
window.removeEventListener('touchstart', onTouchStart);
window.removeEventListener('touchend', onTouchEnd);
window.removeEventListener('touchend', onTouchEnd);
};
};
...
@@ -407,6 +428,7 @@
...
@@ -407,6 +428,7 @@
<ChatItem
<ChatItem
{chat}
{chat}
{shiftKey}
selected={selectedChatId === chat.id}
selected={selectedChatId === chat.id}
on:select={() => {
on:select={() => {
selectedChatId = chat.id;
selectedChatId = chat.id;
...
...
src/lib/components/layout/Sidebar/ChatItem.svelte
View file @
7ba98ad4
<script lang="ts">
<script lang="ts">
import { toast } from 'svelte-sonner';
import { toast } from 'svelte-sonner';
import { goto } from '$app/navigation';
import { goto
, invalidate, invalidateAll
} from '$app/navigation';
import { onMount, getContext, createEventDispatcher } from 'svelte';
import { onMount, getContext, createEventDispatcher
, tick
} from 'svelte';
const i18n = getContext('i18n');
const i18n = getContext('i18n');
const dispatch = createEventDispatcher();
const dispatch = createEventDispatcher();
...
@@ -18,9 +18,15 @@
...
@@ -18,9 +18,15 @@
import ChatMenu from './ChatMenu.svelte';
import ChatMenu from './ChatMenu.svelte';
import ShareChatModal from '$lib/components/chat/ShareChatModal.svelte';
import ShareChatModal from '$lib/components/chat/ShareChatModal.svelte';
import DeleteConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
import DeleteConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
import GarbageBin from '$lib/components/icons/GarbageBin.svelte';
import Tooltip from '$lib/components/common/Tooltip.svelte';
import ArchiveBox from '$lib/components/icons/ArchiveBox.svelte';
export let chat;
export let chat;
export let selected = false;
export let selected = false;
export let shiftKey = false;
let mouseOver = false;
let showDeleteConfirmDialog = false;
let showDeleteConfirmDialog = false;
let showShareChatModal = false;
let showShareChatModal = false;
...
@@ -43,12 +49,13 @@
...
@@ -43,12 +49,13 @@
const deleteChat = async (id) => {
const deleteChat = async (id) => {
const res = await deleteChatById(localStorage.token, id).catch((error) => {
const res = await deleteChatById(localStorage.token, id).catch((error) => {
toast.error(error);
toast.error(error);
return null;
return null;
});
});
if (res) {
if (res) {
if ($chatId === id) {
if ($chatId === id) {
await chatId.set('');
await tick();
goto('/');
goto('/');
}
}
await chats.set(await getChatList(localStorage.token));
await chats.set(await getChatList(localStorage.token));
...
@@ -125,11 +132,11 @@
...
@@ -125,11 +132,11 @@
chatTitle = chat.title;
chatTitle = chat.title;
confirmEdit = true;
confirmEdit = true;
}}
}}
on:mouse
ov
er={(e) => {
on:mouse
ent
er={(e) => {
if (e.shiftKey) {
mouseOver = true;
// Your code here
}}
console.log('hi');
on:mouseleave={(e) => {
}
mouseOver = false;
}}
}}
on:focus={(e) => {}}
on:focus={(e) => {}}
draggable="false"
draggable="false"
...
@@ -142,9 +149,9 @@
...
@@ -142,9 +149,9 @@
</a>
</a>
{/if}
{/if}
<!-- svelte-ignore a11y-no-static-element-interactions -->
<div
<div
class="
class="
{chat.id === $chatId || confirmEdit
{chat.id === $chatId || confirmEdit
? 'from-gray-200 dark:from-gray-900'
? 'from-gray-200 dark:from-gray-900'
: selected
: selected
...
@@ -153,9 +160,16 @@
...
@@ -153,9 +160,16 @@
absolute right-[10px] top-[10px] pr-2 pl-5 bg-gradient-to-l from-80%
absolute right-[10px] top-[10px] pr-2 pl-5 bg-gradient-to-l from-80%
to-transparent"
to-transparent"
on:mouseenter={(e) => {
mouseOver = true;
}}
on:mouseleave={(e) => {
mouseOver = false;
}}
>
>
{#if confirmEdit}
{#if confirmEdit}
<div class="flex self-center space-x-1.5 z-10">
<div class="flex self-center space-x-1.5 z-10">
<Tooltip content="Confirm">
<button
<button
class=" self-center dark:hover:text-white transition"
class=" self-center dark:hover:text-white transition"
on:click={() => {
on:click={() => {
...
@@ -177,6 +191,9 @@
...
@@ -177,6 +191,9 @@
/>
/>
</svg>
</svg>
</button>
</button>
</Tooltip>
<Tooltip content="Cancel">
<button
<button
class=" self-center dark:hover:text-white transition"
class=" self-center dark:hover:text-white transition"
on:click={() => {
on:click={() => {
...
@@ -195,6 +212,33 @@
...
@@ -195,6 +212,33 @@
/>
/>
</svg>
</svg>
</button>
</button>
</Tooltip>
</div>
{:else if shiftKey && mouseOver}
<div class=" flex items-center self-center space-x-1.5">
<Tooltip content="Archive" className="flex items-center">
<button
class=" self-center dark:hover:text-white transition"
on:click={() => {
archiveChatHandler(chat.id);
}}
type="button"
>
<ArchiveBox className="size-4 translate-y-[0.5px]" strokeWidth="2" />
</button>
</Tooltip>
<Tooltip content="Delete">
<button
class=" self-center dark:hover:text-white transition"
on:click={() => {
deleteChat(chat.id);
}}
type="button"
>
<GarbageBin strokeWidth="2" />
</button>
</Tooltip>
</div>
</div>
{:else}
{:else}
<div class="flex self-center space-x-1 z-10">
<div class="flex self-center space-x-1 z-10">
...
...
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