|
@@ -1,7 +1,7 @@
|
|
<script lang="ts">
|
|
<script lang="ts">
|
|
import { toast } from 'svelte-sonner';
|
|
import { toast } from 'svelte-sonner';
|
|
- import { goto } from '$app/navigation';
|
|
|
|
- import { onMount, getContext, createEventDispatcher } from 'svelte';
|
|
|
|
|
|
+ import { goto, invalidate, invalidateAll } from '$app/navigation';
|
|
|
|
+ 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 @@
|
|
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 @@
|
|
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 @@
|
|
chatTitle = chat.title;
|
|
chatTitle = chat.title;
|
|
confirmEdit = true;
|
|
confirmEdit = true;
|
|
}}
|
|
}}
|
|
- on:mouseover={(e) => {
|
|
|
|
- if (e.shiftKey) {
|
|
|
|
- // Your code here
|
|
|
|
- console.log('hi');
|
|
|
|
- }
|
|
|
|
|
|
+ on:mouseenter={(e) => {
|
|
|
|
+ mouseOver = true;
|
|
|
|
+ }}
|
|
|
|
+ on:mouseleave={(e) => {
|
|
|
|
+ mouseOver = false;
|
|
}}
|
|
}}
|
|
on:focus={(e) => {}}
|
|
on:focus={(e) => {}}
|
|
draggable="false"
|
|
draggable="false"
|
|
@@ -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,48 +160,85 @@
|
|
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">
|
|
- <button
|
|
|
|
- class=" self-center dark:hover:text-white transition"
|
|
|
|
- on:click={() => {
|
|
|
|
- editChatTitle(chat.id, chatTitle);
|
|
|
|
- confirmEdit = false;
|
|
|
|
- chatTitle = '';
|
|
|
|
- }}
|
|
|
|
- >
|
|
|
|
- <svg
|
|
|
|
- xmlns="http://www.w3.org/2000/svg"
|
|
|
|
- viewBox="0 0 20 20"
|
|
|
|
- fill="currentColor"
|
|
|
|
- class="w-4 h-4"
|
|
|
|
|
|
+ <Tooltip content="Confirm">
|
|
|
|
+ <button
|
|
|
|
+ class=" self-center dark:hover:text-white transition"
|
|
|
|
+ on:click={() => {
|
|
|
|
+ editChatTitle(chat.id, chatTitle);
|
|
|
|
+ confirmEdit = false;
|
|
|
|
+ chatTitle = '';
|
|
|
|
+ }}
|
|
>
|
|
>
|
|
- <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={() => {
|
|
|
|
- confirmEdit = false;
|
|
|
|
- chatTitle = '';
|
|
|
|
- }}
|
|
|
|
- >
|
|
|
|
- <svg
|
|
|
|
- xmlns="http://www.w3.org/2000/svg"
|
|
|
|
- viewBox="0 0 20 20"
|
|
|
|
- fill="currentColor"
|
|
|
|
- class="w-4 h-4"
|
|
|
|
|
|
+ <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>
|
|
|
|
+ </Tooltip>
|
|
|
|
+
|
|
|
|
+ <Tooltip content="Cancel">
|
|
|
|
+ <button
|
|
|
|
+ class=" self-center dark:hover:text-white transition"
|
|
|
|
+ on:click={() => {
|
|
|
|
+ confirmEdit = false;
|
|
|
|
+ chatTitle = '';
|
|
|
|
+ }}
|
|
>
|
|
>
|
|
- <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>
|
|
|
|
|
|
+ <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>
|
|
|
|
+ </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">
|