refactor(ui): finalize review fixes for action cards and view model
- Guard ActionCard click-outside listener behind open state - Add aria-expanded to ActionGroup collapse toggle - Use optional chaining and drop non-null assertions in column projection
This commit is contained in:
+11
-6
@@ -147,7 +147,9 @@ export function toView(state: GameState, content: GameContent): GameView {
|
||||
}));
|
||||
|
||||
const action = state.activeActionId ? content.actionsById[state.activeActionId] : undefined;
|
||||
const actionProgress = action && action.durationMs ? Math.min(1, state.actionElapsedMs / action.durationMs) : 0;
|
||||
const actionProgress = action?.durationMs
|
||||
? Math.min(1, state.actionElapsedMs / action.durationMs)
|
||||
: 0;
|
||||
const queuedActionIds = [...state.actionQueue];
|
||||
const queuedActionNames = queuedActionIds.map((id) => content.actionsById[id]?.name ?? id);
|
||||
|
||||
@@ -180,9 +182,10 @@ export function toView(state: GameState, content: GameContent): GameView {
|
||||
const kindActions = content.actions.filter((a) => a.kind === kind);
|
||||
|
||||
// For story kind: only include available actions (hides siblings after fork)
|
||||
const includedActions = kind === 'story'
|
||||
? kindActions.filter((a) => actionViewMap.get(a.id)?.available === true)
|
||||
: kindActions;
|
||||
const includedActions =
|
||||
kind === 'story'
|
||||
? kindActions.filter((a) => actionViewMap.get(a.id)?.available === true)
|
||||
: kindActions;
|
||||
|
||||
// Group by action.group, preserving first-seen order
|
||||
const groupOrder: string[] = [];
|
||||
@@ -194,10 +197,12 @@ export function toView(state: GameState, content: GameContent): GameView {
|
||||
groupOrder.push(a.group.id);
|
||||
groupMap.set(a.group.id, { id: a.group.id, label: a.group.label, actions: [] });
|
||||
}
|
||||
groupMap.get(a.group.id)!.actions.push(view);
|
||||
groupMap.get(a.group.id)?.actions.push(view);
|
||||
}
|
||||
|
||||
const groups: ActionGroupView[] = groupOrder.map((gid) => groupMap.get(gid)!);
|
||||
const groups: ActionGroupView[] = groupOrder
|
||||
.map((gid) => groupMap.get(gid))
|
||||
.filter((g): g is ActionGroupView => g !== undefined);
|
||||
|
||||
return {
|
||||
kind,
|
||||
|
||||
Reference in New Issue
Block a user