From e0badc879c79459582f78d099f9b922063f67abc Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Sat, 6 Jun 2026 00:39:19 -0400 Subject: [PATCH] refac --- .../src/lib/components/Sidebar.svelte | 25 +++++++++++ .../src/lib/components/chat/PlusMenu.svelte | 10 +++-- cptr/frontend/src/lib/stores.ts | 41 +++++++++++++++---- 3 files changed, 64 insertions(+), 12 deletions(-) diff --git a/cptr/frontend/src/lib/components/Sidebar.svelte b/cptr/frontend/src/lib/components/Sidebar.svelte index f2d34d6..84556ca 100644 --- a/cptr/frontend/src/lib/components/Sidebar.svelte +++ b/cptr/frontend/src/lib/components/Sidebar.svelte @@ -5,6 +5,7 @@ workspaceList, currentWorkspace, removeWorkspace, + reorderWorkspaces, sidebarOpen, } from '$lib/stores'; import Sortable from 'sortablejs'; @@ -30,10 +31,15 @@ let appVersion = $state(''); let menuButtonEl: HTMLButtonElement | undefined = $state(); let wsListEl: HTMLDivElement | undefined = $state(); + let sortable: Sortable | null = null; // Current workspace path from URL const currentPath = $derived($page.url.searchParams.get('workspace')); + function isTouchDevice(): boolean { + return typeof window !== 'undefined' && ('ontouchstart' in window || navigator.maxTouchPoints > 0); + } + function handleWorkspaceClick(e: MouseEvent, path: string) { // Let Cmd/Ctrl+click open in new tab naturally (it's an ) if (e.metaKey || e.ctrlKey) return; @@ -82,6 +88,25 @@ getWelcome() .then(d => { appVersion = d.version || ''; }) .catch(() => {}); + + // Enable drag-reorder on non-touch devices + if (wsListEl && !isTouchDevice()) { + sortable = Sortable.create(wsListEl, { + animation: 150, + ghostClass: 'opacity-30', + dragClass: 'cursor-grabbing', + direction: 'vertical', + onEnd: (evt) => { + if (evt.oldIndex != null && evt.newIndex != null && evt.oldIndex !== evt.newIndex) { + reorderWorkspaces(evt.oldIndex, evt.newIndex); + } + }, + }); + } + }); + + onDestroy(() => { + sortable?.destroy(); }); diff --git a/cptr/frontend/src/lib/components/chat/PlusMenu.svelte b/cptr/frontend/src/lib/components/chat/PlusMenu.svelte index 22a54fe..3319d6d 100644 --- a/cptr/frontend/src/lib/components/chat/PlusMenu.svelte +++ b/cptr/frontend/src/lib/components/chat/PlusMenu.svelte @@ -1,6 +1,7 @@