refactor: split MainContent into per-concern hooks

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

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
55/100
Issue 类型
重构
描述清晰度
描述清楚
活跃度
冷清
技术栈
react, typescript

调研方向

Start with src/components/layout/MainContent.tsx and choose one listed extraction: useEditorTabs(), useQueryExecution(), usePsqlSession() (around lines 580–700), or the toolbar component. Read the relevant state and call sites, then add a Vitest test for one path and run the TypeScript checks, tests, and build. Done means the extracted module owns its concern, the parent passes data through props, and app behavior remains unchanged.

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

描述

good first issue help wanted refactor

src/components/layout/MainContent.tsx is 2,474 lines — by far the largest component in the app. It manages editor tabs, query execution, the integrated psql shell, results state, tool buttons, AI assist, compare/clone/definition modals, and history navigation. New contributors hit this file first and bounce.

What to extract

Any one of these is a complete, mergeable PR:

  1. useEditorTabs() — tab state, switching, persistence, the + button.
  2. useQueryExecution() — executeQuery, the active execution state, cancellation, history-writing.
  3. usePsqlSession() — CLI path detection, \c handling, cliExecStmt, the psql output buffer. Roughly lines 580–700.
  4. <Toolbar> — the top button strip (Save, Format, Run, Tools, AI, Compare, Clone, etc.) as a sub-component.

Suggested approach

  • Hooks live in src/hooks/editor/ (new directory).
  • Sub-components live next to MainContent.tsx (src/components/layout/).
  • Aim to remove ~300–500 lines from MainContent.tsx per PR. Stop there; don't try to refactor everything in one shot.

Done criteria

  • Behavior unchanged when running the app manually.
  • The extracted hook/component is the only thing that owns its concern — the parent passes data down via props, not via in-line state.
  • TypeScript clean, tests clean, build clean.
  • Add a Vitest test exercising at least one path of the new module.

Out of scope

  • Replacing Zustand with Redux/TanStack Query.
  • Reworking the panel-resize layout.
  • Touching the results grid logic (covered in a future ticket).

Audit reference

K2 in the pre-launch audit.

主要语言
TypeScript
星标
6
派生
1
平均合并
17 分钟
30 天内合并 PR
2

环境准备

从这里开始

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

openidle-dev/queryden 的其他 Issue

查看 openidle-dev/queryden 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

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