cc-haha/desktop/src/api/desktopUiPreferences.ts
程序员阿江(Relakkes) 4e969475f2 Improve session project sidebar controls
The session sidebar already uses project grouping, so the change adds header-level project actions instead of replacing project row controls. Sorting and organization choices are persisted through the existing desktop UI preferences file and mirrored into local cache for startup continuity.

Constraint: Keep the existing project tree, drag ordering, pinning, hiding, and Finder project-row actions intact.

Rejected: Replacing project row actions with the header menu | row-level Finder and per-project session actions are still useful and already covered by tests.

Confidence: high

Scope-risk: moderate

Directive: Do not store sidebar organization in global Claude settings; keep it under cc-haha desktop-ui preferences.

Tested: cd desktop && bun run test -- src/components/layout/Sidebar.test.tsx

Tested: bun test src/server/__tests__/desktop-ui-preferences.test.ts

Tested: cd desktop && bun run lint

Tested: cd desktop && bun run build
2026-05-15 16:49:18 +08:00

33 lines
817 B
TypeScript

import { api } from './client'
export type SidebarProjectPreferences = {
projectOrder: string[]
pinnedProjects: string[]
hiddenProjects: string[]
projectOrganization: 'project' | 'recentProject' | 'time'
projectSortBy: 'createdAt' | 'updatedAt'
}
export type DesktopUiPreferences = {
schemaVersion: number
sidebar: SidebarProjectPreferences
}
export type DesktopUiPreferencesResponse = {
preferences: DesktopUiPreferences
exists: boolean
}
export const desktopUiPreferencesApi = {
getPreferences() {
return api.get<DesktopUiPreferencesResponse>('/api/desktop-ui/preferences')
},
updateSidebarPreferences(sidebar: SidebarProjectPreferences) {
return api.put<{ ok: true; preferences: DesktopUiPreferences }>(
'/api/desktop-ui/preferences/sidebar',
sidebar,
)
},
}