This commit is contained in:
Timothy Jaeryang Baek committed 2026-11-26 01:31:48 +04:00
1 parent 301ae2cf7d
commit 9c9a3ca0d6
8 files changed
+72 -46

No files matched your search

+2
View File
@@ -56,6 +56,8 @@ class FolderNameIdResponse(BaseModel):
name: str
meta: Optional[FolderMetadataResponse] = None
parent_id: Optional[str] = None
machine_id: Optional[str] = None
directory: Optional[str] = None
is_expanded: bool = False
unread_count: int = 0
created_at: int
+6 -1
View File
@@ -147,7 +147,12 @@ async def get_folders(
unread_counts = await get_folder_unread_counts(user.id, db=db)
return [
FolderNameIdResponse(**folder.model_dump(), unread_count=unread_counts.get(folder.id, 0))
FolderNameIdResponse(
**folder.model_dump(),
machine_id=machine_id_of(folder.data or {}),
directory=(folder.data or {}).get('working_directory'),
unread_count=unread_counts.get(folder.id, 0),
)
for folder in folder_list
]
+22 -33
View File
@@ -23,7 +23,6 @@
import MessageInput from './MessageInput.svelte';
import Navbar from './Navbar.svelte';
import { canUseEncryption, connected, enter, request } from '$lib/encryption/client';
import Drawer from '../common/Drawer.svelte';
import ResizableSidePanel from '../common/ResizableSidePanel.svelte';
import EllipsisVertical from '../icons/EllipsisVertical.svelte';
import Thread from './Thread.svelte';
@@ -399,23 +398,21 @@
updateLastReadAt(id);
};
let mediaQuery;
let largeScreen = false;
const MIN_MESSAGES_WIDTH = 360;
const MIN_THREAD_WIDTH = 320;
let contentWidth = 0;
let threadPanelWidth = 420;
const handleMediaQuery = (e) => {
largeScreen = e.matches;
};
// The thread takes the whole width when it does not fit beside the messages.
$: threadFills = contentWidth < MIN_MESSAGES_WIDTH + MIN_THREAD_WIDTH;
$: if (contentWidth && !threadFills) {
threadPanelWidth = Math.min(threadPanelWidth, contentWidth - MIN_MESSAGES_WIDTH);
}
onMount(() => {
mounted = true;
$socket?.on('events:channel', channelEventHandler);
mediaQuery = window.matchMedia('(min-width: 768px)');
mediaQuery.addEventListener('change', handleMediaQuery);
handleMediaQuery(mediaQuery);
});
onDestroy(() => {
@@ -424,7 +421,6 @@
if ($active) updateLastReadAt(id);
if ($_channelId === id) _channelId.set(null);
$socket?.off('events:channel', channelEventHandler);
mediaQuery?.removeEventListener('change', handleMediaQuery);
});
import PageTitle from '$lib/components/common/PageTitle.svelte';
</script>
@@ -499,8 +495,12 @@
</svelte:fragment>
</Navbar>
<div class="w-full flex-1 min-h-0 flex">
<div class="h-full flex flex-col min-w-0 flex-1 relative">
<div class="relative w-full flex-1 min-h-0 flex" bind:clientWidth={contentWidth}>
<!-- Invisible rather than hidden, to keep the scroll position. -->
<div
class="h-full flex flex-col min-w-0 flex-1 relative"
class:invisible={threadId !== null && threadFills}
>
{#if channel && messages !== null}
<div class="flex-1 overflow-y-auto">
<div
@@ -577,32 +577,21 @@
{/if}
</div>
{#if !largeScreen}
{#if threadId !== null}
<Drawer show={threadId !== null} ariaLabel={$i18n.t('Thread')} onClose={closeThread}>
<div class=" {threadId !== null ? ' h-screen w-full' : 'px-6 py-4'} h-full">
<Thread
{threadId}
{channel}
bind:chatInputElement={threadChatInputElement}
onPin={pinHandler}
onClose={closeThread}
/>
</div>
</Drawer>
{/if}
{:else if threadId !== null}
{#if threadId !== null && contentWidth}
<ResizableSidePanel
open={true}
bind:width={threadPanelWidth}
minWidth={320}
minWidth={MIN_THREAD_WIDTH}
maxWidth={640}
minSiblingWidth={360}
minSiblingWidth={MIN_MESSAGES_WIDTH}
subtleDivider
className="h-full px-2 pt-1 pb-2"
fill={threadFills}
className={threadFills ? 'absolute inset-0 z-20' : 'h-full px-2 pt-1 pb-2'}
>
<div
class="h-full w-full rounded-3xl border border-base-200/60 dark:border-base-800/50 shadow-[0_6px_24px_-4px_rgba(0,0,0,0.1)]"
class="h-full w-full {threadFills
? ''
: 'rounded-3xl border border-base-200/60 dark:border-base-800/50 shadow-[0_6px_24px_-4px_rgba(0,0,0,0.1)]'}"
>
<Thread
{threadId}
@@ -7,7 +7,7 @@
import { toast } from 'svelte-sonner';
import { selectedFolder, user } from '$lib/stores';
import { folders, selectedFolder, user } from '$lib/stores';
import {
loadFolderDetails,
updateFolderDetails,
@@ -23,6 +23,7 @@
} from '$lib/apis/folders';
import { getChatsByFolderId } from '$lib/apis/chats';
import { refreshSidebar } from '$lib/stores/chatList';
import { hasDirectory } from '$lib/utils/folders';
import FolderModal from '$lib/components/layout/Sidebar/Folders/FolderModal.svelte';
import FolderShareModal from '$lib/components/layout/Sidebar/Folders/FolderShareModal.svelte';
@@ -174,6 +175,8 @@
showFolderModal = true;
}}
onDelete={() => {
// Closing a directory is not a reason to lose its chats.
deleteFolderContents = !hasDirectory($folders, folder!.id);
showDeleteConfirm = true;
}}
onExport={() => {
@@ -12,6 +12,8 @@
export let closeOnDragBelowMinWidth = false;
export let storageKey = '';
export let subtleDivider = false;
// Lets className size the panel instead, with no resizing.
export let fill = false;
export let className = '';
export let resizerId = 'controls-resizer';
export let portalTarget: string | null = null;
@@ -120,7 +122,7 @@
}
});
$: if (open && panelElement) {
$: if (open && !fill && panelElement) {
const clampedWidth = clamp(width);
if (clampedWidth !== width) {
width = clampedWidth;
@@ -141,14 +143,14 @@
resizeHandler(e.clientX);
}}
on:resize={() => {
if (open) width = clamp(width);
if (open && !fill) width = clamp(width);
}}
on:pointerup={resizeEndHandler}
on:pointercancel={resizeEndHandler}
/>
{#if open}
{#if side === 'right'}
{#if side === 'right' && !fill}
<!-- svelte-ignore a11y_no_noninteractive_element_interactions, a11y_no_noninteractive_tabindex -->
<div
class="relative flex items-center justify-center group border-l border-base-50 dark:border-base-850/30 hover:border-base-200 dark:hover:border-base-800 transition z-20 bg-transparent p-0 appearance-none {subtleDivider
@@ -185,12 +187,12 @@
use:portal
bind:this={panelElement}
class={className}
style="width: {width}px; flex: 0 0 {width}px;"
style={fill ? undefined : `width: ${width}px; flex: 0 0 ${width}px;`}
>
<slot />
</div>
{#if side === 'left'}
{#if side === 'left' && !fill}
<!-- svelte-ignore a11y_no_noninteractive_element_interactions, a11y_no_noninteractive_tabindex -->
<div
class="relative flex items-center justify-center group border-r border-base-50 dark:border-base-850/30 hover:border-base-200 dark:hover:border-base-800 transition z-20 bg-transparent p-0 appearance-none {subtleDivider
+20 -5
View File
@@ -529,13 +529,28 @@
return res;
};
// A folder on a machine's directory, named after it.
// Opens the folder on a machine's directory, or makes one named after it.
const openDirectory = async (machineId: string, directory: string) => {
const folder = await createFolder({
name: directory.split('/').filter(Boolean).at(-1) ?? directory,
data: { machine_id: machineId, working_directory: directory },
parent_id: null
const owned = await getFolders(localStorage.token).catch((error) => {
toast.error(`${error}`);
return null;
});
if (!owned) return false;
// Browsing ends a path with a slash; cloning and typing may not.
const trim = (path: string) => path.replace(/\/+$/, '');
const folder =
owned.find(
(folder: any) =>
folder.machine_id === machineId &&
folder.directory &&
trim(folder.directory) === trim(directory)
) ??
(await createFolder({
name: directory.split('/').filter(Boolean).at(-1) ?? directory,
data: { machine_id: machineId, working_directory: directory },
parent_id: null
}));
if (!folder) return false;
await goto(`/folders/${folder.id}`);
closeMobileSidebar();
@@ -46,7 +46,7 @@
} from '$lib/stores/folderStates';
import { pendingChatRequest } from '$lib/stores/chatCache';
import { refreshFolderChatLists } from '$lib/stores/chatList';
import { sortFolders } from '$lib/utils/folders';
import { hasDirectory, sortFolders } from '$lib/utils/folders';
import { updateNoteFolderIdById } from '$lib/apis/notes';
import { createNoteHandler } from '$lib/components/notes/utils';
import dayjs from '$lib/dayjs';
@@ -965,6 +965,8 @@
showFolderModal = true;
}}
onDelete={() => {
// Closing a directory is not a reason to lose its chats.
deleteFolderContents = !hasDirectory(Object.values(folders), folderId);
showDeleteConfirm = true;
}}
onExport={() => {
+8
View File
@@ -140,5 +140,13 @@ export const sortFolders = <T extends { id: string; name?: string }>(
);
};
/** Whether a folder, or one inside it, is on a directory. */
export const hasDirectory = (folders: any[], id: string): boolean =>
folders.some(
(folder) =>
(folder.id === id && !!folder.directory) ||
(folder.parent_id === id && hasDirectory(folders, folder.id))
);
export const isChatUnread = (chat: WorkspaceChat) =>
(chat.last_read_at ?? 0) === 0 || chat.updated_at > (chat.last_read_at ?? 0);