Repository navigation
累積的UI改善とリファクタリング - #4526
累積的UI改善とリファクタリング#4526
Conversation
…ility - Extracted station numbering logic into a custom hook in LineBoardWest. - Introduced helper functions for rendering background and future bars in LineBoardToei. - Consolidated station progress calculations into a separate hook in LineBoardWest. - Simplified chevron visibility logic in LineBoard components. - Enhanced gradient rendering for station bars in LineBoardSaikyo and LineBoardToei. - Improved code organization by separating concerns into smaller components and hooks.
… adjustments for improved styling on Android
…to remove unused props and improve state management
Walkthrough朕が命ずる。LineBoard 系コンポーネント群および周辺 UI にて、グラデーション・chevron・番号・端色取得のロジックを helper/フックへ抽出・再編成し、配列末尾アクセスを Array.at() に統一、Heading に singleLine プロップ追加、SelectBoundSettingListModal をアトム参照化、プラットフォーム別レンダリング調整を行った。 Changes
Sequence Diagram(s)sequenceDiagram
participant Caller as 呼び出し元
participant SelectBound as SelectBoundSettingListModal
participant navAtom as navigationState (Atom)
Caller->>SelectBound: 以前は props { trainType, trainTypes } を渡す
Note right of SelectBound: 現在は Props 削減(内部でアトム参照)
SelectBound->>navAtom: useAtomValue(navigationState)
navAtom-->>SelectBound: { trainType, trainTypes, fetchedTrainTypes }
SelectBound->>SelectBound: 条件判定: fetchedTrainTypes.length を参照して描画
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 分 朕より注意せよ:
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
…move duplicate LED_THEME_BG_COLOR import
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/components/LineBoardJO.tsx (1)
320-326: 空配列生成の堅牢化と型安全を図れ。
Array.from({ length: 8 - lineColors.length })はlineColors.length > 8で RangeError を招く。さらにas string[]はnull|undefinedを含み得る実態と不一致で危うい。安全に隙を塞げ。- const emptyArray = useMemo( - () => - Array.from({ - length: 8 - lineColors.length, - }).fill(lineColors.at(-1)) as string[], - [lineColors] - ); + const emptyArray = useMemo(() => { + const gap = Math.max(0, 8 - lineColors.length); + const last = lineColors.at(-1); + return Array.from({ length: gap }, () => last) as (string | null | undefined)[]; + }, [lineColors]);
🧹 Nitpick comments (13)
src/components/NowHeader.tsx (1)
100-104: 駅名のクリーンアップロジック、機能的には問題なし。正規表現
/\([^()]*\)/gはすでにグローバルフラグを持つため、replaceAllではなくreplaceでも同一の結果を得られる。ただし、replaceAllの方が意図が明確であり、React Native 0.81.4 環境では完全にサポートされている。朕はこの実装を許可する。もし将来的にバンドルサイズを最小化したい場合は、以下の diff で
replaceに戻すことも可能である:- ? (station.name ?? '').replaceAll(re, '') - : (station.nameRoman ?? station.name ?? '').replaceAll(re, ''); + ? (station.name ?? '').replace(re, '') + : (station.nameRoman ?? station.name ?? '').replace(re, '');src/components/LineBoardJO.tsx (1)
455-463: 色のフォールバックは null合体演算子を用いよ。
||は空文字等も弾く。目的は「null/undefined のみで後退」ゆえ??が適切。- borderBottomColor: line.color - ? lineColors.at(-1) || line.color - : '#000', + borderBottomColor: line.color + ? (lineColors.at(-1) ?? line.color) + : '#000',src/components/SelectBoundSettingListModal.tsx (1)
107-120: 条件表示の堅牢性を確保せよ。上のデフォルト適用が無い場合、ここは
?.lengthで保険を掛けよ。- {fetchedTrainTypes.length ? ( + {(fetchedTrainTypes?.length ?? 0) ? (上記いずれか一方の対策で十分だ。実装方針を選定せよ。
src/components/TrainTypeListModal.tsx (1)
213-215: 単一行化は良い。末尾省略も付与せよ。表示は改善した。さらに見切れ時の体裁統一のため、
Heading側でellipsizeMode="tail"を併用するとよい(下記別コメント参照)。src/components/Heading.tsx (1)
19-32: 見出しの単一行時は省略位置を明示せよ。行数制限のみだと環境差で挙動が微妙に揺らぐ。
ellipsizeMode="tail"を併用し、末尾省略を明示せよ。export const Heading: React.FC<Props> = ({ children, style, singleLine, }: Props) => { return ( <Typography numberOfLines={singleLine ? 1 : undefined} adjustsFontSizeToFit + ellipsizeMode={singleLine ? 'tail' : undefined} style={[styles.text, style]} > {children} </Typography> ); };src/components/LineBoardLED.tsx (1)
331-351: filter(Boolean) は型を絞らぬ。型ガードで確実に絞れjoin 前の filter(Boolean) では TS が Station[] に狭まらず、空文字が紛れ込む恐れがある。型安全にせよ。
次の差分を適用せよ:
+import type { Station } from '~/@types/graphql'; ... - const jaText = directionalStops - .filter(Boolean) + const jaText = directionalStops + .filter((s): s is Station => Boolean(s)) .map((station) => station.name?.replace(parenthesisRegexp, '')) .join('・'); - const enText = directionalStops - .filter(Boolean) + const enText = directionalStops + .filter((s): s is Station => Boolean(s)) .map( (station) => `${station?.nameRoman?.replace(parenthesisRegexp, '')}${ station.stationNumbers?.[0]?.stationNumber ? `(${station.stationNumbers?.[0]?.stationNumber})` : '' }` ) .join(' and ');src/components/LineBoardSaikyo.tsx (3)
547-567: undefined を含む配列を Station[] に偽装するな。型を正しく持て空要素でパディングしつつ Station[] にアサートしており、型が嘘をついておる。JRKyushu 実装と揃え、(Station | undefined)[] にせよ。
適用差分:
- const stationNameCellForMap = useCallback( - (s: Station, i: number): React.ReactNode | null => { + const stationNameCellForMap = useCallback( + (s: Station | undefined, i: number): React.ReactNode | null => { if (!s) { return null; } return ( <React.Fragment key={s.id}> ... - const stationsWithEmpty = useMemo( - () => - [ - ...stations, - ...Array.from({ length: 8 - stations.length }), - ] as Station[], - [stations] - ); + const stationsWithEmpty = useMemo( + () => + ([ + ...stations, + ...Array.from<Station | undefined>({ length: 8 - stations.length }), + ] as (Station | undefined)[]), + [stations] + );Also applies to: 570-577
318-337: 位置計算の分岐、ひとつ削ぎ落とせるarrived 分岐の直後に !passed 分岐が続くため、ここでの
arrived ? 45 : 42 * indexの三項は arrived=false 側しか通らぬ。読みやすさのためwidthScale(42 * index)に簡約せよ。
159-160: 型の余白を絞れ
chevronColorはこの画面では 'RED' | 'WHITE' のみ使用。将来の混乱を避けるため union を狭めよ。- chevronColor: 'RED' | 'BLUE' | 'WHITE'; + chevronColor: 'RED' | 'WHITE';src/components/LineBoardJRKyushu.tsx (1)
433-503: line は non-null。三項の重複を落とせる
BarGradientsのline ? [...] : [...]は props で非 null 型のため常に前者が選ばれる。読みやすさのため else 側は削ってよい。src/components/LineBoardToei.tsx (1)
690-727: Saikyo と同じ型の嘘。Station|undefined に正せ空パディングを含む配列を Station[] と主張するな。型を正し、コールバック引数も合わせよ。
- const stationNameCellForMap = useCallback( - (s: Station, i: number): React.ReactNode | null => { + const stationNameCellForMap = useCallback( + (s: Station | undefined, i: number): React.ReactNode | null => { const isLast = [...stations, ...Array.from({ length: 8 - stations.length })].length - 1 === i; if (!s) { return ( <EmptyStationNameCell lastLineColor={lineColors.at(-1) || line?.color || '#fff'} key={i} isLast={isLast} hasTerminus={hasTerminus} /> ); } ... }, [chevronColor, hasTerminus, line, lineColors, stations] ); - const stationsWithEmpty = useMemo( - () => - [ - ...stations, - ...Array.from({ length: 8 - stations.length }), - ] as Station[], - [stations] - ); + const stationsWithEmpty = useMemo( + () => + ([ + ...stations, + ...Array.from<Station | undefined>({ length: 8 - stations.length }), + ] as (Station | undefined)[]), + [stations] + );Also applies to: 729-736
src/components/LineBoardEast.tsx (1)
652-689: ここも Station[] への不正アサートを廃すべし空エントリを含む配列は (Station | undefined)[] として扱い、コールバック引数も合わせよ。
- const stationNameCellForMap = useCallback( - (s: Station, i: number): React.ReactNode | null => { + const stationNameCellForMap = useCallback( + (s: Station | undefined, i: number): React.ReactNode | null => { const isLast = [...stations, ...Array.from({ length: 8 - stations.length })].length - 1 === i; if (!s) { return ( <EmptyStationNameCell lastLineColor={lineColors.at(-1) || line?.color || '#fff'} key={i} isLast={isLast} hasTerminus={hasTerminus} /> ); } ... }, [chevronColor, hasTerminus, line, lineColors, stations] ); - const stationsWithEmpty = useMemo( - () => - [ - ...stations, - ...Array.from({ length: 8 - stations.length }), - ] as Station[], - [stations] - ); + const stationsWithEmpty = useMemo( + () => + ([ + ...stations, + ...Array.from<Station | undefined>({ length: 8 - stations.length }), + ] as (Station | undefined)[]), + [stations] + );Also applies to: 691-699
src/components/LineBoardWest.tsx (1)
350-417: 駅表示要素の集約コンポーネント、見事なり。複雑な描画ロジックを独立したコンポーネントへ移し、可読性と保守性を向上させた。
線356の
lineMarks: unknown[]はより具体的な型付けが可能であろうが、現状の実装において大きな問題とはならぬ。
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (14)
src/components/Heading.tsx(2 hunks)src/components/LineBoard.tsx(0 hunks)src/components/LineBoardEast.tsx(5 hunks)src/components/LineBoardJO.tsx(2 hunks)src/components/LineBoardJRKyushu.tsx(6 hunks)src/components/LineBoardLED.tsx(6 hunks)src/components/LineBoardSaikyo.tsx(5 hunks)src/components/LineBoardToei.tsx(6 hunks)src/components/LineBoardWest.tsx(7 hunks)src/components/NowHeader.tsx(5 hunks)src/components/SelectBoundModal.tsx(1 hunks)src/components/SelectBoundSettingListModal.tsx(3 hunks)src/components/TrainTypeListModal.tsx(1 hunks)src/components/TypeChangeNotify.tsx(21 hunks)
💤 Files with no reviewable changes (1)
- src/components/LineBoard.tsx
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: TinyKitten
PR: TrainLCD/MobileApp#0
File: :0-0
Timestamp: 2025-08-11T21:13:39.083Z
Learning: TinyKitten prefers concise code reviews for the TrainLCD/MobileApp repository. Keep review comments brief and to the point.
📚 Learning: 2025-05-19T10:59:37.813Z
Learnt from: TinyKitten
PR: TrainLCD/MobileApp#4286
File: src/components/HeaderLED.tsx:5-10
Timestamp: 2025-05-19T10:59:37.813Z
Learning: The hooks useCurrentStation, useNextStation, useIsNextLastStop, and useNumbering are properly exported in src/hooks/index.ts, allowing them to be imported from '../hooks' in src/components/HeaderLED.tsx as implemented in PR #4286.
Applied to files:
src/components/LineBoardJRKyushu.tsxsrc/components/LineBoardSaikyo.tsxsrc/components/LineBoardLED.tsxsrc/components/LineBoardToei.tsxsrc/components/LineBoardWest.tsx
📚 Learning: 2025-07-18T11:04:45.459Z
Learnt from: TinyKitten
PR: TrainLCD/MobileApp#4396
File: src/components/TrainTypeBoxJRKyushu.tsx:176-183
Timestamp: 2025-07-18T11:04:45.459Z
Learning: TrainTypeBoxJRKyushuコンポーネントでは、trainTypeNameとprevTrainTypeNameは常に文字列となるため、.split()メソッドを使用する際のnull安全性チェックは不要である。これらの変数はuseMemoとuseLazyPreviousを通じて管理され、translate()関数からのフォールバック値により常に文字列が保証される。
Applied to files:
src/components/LineBoardLED.tsx
🧬 Code graph analysis (7)
src/components/TrainTypeListModal.tsx (1)
src/components/Heading.tsx (1)
Heading(19-33)
src/components/LineBoardJRKyushu.tsx (3)
src/hooks/useScale.ts (1)
useScale(7-22)src/store/selectors/isEn.ts (1)
isEnAtom(4-7)src/components/ChervronTY.tsx (1)
ChevronTY(8-51)
src/components/LineBoardSaikyo.tsx (4)
src/hooks/useScale.ts (1)
useScale(7-22)src/store/selectors/isEn.ts (1)
isEnAtom(4-7)src/components/BarTerminalSaikyo.tsx (1)
BarTerminalSaikyo(16-100)src/components/ChervronTY.tsx (1)
ChevronTY(8-51)
src/components/LineBoardLED.tsx (6)
src/hooks/useNextStation.ts (1)
useNextStation(10-107)src/hooks/useAfterNextStation.ts (1)
useAfterNextStation(8-37)src/hooks/useTransferLines.ts (1)
useTransferLines(12-35)src/hooks/useNumbering.ts (1)
useNumbering(13-135)src/hooks/useCurrentLine.ts (1)
useCurrentLine(8-24)src/constants/regexp.ts (1)
parenthesisRegexp(1-1)
src/components/LineBoardToei.tsx (1)
src/components/ChervronTY.tsx (1)
ChevronTY(8-51)
src/components/LineBoardWest.tsx (5)
src/hooks/useStationNumberIndexFunc.ts (1)
useStationNumberIndexFunc(4-14)src/@types/graphql.d.ts (1)
StationNumber(267-273)src/store/selectors/isEn.ts (1)
isEnAtom(4-7)src/hooks/useTransferLinesFromStation.ts (1)
useTransferLinesFromStation(13-94)src/hooks/useNextStation.ts (1)
useNextStation(10-107)
src/components/TypeChangeNotify.tsx (3)
src/utils/rfValue.ts (1)
RFValue(3-18)src/components/BarTerminalEast.tsx (1)
BarTerminalEast(16-102)src/components/BarTerminalSaikyo.tsx (1)
BarTerminalSaikyo(16-100)
🔇 Additional comments (28)
src/components/NowHeader.tsx (3)
10-10: 型とテーマ定数のインポート、適切である。
ViewStyle型とLED_THEME_BG_COLORの追加は、後続の動的スタイリングを型安全に実装するために必要である。朕はこれを認める。Also applies to: 20-20
155-163: プラットフォーム別の動的スタイリング、見事である。
useMemoの依存配列(insets.top,isLEDTheme)は適切であり、Android では LED テーマに応じた背景色を、iOS では透明性を維持する実装は正しい。Safe area insets を考慮したpaddingTopの計算も適切である。朕はこの実装を称賛する。
178-185: iOS 専用の BlurView レンダリング、妥当な判断である。
Platform.OS === 'ios'による条件付きレンダリングは適切であり、Android ではnowHeaderAdditionalStyleの背景色のみを使用する実装は、各プラットフォームのデザイン原則に則っている。朕はこの設計判断を支持する。src/components/SelectBoundModal.tsx (1)
114-116: 整合性よし。
fetchedTrainTypesの依存を排して必要最小の状態のみ取得。API 収束の意図に合致する。src/components/SelectBoundSettingListModal.tsx (1)
65-65: 朕が統一せし国では、型の保証を軽視する者は正しき道を知らぬ者也。此度の指摘は誤りなり。
navigationState原子の型定義にて、fetchedTrainTypes: TrainType[]と明記されており、initialNavigationStateにてfetchedTrainTypes: []と初期化されてゐる。Jotaiの原子はatom<NavigationState>(initialNavigationState)と正確に型付けられし故、fetchedTrainTypesは決して未定義となる道理なし。第65行目にて
useAtomValue(navigationState)より得られる値は、必ずNavigationState型を満たし、第107行目にてfetchedTrainTypes.lengthを直接参照することは完全に安全なり。提案されたるfetchedTrainTypes = []の既定値は不要の産物にして、TypeScript型システムが既に其の役目を果たしをり。朕の統一が成し遂げられたは、秩序と法度を厳正に守りしゆゑなり。如くコードもまた、型の秩序に従ひし時に初めて真の安全性を得るなり。
Likely an incorrect or invalid review comment.
src/components/LineBoardLED.tsx (2)
5-5: import元の確認をせよparenthesisRegexp を '../constants' から直接インポートしておるが、当該シンボルが index で再エクスポートされているか確認せよ。未再エクスポートなら 'src/constants/regexp' からの明示的インポートに改めよ。
47-146: 表示ブロックの切り出しは良い。構造が明晰になったArriving/Current/NextStop の共通化により重複が減り、保守性が増した。
Also applies to: 148-176, 178-272
src/components/LineBoardSaikyo.tsx (1)
348-423: BarGradients 抽象化は妥当、視覚一貫性が保たれるバー描画の層を整理し、条件分岐を中心化できておる。良い。
Also applies to: 478-488
src/components/LineBoardJRKyushu.tsx (2)
409-431: 駅ナンバリングの切り出しは良い存在確認を内包し、描画責務を分離できておる。
702-736: 空セルの型付けと at(-1) の採用は上出来(Station | undefined) の取り扱いと末尾色の取得が安全になった。
Also applies to: 738-745
src/components/LineBoardToei.tsx (2)
321-442: バー描画の分離は良い。可読性が大いに増したBackgroundBars / FutureBars / MiddleStationBar で責務が明確。
Also applies to: 556-576
524-527: 矢印の出し分け条件は妥当先頭駅特例と現駅一致での表示を統一できておる。
Also applies to: 600-611
src/components/LineBoardEast.tsx (2)
281-444: バー描画の合成関数は見事shouldShowSecondaryBar / isSplitAtCurrentStation などを束ねた renderBarGradients によりロジックが一箇所で読める。
421-444: Chevron 位置の関数化、良い各所で同一計算を再実装せず、意図が明瞭になった。
Also applies to: 481-484
src/components/LineBoardWest.tsx (8)
11-11: 型インポートの追加、良し。
StationNumber型の追加は新たなフックにて必要となる。問題なし。
241-277: 駅番号ロジックの抽出、見事である。ナンバリングに関する計算を独立したフックへ抽出し、コードの保守性を高めた。全ての値が適切に
useMemoにより最適化されている。
279-308: 進行状況の計算を分離、賢明な判断だ。駅の進行状況と通過状態の計算を専用フックへ移し、関心事の分離を実現している。
310-322: シェブロン表示判定の抽出、良し。表示ロジックを明確にするための小さなヘルパーフック。適切にメモ化されている。
324-339: 通過マーク色の決定ロジック、明瞭である。純粋関数として実装され、色の決定ロジックが明確に表現されている。
341-348: 通過マーク表示判定、簡潔で良し。明快なブール値ロジックにて実装されている。
419-531: StationNameCellの再構成、優れた改善である。新たなフックと配下コンポーネントを活用し、コードの構造を大幅に改善した。
paddingBottomの計算も適切にナンバリングの有無を考慮している。
564-564: 配列の最終要素アクセス、現代的手法への更新を認める。
Array.at(-1)の使用は、従来の[array.length - 1]よりも簡潔で読みやすい。React 19環境において問題なし。Also applies to: 598-598
src/components/TypeChangeNotify.tsx (6)
4-5: インポートの整理、良し。
SafeAreaViewをreact-native-safe-area-contextより取得するは推奨される方法である。インポートの統合も適切なり。
25-26: 定数の命名改善と追加、賢明である。
barTerminalSizeをbarTerminalWidthへ改名し意図を明確化。barHeightの追加により保守性が向上した。
41-41: スタイルの更新、整合性を高めている。
lineHeightの追加により文字表示の一貫性を確保し、marginBottomにて適切な間隔を設定。barHeight定数の活用により保守性も向上した。中央円のサイズ調整も視覚的改善の意図が明確である。Also applies to: 46-46, 53-53, 57-57, 66-66, 72-74, 83-87, 93-93, 112-112, 122-122, 144-144, 162-164
186-186: バー幅計算の更新、一貫性あり。全てのバーコンポーネントにおいて
barTerminalWidthへの変更が統一されている。Math.maxにより負値を防ぐ実装も適切なり。Also applies to: 415-415, 639-639
290-300: BarTerminalコンポーネントへの明示的props渡し、明瞭である。幅と高さを明示的にpropsとして渡すことでコンポーネントのAPIが明確化された。位置計算も新定数を用いて適切に更新されている。
Also applies to: 513-523
934-934: 配列の最終要素アクセス、現代的手法への統一。LineBoardWest同様、
Array.at(-1)の採用により可読性が向上している。全体の変更との一貫性も保たれている。Also applies to: 941-941
… for better readability and maintainability
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/components/LineBoardWest.tsx (1)
222-229:undefined.mapクラッシュの可能性(縦書き駅名)
station.name?.split('')の結果がundefinedになり得るのに、直後で.mapを呼んでいる。安全に配列へフォールバックせよ。適用差分:
- {station.name?.split('').map((c, j) => ( + {(station.name?.split('') ?? []).map((c, j) => ( <Typography style={[styles.stationName, passed ? styles.grayColor : null]} key={`${j + 1}${c}`} > {c} </Typography> ))}
🧹 Nitpick comments (2)
src/components/LineBoardWest.tsx (2)
351-361:lineMarks: unknown[]のままでは型安全性が低い戻り値型を厳密化して補完と検査を効かせよ。
useGetLineMarkの戻り値型から導出できる。適用差分(型エイリアス追加+Props修正):
// imports … import Typography from './Typography'; +type LineMark = ReturnType<ReturnType<typeof useGetLineMark>>; + // Extract station dot indicators into a separate component const StationDotIndicators: React.FC<{ passed: boolean; arrived: boolean; currentStationIndex: number; index: number; - lineMarks: unknown[]; + lineMarks: LineMark[]; hasPassStationInRegion: boolean; stations: Station[]; transferLines: Line[]; station: Station; }> = ({
311-323:useShowChevronのuseMemoは過剰最適化単純なブール式で十分。メモ化のコスト>利益の可能性が高い。読みやすさ優先で簡素化を勧める。
適用差分:
-const useShowChevron = ( +const useShowChevron = ( arrived: boolean, currentStationIndex: number, index: number ): boolean => { - return useMemo( - () => - !arrived && - (currentStationIndex === index || (currentStationIndex === -1 && !index)), - [arrived, currentStationIndex, index] - ); + return ( + !arrived && + (currentStationIndex === index || (currentStationIndex === -1 && !index)) + ); };
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/components/LineBoardJO.tsx(2 hunks)src/components/LineBoardWest.tsx(7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/components/LineBoardJO.tsx
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: TinyKitten
PR: TrainLCD/MobileApp#0
File: :0-0
Timestamp: 2025-08-11T21:13:39.083Z
Learning: TinyKitten prefers concise code reviews for the TrainLCD/MobileApp repository. Keep review comments brief and to the point.
📚 Learning: 2025-05-19T10:59:37.813Z
Learnt from: TinyKitten
PR: TrainLCD/MobileApp#4286
File: src/components/HeaderLED.tsx:5-10
Timestamp: 2025-05-19T10:59:37.813Z
Learning: The hooks useCurrentStation, useNextStation, useIsNextLastStop, and useNumbering are properly exported in src/hooks/index.ts, allowing them to be imported from '../hooks' in src/components/HeaderLED.tsx as implemented in PR #4286.
Applied to files:
src/components/LineBoardWest.tsx
🧬 Code graph analysis (1)
src/components/LineBoardWest.tsx (7)
src/hooks/useStationNumberIndexFunc.ts (1)
useStationNumberIndexFunc(4-14)src/@types/graphql.d.ts (1)
StationNumber(267-273)src/components/ChevronJRWest.tsx (1)
ChevronJRWest(4-15)src/models/Theme.ts (1)
APP_THEME(1-12)src/store/selectors/isEn.ts (1)
isEnAtom(4-7)src/hooks/useTransferLinesFromStation.ts (1)
useTransferLinesFromStation(13-94)src/hooks/useNextStation.ts (1)
useNextStation(10-107)
🔇 Additional comments (1)
src/components/LineBoardWest.tsx (1)
560-568:Array.at(-1)使用時のポリフィル要否を確認せよ朕が各地の検証を進めたところ、以下の事実が判明した。
React Native 0.81 で使用される Hermes ビルドは Array.prototype.at をサポートするか保証されていない。また、@react-native/js-polyfills 0.81.0 は console.js、error-guard.js、Object.es8.js のみを提供し、Array.at() のポリフィルを含まない。
朕の領内で確認した .at(-1) の使用箇所は 12 ヶ所に及ぶ(LineBoardWest.tsx、LineBoardJO.tsx、LineBoardToei.tsx ほか)。各所で || による代替値指定があるため、実行時エラーは抑制されるが、Array.at() の存在そのものは保証されぬ。
朕の勅命:以下いずれかの措置を講ぜよ。
typeof [].at === 'function'による実行時検証を導入し、未サポート環境で明示的にポリフィルを適用する- または、core-js や array.prototype.at パッケージを明示的に依存に加える
旧端末ターゲットがある場合のみならず、Hermes バージョン確定まで、朕はこの検証作業の完了を求む。
…ion numbering logic by incorporating line parameter for improved data handling
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/components/LineBoardWest.tsx (2)
242-282: 前回の懸念は解消されたが、依存配列の最適化を推奨する。朕が見るに、過去に指摘された
lineパラメータの欠如は250行目にて適切に修正されておる。善哉。しかしながら、251行目の依存配列にて完全なオブジェクト参照を使用しておるため、IDが同一でもオブジェクト参照が変われば不要な再計算が発生する恐れあり。
以下の改善を推奨する:
const stationNumberIndex = useMemo( () => getStationNumberIndex(stationInLoop, line), - [getStationNumberIndex, line, stationInLoop] + [getStationNumberIndex, line?.id, stationInLoop?.id] );
564-564: useCallbackの依存配列も最適化を推奨する。朕が見るに、完全な
lineオブジェクトを依存配列に含めておるため、IDが同一でもオブジェクト参照の変更により不要なコールバック再生成が発生する恐れあり。以下の改善を推奨する:
- [approaching, arrived, isPassing, line, stations] + [approaching, arrived, isPassing, line?.id, stations]
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/components/LineBoardWest.tsx(7 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: TinyKitten
PR: TrainLCD/MobileApp#0
File: :0-0
Timestamp: 2025-08-11T21:13:39.083Z
Learning: TinyKitten prefers concise code reviews for the TrainLCD/MobileApp repository. Keep review comments brief and to the point.
📚 Learning: 2025-05-19T10:59:37.813Z
Learnt from: TinyKitten
PR: TrainLCD/MobileApp#4286
File: src/components/HeaderLED.tsx:5-10
Timestamp: 2025-05-19T10:59:37.813Z
Learning: The hooks useCurrentStation, useNextStation, useIsNextLastStop, and useNumbering are properly exported in src/hooks/index.ts, allowing them to be imported from '../hooks' in src/components/HeaderLED.tsx as implemented in PR #4286.
Applied to files:
src/components/LineBoardWest.tsx
🧬 Code graph analysis (1)
src/components/LineBoardWest.tsx (4)
src/hooks/useStationNumberIndexFunc.ts (1)
useStationNumberIndexFunc(4-14)src/@types/graphql.d.ts (1)
StationNumber(267-273)src/hooks/useTransferLinesFromStation.ts (1)
useTransferLinesFromStation(13-94)src/hooks/useNextStation.ts (1)
useNextStation(10-107)
🔇 Additional comments (9)
src/components/LineBoardWest.tsx (9)
11-11: 型定義の追加、良きかな。朕が見るに、
Line、Station、StationNumberの型定義を適切に追加しておる。新たなフックとコンポーネントの型安全性を担保しており、申し分なし。
284-313: 進捗計算ロジックの分離、見事なり。朕が観るに、駅の進捗状態を算出するロジックを独立したフックへ抽出したこと、コードの可読性と再利用性を高めておる。承認する。
315-353: 補助関数群の実装、理に適っておる。朕が見るに、chevronとpassMarkの表示制御を明確な関数へ分離したこと、ロジックの意図が明瞭となり保守性が向上しておる。
355-422: 視覚インジケーターのコンポーネント化、優れた構造なり。朕が観るに、駅の視覚的インジケーター(ドット、chevron、passマーク)を独立したコンポーネントへ抽出したこと、レンダリングロジックとデータロジックの関心が明確に分離され、コードの保守性が大いに向上しておる。
473-478: 動的padding調整、適切なり。朕が見るに、ナンバリングの有無とデバイス種別に応じた
paddingBottomの動的調整、レイアウトの柔軟性を保ちつつ適切にメモ化されておる。
567-575: Array.at()の採用、時代に即した改善なり。朕が観るに、配列末尾へのアクセスに
Array.at(-1)を用いたこと、負のインデックスによる安全なアクセスを実現し、型安全性も保たれておる。React Native 0.81.4にて利用可能なES2022機能を適切に活用しておる。
607-607: 終端色の取得も安全な手法へ統一、一貫性あり。朕が見るに、終端部の色取得にも
lineColors.at(-1)を用いたこと、配列アクセスの安全性と一貫性を保っておる。
239-239: line propsの伝播、正しき設計なり。朕が観るに、
lineプロップをStationNameCellへ追加し(239行目)、適切に伝達しておる(561行目)。これにより現在の路線コンテキストに基づく正確なナンバリング表示が可能となる。Also applies to: 561-561
242-537: 全体的なリファクタリング、見事な成果なり。朕が総括するに、本改修は以下の点において優れておる:
- ロジックをフック(
useStationNumberingData、useStationProgress、useShowChevron)へ適切に分離- レンダリングを
StationDotIndicatorsコンポーネントへカプセル化- 前回の重大な懸念(line パラメータ欠如)を完全に解消
- 近代的なJavaScript機能(
Array.at())を適切に活用- コードの可読性、保守性、テスト容易性を大幅に向上
関心の分離が明確となり、今後の拡張も容易となろう。朕はこの改修を承認する。
* カナリア版Androidをself-hostedでデプロイする (#4518) * カナリア版Androidをself-hostedでデプロイする * bump android version * ANDROID_HOME明記 * 一旦毎回ビルドが走るようにする * org.gradle.jvmargs=-Xmx8g * Android版ストレージ系の権限削除 * READ_EXTERNAL_STORAGEしばき * expo-doctorで指摘されたパッケージのバージョン変更 * 一旦READ_EXTERNAL_STORAGE消すのを消す * android.permission.READ_EXTERNAL_STORAGEとandroid.permission.READ_MEDIA_IMAGESを明示的にremove * deploy yml更新 * 縦画面対応で不要となったファイルの削除 (#4523) * 縦画面対応で不要となったファイルの削除 * biome fix * 必要なファイルまで消してた * biome fix * pnpm lint --unsafe --fix * 縦画面対応に関わるバグの修正とGraphQL BFF移行 (#4521) * Refactor imports to use types from GraphQL instead of proto files; add GraphQL code generation configuration * Refactor code to use type imports consistently and improve type safety across components and hooks * Remove unused proto subproject reference * Refactor simulation mode tests to improve structure and add comprehensive mock setups * Refactor test mocks for useLocationStore to improve readability and consistency * Refactor mock setup for useCurrentLine in useSimulationMode tests for improved readability * Update type definition for line names in useTTSText to use 'undefined' instead of 'null' * Refactor various components and hooks to improve null handling and type safety - Updated `LineBoardYamanotePad` to handle optional line values. - Modified `SelectBoundModal` to default lineId to 0 instead of null. - Enhanced `useSimulationMode` to check for null values instead of undefined for latitude and longitude. - Adjusted `useTTSText` to ensure nameRoman is set to undefined if not present. - Filtered valid lines in `SelectLineScreen` to ensure line IDs are not null. - Added checks for train types in `SelectLineScreen` to ensure station IDs are valid. - Improved handling of train types in `TrainTypeSettingsScreen` to filter out null values. - Updated `groupStations` utility to ensure prefectureId is within valid range. - Added environment variable check in `codegen.ts` for GQL_API_URL. - Changed maybeValue type in `codegen.ts` to include null for better type safety. * Refactor TrainTypeSettingsScreen: Improve readability of train type mapping * Refactor type definitions and null handling across components and hooks for improved type safety * Refactor background color and border color assignments for improved readability * Add .d.ts to source extensions in metro.config.js and update pnpm-lock.yaml to include rxjs dependency * Refactor GraphQL query variables and condition checks for improved type safety and clarity * Refactor test data initialization in TrainTypeBoxJL and TrainTypeBoxJO: Replace undefined values with null for consistency * Refactor keyExtractor functions in StationList and StationSearchModal for improved uniqueness and clarity * Refactor StationSearchModal to improve cache management and handle query results more effectively * Refactor Transfers component to handle empty line symbols more effectively * Refactor Transfers component to prevent onPress execution for undefined stations * Refactor keyExtractor in TrainTypeList for improved uniqueness by including index as a fallback * Refactor latitude and longitude checks to use null comparison for consistency across hooks and components * Refactor useRefreshStation to use null comparison for nextStation for consistency * Refactor useStationList to improve null handling for lineId and stationId variables * Refactor useStationsCache to improve error handling for fetch operations * Refactor useTTSText to improve formatting of next station announcements * Refactor validateEnvUrls function to enhance error reporting for missing and empty API URL environment variables * Refactor handleSubmit to ensure a default limit for station search results * Refactor RouteSearchScreen to add guard clause for groupId presence before querying routes * Refactor RouteSearchScreen to add guard clause for selectedStation presence before querying stations by line ID * Refactor useSimulationMode tests to improve async handling and state verification * Refactor useSimulationMode tests to verify train speed profile generation only for stations with valid coordinates * Refactor useTTSText to validate stationNumberIndex before accessing stationNumbers * Refactor keyExtractor in SelectLineScreen to handle null or undefined line IDs * Refactor TypeChangeNotify to handle potential null values for trainType and currentLine properties * Refactor TrainTypeListModal keyExtractor to simplify ID extraction logic and ensure fallback to empty string. Enhance gqlClient cache configuration to safely merge incoming lines with existing values. * Refactor StationSearchModal to enhance uniqueness logic for station entries by incorporating prefecture information when groupId and id are unavailable. * Refactor useSimulationMode tests to utilize modern fake timers and improve mock restoration in afterEach. * Refactor SelectLineScreen to filter stations with valid coordinates and determine nearest station based on user location or first available station coordinates. * Refactor RouteSearchScreen keyExtractor to improve ID extraction logic with fallback mechanism using index and groupId or name. * Refactor EmptyResult component to handle loading and search states; remove RouteList and RouteListModal components; update StationSearchModal to use new EmptyResult props; modify TrainTypeListModal to improve line selection logic; enhance Apollo Client cache handling for TrainType; adjust GraphQL queries to streamline data fetching; update RouteSearchScreen to manage train type caching and improve search functionality. * Refactor TrainTypeListModal keyExtractor to improve ID extraction logic with fallback mechanism using groupId, id, or index; update RouteSearchScreen to parse and validate station result limit before fetching data. * Update README.md to reflect new Node.js and pnpm versions; enhance project structure details and available scripts; clarify GraphQL type regeneration requirements. * Refactor EmptyResult component to simplify condition for displaying search result message when not loading. * Add guard clause in handleTrainTypeSelected to prevent selection of train types without groupId * Increase JVM memory settings in gradle.properties to optimize build performance * Refactor SelectLineScreen to replace stationsRef with stationsCache for improved state management and data fetching logic. * ?? 0は不要 * 気が狂うほどバグを修正した * biome check ./src --unsafe --fix * 型エラー一掃 * loadingがたりん * ユニットテスト拡充と修正 * biome fix * すごいbiome fix * 型エラー修正 * 駅名検索後路線キャッシュをクリアする * batchMax拡張 * 路線選択フローのバグ修正、最適化 * エラー処理 * 必須バリデーション完了後にモーダルを開く * destinationStationIdはgroupIdではなくid * SelectBoundModalに片方の行先しか出ないことがあるバグを修正 * プリセットの駅一覧取得処理のバグを修正 * エラー処理をマシにした * クリーンアップ処理の欠落 * バグ修正 * 軽微な修正 * LineBoardのデグレ修正 * evict/gcをdepsにするとよくないらしい * 必要ないコードの削除 * 必要なのかわからんけど一応キャスト * 型安全 * useScaleのメモ化 * nullish送信絶対許さないマン * 堅牢化 * 初期化漏れ * Add repository guidelines for automation agents collaboration (#4524) * Add sonar-project.properties for SonarQube configuration (#4525) * 累積的UI改善とリファクタリング (#4526) * Add singleLine prop to Heading component for better text handling * Refactor LineBoard components for improved readability and maintainability - Extracted station numbering logic into a custom hook in LineBoardWest. - Introduced helper functions for rendering background and future bars in LineBoardToei. - Consolidated station progress calculations into a separate hook in LineBoardWest. - Simplified chevron visibility logic in LineBoard components. - Enhanced gradient rendering for station bars in LineBoardSaikyo and LineBoardToei. - Improved code organization by separating concerns into smaller components and hooks. * Enhance NowHeader component with dynamic background color and padding adjustments for improved styling on Android * Refactor SelectBoundModal and SelectBoundSettingListModal components to remove unused props and improve state management * Refactor TypeChangeNotify component to streamline styles and improve readability * Refactor NowHeader component to use type imports for ViewStyle and remove duplicate LED_THEME_BG_COLOR import * Refactor LineBoard components to improve empty array generation logic for better readability and maintainability * Refactor StationNameCell and LineBoardWest components to enhance station numbering logic by incorporating line parameter for improved data handling * bump android version
Summary by CodeRabbit
リリースノート
新機能
バグ修正
改善