Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

composerSendPresentation.ts

56 lines1.7 KB

1import {
2 alternateComposerDispatchAction,
3 type ActiveTurnComposerAction,
4} from "@t3tools/client-runtime/state/composer-dispatch";
5​
6import type { FollowUpBehavior } from "../../lib/followUpBehavior";
7​
8export interface ComposerSendPresentation {
9 readonly label: string;
10 readonly icon: "arrow.up" | "checkmark" | "list.number" | "arrow.turn.left.up";
11 readonly action: ActiveTurnComposerAction | null;
12 readonly alternate: ActiveTurnComposerAction | null;
13 readonly offersFollowUpChoice: boolean;
15​
16const ACTION_LABEL: Record<ActiveTurnComposerAction, string> = {
17 queue: "Queue",
18 steer: "Steer",
19 restart: "Restart",
20};
21​
22export function resolveComposerSendPresentation(input: {
23 readonly editingQueuedMessage: boolean;
24 readonly running: boolean;
25 readonly canSteer: boolean;
26 readonly followUpBehavior: FollowUpBehavior;
27 readonly deliveryDeferred: boolean;
28}): ComposerSendPresentation {
29 if (input.editingQueuedMessage) {
30 return {
31 label: "Update queued message",
32 icon: "checkmark",
33 action: null,
34 alternate: null,
35 offersFollowUpChoice: false,
36 };
37 }
38 if (!input.running) {
39 return {
40 label: input.deliveryDeferred ? "Queue" : "Send",
41 icon: "arrow.up",
42 action: null,
43 alternate: null,
44 offersFollowUpChoice: false,
45 };
46 }
47 const action: ActiveTurnComposerAction = input.canSteer ? input.followUpBehavior : "queue";
48 const alternate = alternateComposerDispatchAction(action);
49 return {
50 label: ACTION_LABEL[action],
51 icon: action === "steer" ? "arrow.turn.left.up" : "list.number",
52 action,
53 alternate: input.canSteer ? alternate : null,
54 offersFollowUpChoice: input.canSteer,
55 };