1313 * @ai -context: 树序范围:全局可见序(树=未分组+各组顺次、折叠组行不参与)为
1414 * 区间/划选唯一基准;跨组语义=归组(目标手排时按落点插入)。
1515 */
16- import { useCallback , useEffect , useMemo , useState } from "react" ;
16+ import { useCallback , useMemo } from "react" ;
1717import type { Note , NoteGroup } from "../types" ;
1818import { paletteHex } from "../utils/colorPalette" ;
1919import type { ThemeMode } from "../utils/colorPalette" ;
2020// 批 0-C2:展示节/可见序纯函数层(含 scope 键与裸折叠键派生——纯逻辑与副作用分离)
21- import { buildSections , buildVisibleOrder , isTreeMode , manualBaseIds , scopeKey } from "../utils/noteSectionModel" ;
21+ import { manualBaseIds , scopeKey } from "../utils/noteSectionModel" ;
2222// 批 0-C2:序行 store(笔记手排序行 + 组手排序行)——兑现既有登记拆分计划
2323import { useNoteOrders } from "../hooks/useNoteOrders" ;
24+ // 批 0-C2:折叠记忆(裸键)+ 展树数据接线(treeMode/sections/visibleOrder)
25+ import { useNoteSections } from "../hooks/useNoteSections" ;
2426// 批 0-C2:拖拽/移动三入口接线(共享一把行落点并发锁——硬性同文件约束)
2527import { useNoteMoves } from "../hooks/useNoteMoves" ;
2628// 批 0-C2:多选三通道 + 菜单三态 + 唯一 Esc handler(可见序镜像同文件)
@@ -73,11 +75,6 @@ interface Props {
7375 refreshToken ?: number ;
7476}
7577
76- /** 读组折叠记忆(localStorage 损坏/无 → 默认展开) */
77- function readGroupFold ( key : string ) : boolean {
78- try { return window . localStorage . getItem ( `notes:group-fold:${ key } ` ) === "1" ; } catch { return false ; }
79- }
80-
8178export default function NoteListView ( {
8279 width = 320 , notes, groups = [ ] , groupFilter = null , onGroupFilterChange,
8380 keyword, tagFilter, sortMode, allTags, selectedId, status,
@@ -91,48 +88,15 @@ export default function NoteListView({
9188 [ ] ,
9289 ) ;
9390
94- // 组折叠态
95- const [ groupFolds , setGroupFolds ] = useState < Record < string , boolean > > ( { } ) ;
96-
9791 // 序行 store(笔记手排序行 + 组手排序行)——装载/保存路径下沉 hooks/useNoteOrders
98- const { manualOrders, groupOrderRows, saveOrder, resetOrder } = useNoteOrders ( refreshToken ) ;
99-
100- // 手动序装载(REQ-287:notes 行)+ REQ-315:组序行(树组头排序)——见 hooks/useNoteOrders
10192 // (依赖 refreshToken 的理由随实现搬至该 hook 头注释:审查 P2-10 的令牌重拉)
93+ const { manualOrders, groupOrderRows, saveOrder, resetOrder } = useNoteOrders ( refreshToken ) ;
10294
103- // ── 分组树数据(同 v0.15 结构)——可见序统一从本结构生成 ──
104- // Why 不再有分桶 memo:旧 `grouped` 是死载荷——仅被当作 treeMode 的第二真值,
105- // 其 ungrouped/byGroup 从未被读取(真分桶一直在 sections 内重算);批 0-C2 去重
106- const treeMode = isTreeMode ( keyword , tagFilter , sortMode ) ;
107-
108- // 折叠初始值(沿用 v0.15)
109- useEffect ( ( ) => {
110- setGroupFolds ( ( cur ) => {
111- let changed = false ;
112- const next = { ...cur } ;
113- for ( const g of groups ) {
114- const key = String ( g . id ) ;
115- if ( ! ( key in next ) ) { next [ key ] = readGroupFold ( key ) ; changed = true ; }
116- }
117- if ( ! ( "none" in next ) ) { next . none = readGroupFold ( "none" ) ; changed = true ; }
118- return changed ? next : cur ;
119- } ) ;
120- } , [ groups ] ) ;
121- useEffect ( ( ) => {
122- try {
123- for ( const [ k , v ] of Object . entries ( groupFolds ) ) window . localStorage . setItem ( `notes:group-fold:${ k } ` , v ? "1" : "0" ) ;
124- } catch { /* 隐私模式 */ }
125- } , [ groupFolds ] ) ;
126-
127- // 显示节(树/平铺)——节内展示序/分桶/accent 全在 utils/noteSectionModel.buildSections
128- // deps 保留 groupFolds:函数体不读它,但移除会改变重算次数(本批只搬家不优化)
129- const sections = useMemo (
130- ( ) => buildSections ( { notes, groups, groupFilter, theme, treeMode, manualOrders, groupOrderRows } ) ,
131- [ treeMode , groups , notes , groupFolds , manualOrders , theme , groupFilter , groupOrderRows ] ,
132- ) ;
133-
134- // 可见序(L1 审查:折叠组行不参与区间/划选——与渲染可见一致;折叠组头仍在)
135- const visibleOrder = useMemo ( ( ) => buildVisibleOrder ( sections , groupFolds ) , [ sections , groupFolds ] ) ;
95+ // 折叠记忆 + 展树数据(treeMode 总闸 / sections 展示节 / visibleOrder 全局可见序)
96+ // —— 裸键折叠记忆与纯函数派生见 hooks/useNoteSections + utils/noteSectionModel
97+ const { treeMode, sections, visibleOrder, groupFolds, toggleGroupFold } = useNoteSections ( {
98+ notes, groups, keyword, tagFilter, sortMode, groupFilter, theme, manualOrders, groupOrderRows,
99+ } ) ;
136100
137101 // ── 行交互 / 多选 / 菜单(Esc 优先级链、可见序镜像、选集裁剪)——见 hooks/useNoteListSelection
138102 const {
@@ -172,8 +136,6 @@ export default function NoteListView({
172136 />
173137 ) ;
174138
175- const toggleGroupFold = ( key : string ) => setGroupFolds ( ( cur ) => ( { ...cur , [ key ] : ! cur [ key ] } ) ) ;
176-
177139 /**
178140 * 右键菜单「上移/下移」可用性(REQ-315):仅树视图 scope 上下文开放(交互矩阵:
179141 * 平铺/搜索/标签/非默认排序禁移动——移动=scope 级手排快照,过滤结果是子集非
0 commit comments