diff --git a/frontend/src/components/ListSpaceSidebar.vue b/frontend/src/components/ListSpaceSidebar.vue index 53abc07c..964d13ee 100644 --- a/frontend/src/components/ListSpaceSidebar.vue +++ b/frontend/src/components/ListSpaceSidebar.vue @@ -1,148 +1,156 @@ @@ -152,6 +160,10 @@ import { Icon as TIcon } from 'tdesign-vue-next' import SpaceAvatar from './SpaceAvatar.vue' import { useOrganizationStore } from '@/stores/organization' +const COLLAPSED_WIDTH = 56 +const EXPANDED_WIDTH = 208 +const SNAP_THRESHOLD = 120 + const props = withDefaults( defineProps<{ mode?: 'resource' | 'organization' @@ -163,45 +175,59 @@ const props = withDefaults( countByOrg?: Record countCreated?: number countJoined?: number + hideAll?: boolean + hideShared?: boolean }>(), - { mode: 'resource', collapsedKey: 'sidebar-collapsed-list', countAll: undefined, countMine: undefined, countShared: undefined, countByOrg: () => ({}), countCreated: undefined, countJoined: undefined } + { mode: 'resource', collapsedKey: 'sidebar-collapsed-list', countAll: undefined, countMine: undefined, countShared: undefined, countByOrg: () => ({}), countCreated: undefined, countJoined: undefined, hideAll: false, hideShared: false } ) -const pinStorageKey = props.collapsedKey + '-pinned' -const pinned = ref(localStorage.getItem(pinStorageKey) === 'true') -const expanded = ref(pinned.value) -let enterTimer: ReturnType | null = null -let leaveTimer: ReturnType | null = null +const storageKey = props.collapsedKey + '-expanded' +const sidebarRef = ref(null) +const isExpanded = ref(localStorage.getItem(storageKey) === 'true') +const isDragging = ref(false) +const dragWidth = ref(isExpanded.value ? EXPANDED_WIDTH : COLLAPSED_WIDTH) -function togglePin() { - pinned.value = !pinned.value - localStorage.setItem(pinStorageKey, String(pinned.value)) - if (pinned.value) { - expanded.value = true - } +let startX = 0 +let startWidth = 0 + +function onDragStart(e: MouseEvent) { + isDragging.value = true + startX = e.clientX + startWidth = isExpanded.value ? EXPANDED_WIDTH : COLLAPSED_WIDTH + dragWidth.value = startWidth + document.addEventListener('mousemove', onDragMove) + document.addEventListener('mouseup', onDragEnd) + document.body.style.cursor = 'col-resize' + document.body.style.userSelect = 'none' } -function onMouseEnter() { - if (pinned.value) return - if (leaveTimer) { clearTimeout(leaveTimer); leaveTimer = null } - enterTimer = setTimeout(() => { expanded.value = true }, 180) +function onDragMove(e: MouseEvent) { + const delta = e.clientX - startX + const newWidth = Math.max(COLLAPSED_WIDTH, Math.min(EXPANDED_WIDTH + 20, startWidth + delta)) + dragWidth.value = newWidth } -function onMouseLeave() { - if (pinned.value) return - if (enterTimer) { clearTimeout(enterTimer); enterTimer = null } - leaveTimer = setTimeout(() => { expanded.value = false }, 250) -} +function onDragEnd() { + document.removeEventListener('mousemove', onDragMove) + document.removeEventListener('mouseup', onDragEnd) + document.body.style.cursor = '' + document.body.style.userSelect = '' -onBeforeUnmount(() => { - if (enterTimer) clearTimeout(enterTimer) - if (leaveTimer) clearTimeout(leaveTimer) -}) + const shouldExpand = dragWidth.value >= SNAP_THRESHOLD + isExpanded.value = shouldExpand + localStorage.setItem(storageKey, String(shouldExpand)) + isDragging.value = false + dragWidth.value = shouldExpand ? EXPANDED_WIDTH : COLLAPSED_WIDTH +} function tooltipText(name: string, count?: number): string { return count !== undefined ? `${name} (${count})` : name } +function truncateLabel(text: string, max = 4): string { + return text.length > max ? text.slice(0, max) : text +} + const emit = defineEmits<{ 'update:modelValue': [value: string] }>() @@ -231,11 +257,16 @@ function getOrgCount(orgId: string): number | undefined { onMounted(() => { orgStore.fetchOrganizations() }) + +onBeforeUnmount(() => { + document.removeEventListener('mousemove', onDragMove) + document.removeEventListener('mouseup', onDragEnd) +})