Web UI: decompose App.tsx (1803 lines) into focused hooks + components

未关闭
#148 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
重构
描述清晰度
描述清楚
活跃度
活跃
技术栈
react, typescript

调研方向

Start with App.tsx and the presentation-layer rules in AGENTS.md; the issue gives line ranges for each proposed hook, component, and helper. Follow the suggested sequence, beginning with useScanController and the five duplicated scan flows. Finish when the listed responsibilities are extracted into focused, independently testable pieces and the test suite remains green.

由索引模型根据 Issue 内容生成。

描述

code-quality frontend tech-debt

Problem

App.tsx is a 1803-line monolith mixing scan orchestration, theme, barcode mode, drag-drop, global shortcuts, LAN toggle, telemetry and more. AGENTS.md's presentation-layer rules (delegate business logic to core, UI only) are hard to enforce at this size, and several bugs found in this audit trace directly to the tangle (stale closures in the scan flow, shortcut-guard gaps, duplicated scan-merge logic).

Concrete decomposition plan (each hook independently testable)

  1. useScanController — files/totalCount/hasScanned/scanning/loadingMore, generation + abort refs (App.tsx:85-89, 175-196), loadScanResults, runScan, handleLoadMore, and a single scanWith(params) replacing the five duplicated try { await runScan(...) } catch { showToast } finally { finishScan } blocks (App.tsx:666-681, 723-739, 742-758, 832-843, 845-856).
  2. useToast — lines 98, 147-168.
  3. useExternalEvents — the notification poll + externalConfigApplyRef (lines 445-476).
  4. useBarcodeMode — state, buffer ref, capture-phase keydown effect, applyBarcodeValues (lines 132-133, 1085-1191).
  5. useAutoRescanTimer — autoRescanInterval + interval effect (lines 144-145, 1196-1217).
  6. useGlobalShortcuts(anyModalOpen, …) — the 200-line keydown effect (lines 1223-1444).
  7. useTheme — theme state + persistence effect (fixes #129 at the same time).
  8. useDragDropConfig — drag tracker refs + window listeners + handleDroppedConfig (lines 418-511).

Components: extract LanConfirmDialog (lines 1722-1785 — the waitForLanState observe-and-verify flow is ~60 lines of inline JSX + logic).

Business logic that should leave the UI per AGENTS.md:

  • handleCopyUri's path→URI construction (line 895) → pure pathToFileUri() in utils/ (currently also wrong for UNC paths).
  • The barcode shouldScan decision (lines 1111-1117) → utils/barcodeScanner.ts.
  • The three duplicated "merge extension/filter from directoryConfig" blocks (lines 531-536, 644-649, 387-394) → one pure helper.
  • handleCameraDetected's inline duplicate of runScan (lines 1043-1082 vs 274-285) → reuse the scan controller.

Suggested sequencing

Do it in slices that keep the suite green (config-editor tests already cover the editor slice): scan controller first (kills the five duplicated blocks), then shortcuts/theme/barcode, then the component extractions.

主要语言
Python
星标
1
派生
1
平均合并
4 小时 46 分钟
30 天内合并 PR
55

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

falbany/ProFiles 的其他 Issue

查看 falbany/ProFiles 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。