-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
enhancementNew feature or requestNew feature or request
Description
📝 Description
目前 isNewSet 的計算邏輯分散在 Options 元件內部(第 40 行),但根據元件架構,這個邏輯應該在使用 SetOptions 實例的父層元件(如 SetsList 和 Record/Interval)中計算,然後透過 props 層層傳遞到最終的 Options 元件。
🔍 Current Implementation
在 options.tsx 第 40 行:
const isNewSet = setIndex === record?.sets.length;父層元件使用方式:
SetsList元件:<SetOptions recordId={recordId} setIndex={setIndex} />Record/Interval元件:<SetOptions recordId={recordId} setIndex={setIndex + 1} />
🎯 Expected Implementation
- 在
SetsList和Record/Interval父元件中計算isNewSet值 - 透過 props 層層傳遞:父元件 →
SetOptions→SetOptionsPanel→Options - 移除
Options元件內部的計算邏輯
📂 Files to Modify
- list.tsx (SetsList 元件)
- index.tsx (Record/Interval 元件)
- index.tsx (SetOptions 元件)
- index.tsx (SetOptionsPanel 元件)
- options.tsx (Options 元件)
✅ Acceptance Criteria
-
SetsList元件計算isNewSet並傳遞給SetOptions -
Record/Interval元件計算isNewSet並傳遞給SetOptions -
SetOptions元件接收並傳遞isNewSetprop -
SetOptionsPanel元件接收並傳遞isNewSetprop -
Options元件接收isNewSet作為 prop,移除內部計算邏輯 - 所有相關的 TypeScript 介面都已更新
- 功能保持不變,現有行為不受影響
🛠 Implementation Steps
-
修改
SetsList元件// 在 handleOptionsOpen 中計算 const handleOptionsOpen = (setIndex: number) => { const isNewSet = setIndex === record.sets.length; setSetIndex(setIndex); setOptionsOpen(true); }; // 傳遞 isNewSet prop <SetOptions recordId={recordId} setIndex={setIndex} isNewSet={isNewSet} />
-
修改
Record/Interval元件// 在 Interval 元件中 const isNewSet = true; // setIndex + 1 總是新一局 <SetOptions recordId={recordId} setIndex={setIndex + 1} isNewSet={isNewSet} />
-
更新
SetOptions元件介面export const SetOptions = ({ recordId, setIndex, isNewSet, }: { recordId: string; setIndex: number; isNewSet: boolean; }) => {
-
更新
SetOptionsPanel元件<SetOptionsPanel recordId={recordId} isNewSet={isNewSet} />
-
更新
Options元件export const Options = ({ recordId, isNewSet }: { recordId: string; isNewSet: boolean; }) => { // 移除內部計算 // const isNewSet = setIndex === record?.sets.length;
🏷 Labels
refactoring component-architecture typescript props-drilling medium-priority
💡 Benefits
- 將業務邏輯提升到適當的層級
- 提高元件的可預測性和可測試性
- 減少元件對外部資料的依賴
- 改善程式碼的可維護性
- 使 props 流向更加清晰
⚠️ Notes
這個重構涉及多層元件的 props 傳遞,需要確保每一層都正確接收和傳遞 isNewSet 值,避免破壞現有功能。
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request