refactor(frontend): extract FilesTab from App.svelte

• Create lib/components/files/FilesTab.svelte (616 lines)
  - Self-contained file browser with internal state
  - Folder navigation, breadcrumbs, file list
  - File preview with CheckFileAction for .md → note editor flow
  - Import dialog (copy/link)
  - Drag-and-drop, selection, keyboard shortcuts
  - Cut/copy/paste, rename, delete, duplicate
  - Public API: resetToNode(), filesHandleKeydown()
• Remove ~594 lines from App.svelte (4794 → 4200)
  - Removed: loadingFiles, currentFolderId, folderStack, fileItems,
    previewItem/Content/Loading/Error, clipboard, selectedIds, dragIds,
    importing, importSummary, showImportDialog, pendingImportPath/Parent,
    treeItems, expanded, childrenMap, dropRootValid, inboxDropValid,
    captureDropActive/Label/DragDepth/lastCaptureDragOverAt/captureDragResetTimer
  - Removed: loadTree, loadFolder, navigateToFolder, navigateBack,
    navigateToBreadcrumb, openPreview, closePreview, createFile,
    duplicateItem, renameItem, cutItem, copyItem, pasteItem,
    toggleSelection, selectOne, selectAll, rangeSelect, clearSelection,
    getTargetIds, deleteSelected, cutSelected, copySelected,
    onDragStart, onDragOver, onDrop, openSelected, openSelectedExternal,
    addFile, addFolder, startImport, confirmImport, cancelImport, deleteFile
  - Keyboard handler delegates to filesTabRef.filesHandleKeydown()
  - selectNode() calls filesTabRef.resetToNode()
• Update docs/frontend-architecture.md — Files Flow section
• Update docs/frontend-change-map.md — Phase 2 & 5 marked complete
• Build passes: npm run build ✓, go test ✓, build.sh gui ✓
This commit is contained in:
2026-06-15 20:31:23 +08:00
parent 490a3dd624
commit 9878ab4fb3
8 changed files with 768 additions and 649 deletions
+18
View File
@@ -136,8 +136,26 @@ The `wailsCall()` helper in `lib/services/wails.js` provides error handling.
Currently all state lives in App.svelte as local variables.
Target: extract into `lib/state/navigation.js` and `lib/state/uiState.js`.
### Files Flow
- **Component:** `lib/components/files/FilesTab.svelte` — self-contained file browser
- **API services:** `lib/services/files.js`, `lib/services/nodes.js`
- **Events emitted:**
- `on:openNote` — when a .md file linked to a note is opened
- `on:refreshParent` — after file operations that modify the tree
- `on:error` — on operation failures
- `on:rename` — requests parent to show rename modal
- `on:confirm` — requests parent to show confirm dialog
- **Public methods:**
- `resetToNode(nodeId)` — reset state when selected node changes
- `filesHandleKeydown(e)` — keyboard handler for files tab
- **.md → note editor flow:** Handled inside FilesTab via `CheckFileAction` Wails call. If action is 'note', emits `openNote`. If 'external', opens in system viewer. Otherwise shows built-in preview.
- **File preview:** `FilePreviewModal.svelte` (already existed), invoked by FilesTab
- **Import dialog:** Inline in FilesTab template (moved from App.svelte)
## Build & Verification
- `npm run build` in `frontend/` directory
- `go test ./...` from project root
- `bash scripts/build.sh gui` for full GUI binary
- Manual smoke testing via Wails dev server
+26 -14
View File
@@ -15,17 +15,29 @@ into a modular frontend architecture. Each step preserves behaviour exactly.
Extract all Wails calls into service modules.
- [ ] Create `lib/services/wails.js` — base `wailsCall` helper
- [ ] Create `lib/services/notes.js``listNotes`, `createNote`, `readNote`, `saveNote`, `renameNote`, `deleteNote`
- [ ] Create `lib/services/files.js``loadFolder`, `addFile`, `deleteFile`, etc.
- [ ] Create `lib/services/search.js``searchNodes`
- [ ] Create `lib/services/inbox.js``listInbox`, `captureClipboard`, etc.
- [ ] Create `lib/services/trash.js``loadTrash`, `restore`, `purge`
- [ ] Create `lib/services/sync.js``loadSyncStatus`, `runSync`
- [ ] Create `lib/services/journal.js``loadJournal`, `worklog CRUD`
- [ ] Create `lib/services/actions.js``listActions`, `createAction`, `deleteAction`
- [ ] Create `lib/services/links.js``listLinks`, `updateLink`, `deleteLink`
- [ ] Create `lib/services/activity.js``loadActivityFeed`, `loadCaseActivity`
- [x] Create `lib/services/wails.js` — base `wailsCall` helper
- [x] Create `lib/services/notes.js``listNotes`, `createNote`, `readNote`, `saveNote`, `renameNote`, `deleteNote`
- [x] Create `lib/services/files.js``loadFolder`, `addFile`, `deleteFile`, etc.
- [x] Create `lib/services/search.js``searchNodes`, `getNodeDetail`, `searchWorkspace`
- [x] Create `lib/services/inbox.js`inbox capture and management
- [x] Create `lib/services/trash.js`trash operations
- [x] Create `lib/services/sync.js`sync status and trigger
- [x] Create `lib/services/journal.js`worklog CRUD and reports
- [x] Create `lib/services/actions.js`actions CRUD
- [x] Create `lib/services/links.js`links CRUD
- [x] Create `lib/services/activity.js`activity feed
- [x] Create `lib/services/nodes.js` — tree, node CRUD, system views
- [x] Create `lib/services/suggestions.js` — worklog suggestions
- [x] Create `lib/services/today.js` — today dashboard
- [x] Create `lib/services/browserEvents.js` — browser extension events
- [x] Create `lib/services/search.js``searchNodes`
- [x] Create `lib/services/inbox.js``listInbox`, `captureClipboard`, etc.
- [x] Create `lib/services/trash.js``loadTrash`, `restore`, `purge`
- [x] Create `lib/services/sync.js``loadSyncStatus`, `runSync`
- [x] Create `lib/services/journal.js``loadJournal`, `worklog CRUD`
- [x] Create `lib/services/actions.js``listActions`, `createAction`, `deleteAction`
- [x] Create `lib/services/links.js``listLinks`, `updateLink`, `deleteLink`
- [x] Create `lib/services/activity.js``loadActivityFeed`, `loadCaseActivity`
## Phase 3: State Extraction
@@ -40,9 +52,9 @@ Extract all Wails calls into service modules.
## Phase 5: Component Extraction — Tab Content
- [ ] Extract `OverviewTab.svelte`
- [ ] Extract `NotesTab.svelte`
- [ ] Extract `FilesTab.svelte`
- [x] Extract `OverviewTab.svelte`
- [x] Extract `NotesTab.svelte`
- [x] Extract `FilesTab.svelte`
- [ ] Extract `LinksTab.svelte`
- [ ] Extract `ActionsTab.svelte`
- [ ] Extract `WorklogTab.svelte`