Files
Dune/lib/actionable-notices.ts
T
Quintine bd8377d87b
Verify and publish checkpoint container / container (push) Successful in 11m42s
Support current battle choice promises and persistent notices
2026-11-16 21:49:48 +11:00

21 lines
1.0 KiB
TypeScript

/** Local presentation state for messages which need a player's acknowledgement. */
export type ActionableNotice = { id: number; text: string };
export type ActionableNoticeQueue = { nextId: number; items: ActionableNotice[] };
export type ActionableNoticeUpdate =
| { type: 'enqueue'; text: string }
| { type: 'dismiss'; id: number };
export const initialActionableNotices: ActionableNoticeQueue = { nextId: 1, items: [] };
/** Repeated identical messages coalesce while pending; a stale button cannot
* dismiss a later message, including another occurrence of the same text. */
export function updateActionableNotices(
state: ActionableNoticeQueue,
update: ActionableNoticeUpdate,
): ActionableNoticeQueue {
if (update.type === 'dismiss') return state.items[0]?.id === update.id
? { ...state, items: state.items.slice(1) } : state;
if (!update.text || state.items.some(item => item.text === update.text)) return state;
return { nextId: state.nextId + 1, items: [...state.items, { id: state.nextId, text: update.text }] };
}