File
Blob: src/client/lib/affordance/action-state.ts
| 1 | export type UiActionState = { kind: "enabled" } | { kind: "disabled"; reason?: string } | { kind: "hidden" }; |
| 2 | |
| 3 | export const ENABLED_ACTION: UiActionState = { kind: "enabled" }; |
| 4 | export const HIDDEN_ACTION: UiActionState = { kind: "hidden" }; |
| 5 | export const OFFLINE_ACTION_REASON = "You're offline"; |
| 6 | export const ARCHIVE_OWNERSHIP_ACTION_REASON = "Only the page creator can archive this"; |
| 7 | |
| 8 | export function disabledAction(reason?: string): UiActionState { |
| 9 | return { kind: "disabled", reason }; |
| 10 | } |
| 11 | |
| 12 | export function isActionVisible(action: UiActionState): boolean { |
| 13 | return action.kind !== "hidden"; |
| 14 | } |
| 15 | |
| 16 | export function isActionEnabled(action: UiActionState): boolean { |
| 17 | return action.kind === "enabled"; |
| 18 | } |