open-webui/src/lib/components/layout/Sidebar.svelte

689 lines
18 KiB
Svelte
Raw Normal View History

2023-11-20 01:47:07 +00:00
<script lang="ts">
2024-06-15 10:41:48 +00:00
import { toast } from 'svelte-sonner';
2024-04-30 23:34:29 +00:00
import { goto } from '$app/navigation';
2024-05-15 00:50:24 +00:00
import {
user,
chats,
settings,
showSettings,
chatId,
tags,
showSidebar,
2024-05-15 08:22:15 +00:00
mobile,
2024-07-02 06:08:01 +00:00
showArchivedChats,
2024-08-01 19:19:14 +00:00
pinnedChats,
2024-08-04 14:58:08 +00:00
scrollPaginationEnabled,
currentChatPage,
2024-10-06 22:27:19 +00:00
temporaryChatEnabled,
showArtifacts,
showOverview,
showControls
2024-05-15 00:50:24 +00:00
} from '$lib/stores';
2024-10-09 07:13:54 +00:00
import { onMount, getContext, tick, onDestroy } from 'svelte';
2024-03-01 04:40:36 +00:00
const i18n = getContext('i18n');
2024-06-15 10:41:48 +00:00
import { updateUserSettings } from '$lib/apis/users';
2024-01-18 10:55:25 +00:00
import {
deleteChatById,
getChatList,
2024-02-08 00:39:20 +00:00
getChatById,
2024-01-18 10:55:25 +00:00
getChatListByTagName,
2024-02-25 21:03:26 +00:00
updateChatById,
2024-04-20 22:03:39 +00:00
getAllChatTags,
2024-05-31 17:30:42 +00:00
archiveChatById,
2024-10-09 06:37:37 +00:00
cloneChatById,
2024-10-09 07:13:54 +00:00
getChatListBySearchText,
2024-10-11 06:22:53 +00:00
createNewChat,
getPinnedChatList
2024-01-18 10:55:25 +00:00
} from '$lib/apis/chats';
2024-02-24 01:12:19 +00:00
import { WEBUI_BASE_URL } from '$lib/constants';
2024-06-15 10:41:48 +00:00
2024-04-20 23:24:18 +00:00
import ArchivedChatsModal from './Sidebar/ArchivedChatsModal.svelte';
2024-05-09 07:34:57 +00:00
import UserMenu from './Sidebar/UserMenu.svelte';
2024-06-14 18:06:19 +00:00
import ChatItem from './Sidebar/ChatItem.svelte';
2024-06-15 10:41:48 +00:00
import DeleteConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
import Spinner from '../common/Spinner.svelte';
2024-08-04 14:36:44 +00:00
import Loader from '../common/Loader.svelte';
2024-10-09 07:13:54 +00:00
import FilesOverlay from '../chat/MessageInput/FilesOverlay.svelte';
import AddFilesPlaceholder from '../AddFilesPlaceholder.svelte';
2024-10-11 06:43:08 +00:00
import { select } from 'd3-selection';
2024-10-15 00:31:52 +00:00
import SearchInput from './Sidebar/SearchInput.svelte';
2024-10-15 02:33:32 +00:00
import ChevronDown from '../icons/ChevronDown.svelte';
import ChevronUp from '../icons/ChevronUp.svelte';
import ChevronRight from '../icons/ChevronRight.svelte';
2023-11-20 01:47:07 +00:00
2024-05-15 06:48:46 +00:00
const BREAKPOINT = 768;
2024-04-30 23:34:29 +00:00
2023-11-20 01:47:07 +00:00
let navElement;
2023-11-23 22:33:08 +00:00
let search = '';
2023-11-20 01:47:07 +00:00
2024-06-14 20:02:07 +00:00
let shiftKey = false;
2024-03-16 08:57:26 +00:00
let selectedChatId = null;
2024-06-15 10:41:48 +00:00
let deleteChat = null;
2024-06-14 20:02:07 +00:00
2024-06-15 10:41:48 +00:00
let showDeleteConfirm = false;
2023-11-20 01:47:07 +00:00
let showDropdown = false;
2024-07-02 06:08:01 +00:00
2024-09-17 23:21:32 +00:00
let selectedTagName = null;
2024-10-15 02:33:32 +00:00
let showPinnedChat = true;
2024-08-04 14:36:44 +00:00
// Pagination variables
2024-08-04 15:31:41 +00:00
let chatListLoading = false;
2024-08-04 14:36:44 +00:00
let allChatsLoaded = false;
2024-10-09 06:37:37 +00:00
const initChatList = async () => {
2024-08-04 15:31:41 +00:00
// Reset pagination variables
currentChatPage.set(1);
allChatsLoaded = false;
await chats.set(await getChatList(localStorage.token, $currentChatPage));
// Enable pagination
scrollPaginationEnabled.set(true);
};
2024-08-04 14:36:44 +00:00
const loadMoreChats = async () => {
chatListLoading = true;
2024-08-04 14:58:08 +00:00
currentChatPage.set($currentChatPage + 1);
2024-10-09 06:37:37 +00:00
let newChatList = [];
if (search) {
newChatList = await getChatListBySearchText(localStorage.token, search, $currentChatPage);
} else {
newChatList = await getChatList(localStorage.token, $currentChatPage);
}
2024-08-04 14:36:44 +00:00
// once the bottom of the list has been reached (no results) there is no need to continue querying
allChatsLoaded = newChatList.length === 0;
2024-10-15 00:31:52 +00:00
await chats.set([...($chats ? $chats : []), ...newChatList]);
2024-08-04 14:36:44 +00:00
chatListLoading = false;
};
2024-10-09 06:37:37 +00:00
let searchDebounceTimeout;
const searchDebounceHandler = async () => {
console.log('search', search);
chats.set(null);
selectedTagName = null;
if (searchDebounceTimeout) {
clearTimeout(searchDebounceTimeout);
}
if (search === '') {
await initChatList();
return;
} else {
searchDebounceTimeout = setTimeout(async () => {
currentChatPage.set(1);
await chats.set(await getChatListBySearchText(localStorage.token, search));
}, 1000);
}
};
2024-10-09 07:13:54 +00:00
const deleteChatHandler = async (id) => {
const res = await deleteChatById(localStorage.token, id).catch((error) => {
toast.error(error);
return null;
});
if (res) {
if ($chatId === id) {
await chatId.set('');
await tick();
goto('/');
}
allChatsLoaded = false;
currentChatPage.set(1);
await chats.set(await getChatList(localStorage.token, $currentChatPage));
2024-10-11 06:22:53 +00:00
await pinnedChats.set(await getPinnedChatList(localStorage.token));
2024-10-09 07:13:54 +00:00
}
};
const inputFilesHandler = async (files) => {
console.log(files);
for (const file of files) {
const reader = new FileReader();
reader.onload = async (e) => {
const content = e.target.result;
try {
const items = JSON.parse(content);
for (const item of items) {
if (item.chat) {
await createNewChat(localStorage.token, item.chat);
}
}
} catch {
toast.error($i18n.t(`Invalid file format.`));
}
initChatList();
};
reader.readAsText(file);
}
};
2024-10-11 06:43:08 +00:00
const tagEventHandler = async (type, tagName, chatId) => {
console.log(type, tagName, chatId);
if (type === 'delete') {
currentChatPage.set(1);
await chats.set(await getChatListBySearchText(localStorage.token, search));
2024-10-11 06:43:08 +00:00
}
};
2024-10-09 07:13:54 +00:00
let dragged = false;
const onDragOver = (e) => {
e.preventDefault();
// Check if a file is being dragged.
if (e.dataTransfer?.types?.includes('Files')) {
dragged = true;
} else {
dragged = false;
}
2024-10-09 07:13:54 +00:00
};
const onDragLeave = () => {
dragged = false;
};
const onDrop = async (e) => {
e.preventDefault();
console.log(e); // Log the drop event
2024-10-09 07:13:54 +00:00
// Perform file drop check and handle it accordingly
2024-10-09 07:13:54 +00:00
if (e.dataTransfer?.files) {
const inputFiles = Array.from(e.dataTransfer?.files);
2024-10-09 07:13:54 +00:00
if (inputFiles && inputFiles.length > 0) {
console.log(inputFiles); // Log the dropped files
inputFilesHandler(inputFiles); // Handle the dropped files
2024-10-09 07:13:54 +00:00
}
}
dragged = false; // Reset dragged status after drop
2024-10-09 07:13:54 +00:00
};
let touchstart;
let touchend;
function checkDirection() {
const screenWidth = window.innerWidth;
const swipeDistance = Math.abs(touchend.screenX - touchstart.screenX);
if (touchstart.clientX < 40 && swipeDistance >= screenWidth / 8) {
if (touchend.screenX < touchstart.screenX) {
showSidebar.set(false);
}
if (touchend.screenX > touchstart.screenX) {
showSidebar.set(true);
}
}
}
const onTouchStart = (e) => {
touchstart = e.changedTouches[0];
console.log(touchstart.clientX);
};
const onTouchEnd = (e) => {
touchend = e.changedTouches[0];
checkDirection();
};
const onKeyDown = (e) => {
if (e.key === 'Shift') {
shiftKey = true;
}
};
const onKeyUp = (e) => {
if (e.key === 'Shift') {
shiftKey = false;
}
};
const onFocus = () => {};
const onBlur = () => {
shiftKey = false;
selectedChatId = null;
};
2023-11-20 01:47:07 +00:00
onMount(async () => {
2024-10-15 02:33:32 +00:00
showPinnedChat = localStorage?.showPinnedChat ? localStorage.showPinnedChat === 'true' : true;
2024-05-15 18:13:14 +00:00
mobile.subscribe((e) => {
if ($showSidebar && e) {
showSidebar.set(false);
}
if (!$showSidebar && !e) {
showSidebar.set(true);
}
});
2024-10-06 00:00:56 +00:00
showSidebar.set(!$mobile ? localStorage.sidebar === 'true' : false);
showSidebar.subscribe((value) => {
localStorage.sidebar = value;
});
2024-10-11 06:22:53 +00:00
await pinnedChats.set(await getPinnedChatList(localStorage.token));
2024-10-09 06:37:37 +00:00
await initChatList();
2024-04-16 20:57:14 +00:00
2024-06-16 17:36:15 +00:00
window.addEventListener('keydown', onKeyDown);
window.addEventListener('keyup', onKeyUp);
2024-06-14 20:02:07 +00:00
window.addEventListener('touchstart', onTouchStart);
window.addEventListener('touchend', onTouchEnd);
2024-04-16 22:03:12 +00:00
2024-06-16 17:36:15 +00:00
window.addEventListener('focus', onFocus);
window.addEventListener('blur', onBlur);
2024-10-09 07:13:54 +00:00
const dropZone = document.getElementById('sidebar');
2024-06-16 17:36:15 +00:00
2024-10-09 07:13:54 +00:00
dropZone?.addEventListener('dragover', onDragOver);
dropZone?.addEventListener('drop', onDrop);
dropZone?.addEventListener('dragleave', onDragLeave);
2024-02-08 01:06:07 +00:00
});
2024-10-09 07:13:54 +00:00
onDestroy(() => {
window.removeEventListener('keydown', onKeyDown);
window.removeEventListener('keyup', onKeyUp);
2024-06-15 10:41:48 +00:00
2024-10-09 07:13:54 +00:00
window.removeEventListener('touchstart', onTouchStart);
window.removeEventListener('touchend', onTouchEnd);
2024-08-04 14:58:08 +00:00
2024-10-09 07:13:54 +00:00
window.removeEventListener('focus', onFocus);
window.removeEventListener('blur', onBlur);
2024-08-04 14:58:08 +00:00
2024-10-09 07:13:54 +00:00
const dropZone = document.getElementById('sidebar');
dropZone?.removeEventListener('dragover', onDragOver);
dropZone?.removeEventListener('drop', onDrop);
dropZone?.removeEventListener('dragleave', onDragLeave);
});
2023-11-20 01:47:07 +00:00
</script>
2024-04-20 23:47:20 +00:00
<ArchivedChatsModal
2024-05-15 08:22:15 +00:00
bind:show={$showArchivedChats}
2024-04-20 23:47:20 +00:00
on:change={async () => {
2024-10-14 22:29:43 +00:00
await pinnedChats.set(await getPinnedChatList(localStorage.token));
2024-04-20 23:47:20 +00:00
await chats.set(await getChatList(localStorage.token));
}}
/>
2024-04-20 19:40:06 +00:00
2024-06-15 10:41:48 +00:00
<DeleteConfirmDialog
bind:show={showDeleteConfirm}
title={$i18n.t('Delete chat?')}
2024-06-15 10:41:48 +00:00
on:confirm={() => {
deleteChatHandler(deleteChat.id);
}}
>
<div class=" text-sm text-gray-500 flex-1 line-clamp-3">
{$i18n.t('This will delete')} <span class=" font-semibold">{deleteChat.title}</span>.
2024-06-15 10:41:48 +00:00
</div>
</DeleteConfirmDialog>
2024-05-14 22:09:30 +00:00
<!-- svelte-ignore a11y-no-static-element-interactions -->
{#if $showSidebar}
<div
2024-06-18 22:39:50 +00:00
class=" fixed md:hidden z-40 top-0 right-0 left-0 bottom-0 bg-black/60 w-full min-h-screen h-screen flex justify-center overflow-hidden overscroll-contain"
2024-05-14 22:09:30 +00:00
on:mousedown={() => {
showSidebar.set(!$showSidebar);
}}
/>
{/if}
2023-11-20 01:47:07 +00:00
<div
bind:this={navElement}
2024-04-30 23:34:29 +00:00
id="sidebar"
class="h-screen max-h-[100dvh] min-h-screen select-none {$showSidebar
2024-05-15 18:13:14 +00:00
? 'md:relative w-[260px]'
2024-09-05 17:11:27 +00:00
: '-translate-x-[260px] w-[0px]'} bg-gray-50 text-gray-900 dark:bg-gray-950 dark:text-gray-200 text-sm transition fixed z-50 top-0 left-0
2023-11-20 01:47:07 +00:00
"
2024-04-30 23:34:29 +00:00
data-state={$showSidebar}
2023-11-20 01:47:07 +00:00
>
2024-10-09 07:13:54 +00:00
{#if dragged}
<div
class="absolute w-full h-full max-h-full backdrop-blur bg-gray-800/40 flex justify-center z-[999] touch-none pointer-events-none"
>
<div class="m-auto pt-64 flex flex-col justify-center">
<AddFilesPlaceholder
title={$i18n.t('Drop Chat Export')}
content={$i18n.t('Drop a chat export file here to import it.')}
/>
</div>
</div>
{/if}
2024-02-16 04:10:48 +00:00
<div
2024-06-18 22:39:50 +00:00
class="py-2.5 my-auto flex flex-col justify-between h-screen max-h-[100dvh] w-[260px] z-50 {$showSidebar
2024-02-16 04:10:48 +00:00
? ''
: 'invisible'}"
>
2024-05-15 06:21:22 +00:00
<div class="px-2.5 flex justify-between space-x-1 text-gray-600 dark:text-gray-400">
2024-02-28 03:56:52 +00:00
<a
2023-12-28 10:46:57 +00:00
id="sidebar-new-chat-button"
2024-09-05 17:11:27 +00:00
class="flex flex-1 justify-between rounded-xl px-2 h-full hover:bg-gray-100 dark:hover:bg-gray-900 transition"
2024-02-28 03:56:52 +00:00
href="/"
2024-05-15 18:27:52 +00:00
draggable="false"
2023-11-20 04:39:13 +00:00
on:click={async () => {
2024-03-18 17:49:39 +00:00
selectedChatId = null;
2024-02-28 03:56:52 +00:00
await goto('/');
2023-12-26 11:28:30 +00:00
const newChatButton = document.getElementById('new-chat-button');
2024-02-28 03:56:52 +00:00
setTimeout(() => {
newChatButton?.click();
2024-05-15 08:09:32 +00:00
if ($mobile) {
showSidebar.set(false);
}
2024-02-28 03:56:52 +00:00
}, 0);
2023-11-20 01:47:07 +00:00
}}
>
2024-05-15 09:45:27 +00:00
<div class="self-center mx-1.5">
<img
2024-05-17 03:49:28 +00:00
crossorigin="anonymous"
2024-05-15 09:45:27 +00:00
src="{WEBUI_BASE_URL}/static/favicon.png"
class=" size-6 -translate-x-1.5 rounded-full"
alt="logo"
/>
</div>
2024-07-08 23:55:12 +00:00
<div class=" self-center font-medium text-sm text-gray-850 dark:text-white font-primary">
2024-05-15 09:57:32 +00:00
{$i18n.t('New Chat')}
</div>
2024-05-15 09:45:27 +00:00
<div class="self-center ml-auto">
2023-11-20 01:47:07 +00:00
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
2024-05-14 22:09:30 +00:00
class="size-5"
2023-11-20 01:47:07 +00:00
>
<path
d="M5.433 13.917l1.262-3.155A4 4 0 017.58 9.42l6.92-6.918a2.121 2.121 0 013 3l-6.92 6.918c-.383.383-.84.685-1.343.886l-3.154 1.262a.5.5 0 01-.65-.65z"
/>
<path
d="M3.5 5.75c0-.69.56-1.25 1.25-1.25H10A.75.75 0 0010 3H4.75A2.75 2.75 0 002 5.75v9.5A2.75 2.75 0 004.75 18h9.5A2.75 2.75 0 0017 15.25V10a.75.75 0 00-1.5 0v5.25c0 .69-.56 1.25-1.25 1.25h-9.5c-.69 0-1.25-.56-1.25-1.25v-9.5z"
/>
</svg>
</div>
2024-02-28 03:56:52 +00:00
</a>
2024-05-15 09:45:27 +00:00
<button
2024-07-19 11:57:35 +00:00
class=" cursor-pointer px-2 py-2 flex rounded-xl hover:bg-gray-100 dark:hover:bg-gray-900 transition"
2024-05-15 09:45:27 +00:00
on:click={() => {
showSidebar.set(!$showSidebar);
}}
>
<div class=" m-auto self-center">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="2"
stroke="currentColor"
class="size-5"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25H12"
/>
</svg>
</div>
</button>
2023-11-23 22:33:08 +00:00
</div>
2023-12-27 06:02:17 +00:00
{#if $user?.role === 'admin'}
2024-05-15 07:26:54 +00:00
<div class="px-2.5 flex justify-center text-gray-800 dark:text-gray-200">
2024-02-19 18:45:12 +00:00
<a
2024-05-15 07:26:54 +00:00
class="flex-grow flex space-x-3 rounded-xl px-2.5 py-2 hover:bg-gray-100 dark:hover:bg-gray-900 transition"
2024-05-15 06:16:22 +00:00
href="/workspace"
2024-03-18 17:49:39 +00:00
on:click={() => {
selectedChatId = null;
chatId.set('');
2024-06-06 01:31:15 +00:00
if ($mobile) {
showSidebar.set(false);
}
2024-03-18 17:49:39 +00:00
}}
2024-05-15 18:27:52 +00:00
draggable="false"
2023-12-27 06:02:17 +00:00
>
<div class="self-center">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
2024-03-24 01:07:42 +00:00
stroke-width="2"
2023-12-27 06:02:17 +00:00
stroke="currentColor"
2024-05-15 07:26:54 +00:00
class="size-[1.1rem]"
2023-12-27 06:02:17 +00:00
>
<path
stroke-linecap="round"
stroke-linejoin="round"
2024-01-08 06:14:08 +00:00
d="M13.5 16.875h3.375m0 0h3.375m-3.375 0V13.5m0 3.375v3.375M6 10.5h2.25a2.25 2.25 0 0 0 2.25-2.25V6a2.25 2.25 0 0 0-2.25-2.25H6A2.25 2.25 0 0 0 3.75 6v2.25A2.25 2.25 0 0 0 6 10.5Zm0 9.75h2.25A2.25 2.25 0 0 0 10.5 18v-2.25a2.25 2.25 0 0 0-2.25-2.25H6a2.25 2.25 0 0 0-2.25 2.25V18A2.25 2.25 0 0 0 6 20.25Zm9.75-9.75H18a2.25 2.25 0 0 0 2.25-2.25V6A2.25 2.25 0 0 0 18 3.75h-2.25A2.25 2.25 0 0 0 13.5 6v2.25a2.25 2.25 0 0 0 2.25 2.25Z"
2023-12-27 06:02:17 +00:00
/>
</svg>
</div>
2023-11-23 22:33:08 +00:00
2023-12-27 06:02:17 +00:00
<div class="flex self-center">
2024-07-08 23:55:12 +00:00
<div class=" self-center font-medium text-sm font-primary">{$i18n.t('Workspace')}</div>
2024-01-08 06:14:08 +00:00
</div>
2024-02-19 18:45:12 +00:00
</a>
2024-01-08 06:14:08 +00:00
</div>
2023-12-27 06:02:17 +00:00
{/if}
2023-11-23 22:33:08 +00:00
2024-10-15 02:33:32 +00:00
<div class="relative {$temporaryChatEnabled ? 'opacity-20' : ''}">
{#if $temporaryChatEnabled}
2024-09-18 00:11:25 +00:00
<div class="absolute z-40 w-full h-full flex justify-center"></div>
2024-01-06 10:33:00 +00:00
{/if}
2023-11-23 22:33:08 +00:00
2024-10-15 00:31:52 +00:00
<SearchInput
bind:value={search}
on:input={searchDebounceHandler}
placeholder={$i18n.t('Search')}
/>
2024-10-15 02:33:32 +00:00
</div>
2023-11-20 01:47:07 +00:00
2024-10-15 02:33:32 +00:00
<div
class="relative flex flex-col flex-1 overflow-y-auto {$temporaryChatEnabled
? 'opacity-20'
: ''}"
>
{#if $temporaryChatEnabled}
<div class="absolute z-40 w-full h-full flex justify-center"></div>
{/if}
2024-01-18 10:55:25 +00:00
2024-09-22 12:49:53 +00:00
{#if !search && $pinnedChats.length > 0}
2024-10-15 02:33:32 +00:00
<div class=" pb-2 flex flex-col space-y-1">
2024-07-02 06:08:01 +00:00
<div class="">
2024-10-15 02:33:32 +00:00
<div class="px-2">
<button
2024-10-15 03:36:16 +00:00
class="w-full py-1 px-1.5 rounded-md flex items-center gap-1 text-xs text-gray-500 dark:text-gray-500 font-medium hover:bg-gray-100 dark:hover:bg-gray-900 transition"
2024-10-15 02:33:32 +00:00
on:click={() => {
showPinnedChat = !showPinnedChat;
localStorage.setItem('showPinnedChat', showPinnedChat);
}}
>
<div class="text-gray-300">
{#if showPinnedChat}
<ChevronDown className=" size-3" strokeWidth="2.5" />
{:else}
<ChevronRight className=" text-gra size-3" strokeWidth="2.5" />
{/if}
</div>
<div class=" translate-y-[0.5px]">
{$i18n.t('Pinned')}
</div>
</button>
2024-07-02 06:08:01 +00:00
</div>
2024-10-15 02:33:32 +00:00
{#if showPinnedChat}
<div class="pl-2 mt-1 flex flex-col overflow-y-auto scrollbar-hidden">
{#each $pinnedChats as chat, idx}
<ChatItem
{chat}
{shiftKey}
selected={selectedChatId === chat.id}
on:select={() => {
selectedChatId = chat.id;
}}
on:unselect={() => {
selectedChatId = null;
}}
on:delete={(e) => {
if ((e?.detail ?? '') === 'shift') {
deleteChatHandler(chat.id);
} else {
deleteChat = chat;
showDeleteConfirm = true;
}
}}
on:tag={(e) => {
const { type, name } = e.detail;
tagEventHandler(type, name, chat.id);
}}
/>
{/each}
</div>
{/if}
2024-07-02 06:08:01 +00:00
</div>
</div>
{/if}
2024-10-11 07:00:13 +00:00
<div class="pl-2 flex-1 flex flex-col space-y-1 overflow-y-auto scrollbar-hidden">
2024-10-09 06:37:37 +00:00
{#if $chats}
{#each $chats as chat, idx}
{#if idx === 0 || (idx > 0 && chat.time_range !== $chats[idx - 1].time_range)}
<div
class="w-full pl-2.5 text-xs text-gray-500 dark:text-gray-500 font-medium {idx === 0
? ''
: 'pt-5'} pb-0.5"
>
{$i18n.t(chat.time_range)}
<!-- localisation keys for time_range to be recognized from the i18next parser (so they don't get automatically removed):
{$i18n.t('Today')}
{$i18n.t('Yesterday')}
{$i18n.t('Previous 7 days')}
{$i18n.t('Previous 30 days')}
{$i18n.t('January')}
{$i18n.t('February')}
{$i18n.t('March')}
{$i18n.t('April')}
{$i18n.t('May')}
{$i18n.t('June')}
{$i18n.t('July')}
{$i18n.t('August')}
{$i18n.t('September')}
{$i18n.t('October')}
{$i18n.t('November')}
{$i18n.t('December')}
-->
2024-10-09 06:37:37 +00:00
</div>
{/if}
<ChatItem
{chat}
{shiftKey}
selected={selectedChatId === chat.id}
on:select={() => {
selectedChatId = chat.id;
}}
on:unselect={() => {
selectedChatId = null;
}}
on:delete={(e) => {
if ((e?.detail ?? '') === 'shift') {
deleteChatHandler(chat.id);
} else {
deleteChat = chat;
showDeleteConfirm = true;
}
}}
2024-10-11 06:43:08 +00:00
on:tag={(e) => {
const { type, name } = e.detail;
tagEventHandler(type, name, chat.id);
}}
2024-10-09 06:37:37 +00:00
/>
{/each}
2024-05-04 08:23:02 +00:00
2024-10-09 06:37:37 +00:00
{#if $scrollPaginationEnabled && !allChatsLoaded}
<Loader
on:visible={(e) => {
if (!chatListLoading) {
loadMoreChats();
}
}}
>
<div class="w-full flex justify-center py-1 text-xs animate-pulse items-center gap-2">
<Spinner className=" size-4" />
<div class=" ">Loading...</div>
</div>
</Loader>
{/if}
{:else}
<div class="w-full flex justify-center py-1 text-xs animate-pulse items-center gap-2">
<Spinner className=" size-4" />
<div class=" ">Loading...</div>
</div>
2024-08-04 00:13:36 +00:00
{/if}
2024-01-06 10:33:00 +00:00
</div>
2023-11-20 01:47:07 +00:00
</div>
<div class="px-2.5 pb-safe-bottom">
2024-05-15 18:27:52 +00:00
<!-- <hr class=" border-gray-900 mb-1 w-full" /> -->
2024-07-08 23:55:12 +00:00
<div class="flex flex-col font-primary">
2024-05-15 18:27:52 +00:00
{#if $user !== undefined}
<UserMenu
role={$user.role}
on:show={(e) => {
if (e.detail === 'archived-chat') {
showArchivedChats.set(true);
}
}}
>
<button
class=" flex rounded-xl py-3 px-3.5 w-full hover:bg-gray-100 dark:hover:bg-gray-900 transition"
on:click={() => {
showDropdown = !showDropdown;
2024-05-09 07:34:57 +00:00
}}
2023-11-20 01:47:07 +00:00
>
2024-05-15 18:27:52 +00:00
<div class=" self-center mr-3">
<img
src={$user.profile_image_url}
class=" max-w-[30px] object-cover rounded-full"
alt="User profile"
/>
</div>
2024-07-08 23:55:12 +00:00
<div class=" self-center font-medium">{$user.name}</div>
2024-05-15 18:27:52 +00:00
</button>
</UserMenu>
{/if}
2023-11-20 01:47:07 +00:00
</div>
2024-05-15 18:27:52 +00:00
</div>
2023-11-20 01:47:07 +00:00
</div>
</div>
2024-04-30 23:55:32 +00:00
<style>
2024-05-15 06:16:22 +00:00
.scrollbar-hidden:active::-webkit-scrollbar-thumb,
.scrollbar-hidden:focus::-webkit-scrollbar-thumb,
.scrollbar-hidden:hover::-webkit-scrollbar-thumb {
2024-05-02 02:37:12 +00:00
visibility: visible;
2024-04-30 23:55:32 +00:00
}
2024-05-15 06:16:22 +00:00
.scrollbar-hidden::-webkit-scrollbar-thumb {
2024-05-02 02:37:12 +00:00
visibility: hidden;
2024-04-30 23:55:32 +00:00
}
</style>