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
aba2ca39
Commit
aba2ca39
authored
Jun 14, 2024
by
Timothy J. Baek
Browse files
enh: delete confirm dialog
parent
8db439a0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
55 deletions
+28
-55
src/lib/components/common/ConfirmDialog.svelte
src/lib/components/common/ConfirmDialog.svelte
+5
-2
src/lib/components/layout/Sidebar/ChatItem.svelte
src/lib/components/layout/Sidebar/ChatItem.svelte
+23
-53
No files found.
src/lib/components/common/ConfirmDialog.svelte
View file @
aba2ca39
...
@@ -9,6 +9,9 @@
...
@@ -9,6 +9,9 @@
export let title = 'Confirm your action';
export let title = 'Confirm your action';
export let message = 'This action cannot be undone. Do you wish to continue?';
export let message = 'This action cannot be undone. Do you wish to continue?';
export let cancelLabel = 'Cancel';
export let confirmLabel = 'Confirm';
export let show = false;
export let show = false;
let modalElement = null;
let modalElement = null;
let mounted = false;
let mounted = false;
...
@@ -70,7 +73,7 @@
...
@@ -70,7 +73,7 @@
}}
}}
type="button"
type="button"
>
>
C
ancel
{c
ancel
Label}
</button>
</button>
<button
<button
class="bg-gray-900 hover:bg-gray-850 text-gray-100 dark:bg-gray-100 dark:hover:bg-white dark:text-gray-800 font-medium w-full py-2.5 rounded-lg transition"
class="bg-gray-900 hover:bg-gray-850 text-gray-100 dark:bg-gray-100 dark:hover:bg-white dark:text-gray-800 font-medium w-full py-2.5 rounded-lg transition"
...
@@ -80,7 +83,7 @@
...
@@ -80,7 +83,7 @@
}}
}}
type="button"
type="button"
>
>
C
onfirm
{c
onfirm
Label}
</button>
</button>
</div>
</div>
</div>
</div>
...
...
src/lib/components/layout/Sidebar/ChatItem.svelte
View file @
aba2ca39
...
@@ -17,17 +17,17 @@
...
@@ -17,17 +17,17 @@
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';
export let chat;
export let chat;
export let selected = false;
let showDeleteConfirmDialog = false;
let showShareChatModal = false;
let showShareChatModal = false;
export let selected = false;
let confirmEdit = false;
let confirmEdit = false;
let confirmDelete = false;
let chatTitle =
''
;
let chatTitle =
chat.title
;
const editChatTitle = async (id, _title) => {
const editChatTitle = async (id, _title) => {
if (_title === '') {
if (_title === '') {
...
@@ -43,7 +43,6 @@
...
@@ -43,7 +43,6 @@
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);
confirmDelete = false;
return null;
return null;
});
});
...
@@ -80,12 +79,22 @@
...
@@ -80,12 +79,22 @@
<ShareChatModal bind:show={showShareChatModal} chatId={chat.id} />
<ShareChatModal bind:show={showShareChatModal} chatId={chat.id} />
<DeleteConfirmDialog
bind:show={showDeleteConfirmDialog}
title="Delete chat?"
on:confirm={() => {
deleteChat(chat.id);
}}
>
<div class=" text-sm text-gray-500">
This will delete <span class=" font-semibold">{chat.title}</span>.
</div>
</DeleteConfirmDialog>
<div class=" w-full pr-2 relative group">
<div class=" w-full pr-2 relative group">
{#if confirmEdit}
{#if confirmEdit}
<div
<div
class=" w-full flex justify-between rounded-xl px-3 py-2 {chat.id === $chatId ||
class=" w-full flex justify-between rounded-xl px-3 py-2 {chat.id === $chatId || confirmEdit
confirmEdit ||
confirmDelete
? 'bg-gray-200 dark:bg-gray-900'
? 'bg-gray-200 dark:bg-gray-900'
: selected
: selected
? 'bg-gray-100 dark:bg-gray-950'
? 'bg-gray-100 dark:bg-gray-950'
...
@@ -99,9 +108,7 @@
...
@@ -99,9 +108,7 @@
</div>
</div>
{:else}
{:else}
<a
<a
class=" w-full flex justify-between rounded-xl px-3 py-2 {chat.id === $chatId ||
class=" w-full flex justify-between rounded-xl px-3 py-2 {chat.id === $chatId || confirmEdit
confirmEdit ||
confirmDelete
? 'bg-gray-200 dark:bg-gray-900'
? 'bg-gray-200 dark:bg-gray-900'
: selected
: selected
? 'bg-gray-100 dark:bg-gray-950'
? 'bg-gray-100 dark:bg-gray-950'
...
@@ -138,7 +145,7 @@
...
@@ -138,7 +145,7 @@
<div
<div
class="
class="
{chat.id === $chatId || confirmEdit
|| confirmDelete
{chat.id === $chatId || confirmEdit
? 'from-gray-200 dark:from-gray-900'
? 'from-gray-200 dark:from-gray-900'
: selected
: selected
? 'from-gray-100 dark:from-gray-950'
? 'from-gray-100 dark:from-gray-950'
...
@@ -189,45 +196,6 @@
...
@@ -189,45 +196,6 @@
</svg>
</svg>
</button>
</button>
</div>
</div>
{:else if confirmDelete}
<div class="flex self-center space-x-1.5 z-10">
<button
class=" self-center dark:hover:text-white transition"
on:click={() => {
deleteChat(chat.id);
}}
>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
class="w-4 h-4"
>
<path
fill-rule="evenodd"
d="M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z"
clip-rule="evenodd"
/>
</svg>
</button>
<button
class=" self-center dark:hover:text-white transition"
on:click={() => {
confirmDelete = false;
}}
>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
class="w-4 h-4"
>
<path
d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
/>
</svg>
</button>
</div>
{:else}
{:else}
<div class="flex self-center space-x-1 z-10">
<div class="flex self-center space-x-1 z-10">
<ChatMenu
<ChatMenu
...
@@ -242,10 +210,12 @@
...
@@ -242,10 +210,12 @@
archiveChatHandler(chat.id);
archiveChatHandler(chat.id);
}}
}}
renameHandler={() => {
renameHandler={() => {
chatTitle = chat.title;
confirmEdit = true;
confirmEdit = true;
}}
}}
deleteHandler={() => {
deleteHandler={() => {
c
onfirmD
elete
= true;
showDeleteC
onfirmD
ialog
= true;
}}
}}
onClose={() => {
onClose={() => {
selected = false;
selected = false;
...
@@ -277,7 +247,7 @@
...
@@ -277,7 +247,7 @@
id="delete-chat-button"
id="delete-chat-button"
class="hidden"
class="hidden"
on:click={() => {
on:click={() => {
c
onfirmD
elete
= true;
showDeleteC
onfirmD
ialog
= true;
}}
}}
>
>
<svg
<svg
...
...
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