@@ -8,44 +8,50 @@ import { GoLogo } from "./logo" |
8 | 8 | import { BgPulse, type BgPulseMask } from "./bg-pulse" |
9 | 9 | import { useBindings } from "../keymap" |
10 | 10 |
|
11 | | -const GO_URL = "https://opencode.ai/go" |
12 | 11 | const PAD_X = 3 |
13 | 12 | const PAD_TOP_OUTER = 1 |
14 | 13 |
|
15 | | -export type DialogGoUpsellProps = { |
| 14 | +export type DialogRetryActionProps = { |
| 15 | + title: string |
| 16 | + message: string |
| 17 | + label: string |
| 18 | + link?: string |
16 | 19 | onClose?: (dontShowAgain?: boolean) => void |
17 | 20 | } |
18 | 21 |
|
19 | | -function subscribe(props: DialogGoUpsellProps, dialog: ReturnType<typeof useDialog>) { |
20 | | - open(GO_URL).catch(() => {}) |
| 22 | +function runAction(props: DialogRetryActionProps, dialog: ReturnType<typeof useDialog>) { |
| 23 | + if (props.link) open(props.link).catch(() => {}) |
21 | 24 | props.onClose?.() |
22 | 25 | dialog.clear() |
23 | 26 | } |
24 | 27 |
|
25 | | -function dismiss(props: DialogGoUpsellProps, dialog: ReturnType<typeof useDialog>) { |
| 28 | +function dismiss(props: DialogRetryActionProps, dialog: ReturnType<typeof useDialog>) { |
26 | 29 | props.onClose?.(true) |
27 | 30 | dialog.clear() |
28 | 31 | } |
29 | 32 |
|
30 | | -export function DialogGoUpsell(props: DialogGoUpsellProps) { |
| 33 | +export function DialogRetryAction(props: DialogRetryActionProps) { |
31 | 34 | const dialog = useDialog() |
32 | 35 | const { theme } = useTheme() |
33 | 36 | const fg = selectedForeground(theme) |
34 | | - const [selected, setSelected] = createSignal<"dismiss" | "subscribe">("subscribe") |
| 37 | + const [selected, setSelected] = createSignal<"dismiss" | "action">("action") |
35 | 38 | const [center, setCenter] = createSignal<{ x: number; y: number } | undefined>() |
36 | 39 | const [masks, setMasks] = createSignal<BgPulseMask[]>([]) |
| 40 | + const showGoTreatment = () => props.link === "https://opencode.ai/go" |
37 | 41 | let content: BoxRenderable | undefined |
38 | 42 | let logoBox: BoxRenderable | undefined |
39 | 43 | let headingBox: BoxRenderable | undefined |
40 | 44 | let descBox: BoxRenderable | undefined |
41 | 45 | let buttonsBox: BoxRenderable | undefined |
42 | 46 |
|
43 | 47 | const sync = () => { |
44 | | - if (!content || !logoBox) return |
45 | | - setCenter({ |
46 | | - x: logoBox.x - content.x + logoBox.width / 2, |
47 | | - y: logoBox.y - content.y + logoBox.height / 2 + PAD_TOP_OUTER, |
48 | | - }) |
| 48 | + if (!content) return |
| 49 | + if (logoBox) { |
| 50 | + setCenter({ |
| 51 | + x: logoBox.x - content.x + logoBox.width / 2, |
| 52 | + y: logoBox.y - content.y + logoBox.height / 2 + PAD_TOP_OUTER, |
| 53 | + }) |
| 54 | + } |
49 | 55 | const next: BgPulseMask[] = [] |
50 | 56 | const baseY = PAD_TOP_OUTER |
51 | 57 | for (const b of [headingBox, descBox, buttonsBox]) { |
@@ -75,20 +81,20 @@ export function DialogGoUpsell(props: DialogGoUpsellProps) { |
75 | 81 | bindings: [ |
76 | 82 | { |
77 | 83 | key: "left", |
78 | | - cmd: () => setSelected((value) => (value === "subscribe" ? "dismiss" : "subscribe")), |
| 84 | + cmd: () => setSelected((value) => (value === "action" ? "dismiss" : "action")), |
79 | 85 | }, |
80 | 86 | { |
81 | 87 | key: "right", |
82 | | - cmd: () => setSelected((value) => (value === "subscribe" ? "dismiss" : "subscribe")), |
| 88 | + cmd: () => setSelected((value) => (value === "action" ? "dismiss" : "action")), |
83 | 89 | }, |
84 | 90 | { |
85 | 91 | key: "tab", |
86 | | - cmd: () => setSelected((value) => (value === "subscribe" ? "dismiss" : "subscribe")), |
| 92 | + cmd: () => setSelected((value) => (value === "action" ? "dismiss" : "action")), |
87 | 93 | }, |
88 | 94 | { |
89 | 95 | key: "return", |
90 | 96 | cmd: () => { |
91 | | - if (selected() === "subscribe") subscribe(props, dialog) |
| 97 | + if (selected() === "action") runAction(props, dialog) |
92 | 98 | else dismiss(props, dialog) |
93 | 99 | }, |
94 | 100 | }, |
@@ -97,33 +103,34 @@ export function DialogGoUpsell(props: DialogGoUpsellProps) { |
97 | 103 |
|
98 | 104 | return ( |
99 | 105 | <box ref={(item: BoxRenderable) => (content = item)}> |
100 | | - <box position="absolute" top={-PAD_TOP_OUTER} left={0} right={0} bottom={0} zIndex={0}> |
101 | | - <BgPulse centerX={center()?.x} centerY={center()?.y} masks={masks()} /> |
102 | | - </box> |
103 | | - <box paddingLeft={PAD_X} paddingRight={PAD_X} paddingBottom={1} gap={1}> |
| 106 | + {showGoTreatment() ? ( |
| 107 | + <box position="absolute" top={-PAD_TOP_OUTER} left={0} right={0} bottom={0} zIndex={0}> |
| 108 | + <BgPulse centerX={center()?.x} centerY={center()?.y} masks={masks()} /> |
| 109 | + </box> |
| 110 | + ) : null} |
| 111 | + <box paddingLeft={PAD_X} paddingRight={PAD_X} paddingBottom={1} gap={1} zIndex={1}> |
104 | 112 | <box ref={(item: BoxRenderable) => (headingBox = item)} flexDirection="row" justifyContent="space-between"> |
105 | 113 | <text attributes={TextAttributes.BOLD} fg={theme.text}> |
106 | | - Free limit reached |
| 114 | + {props.title} |
107 | 115 | </text> |
108 | 116 | <text fg={theme.textMuted} onMouseUp={() => dialog.clear()}> |
109 | 117 | esc |
110 | 118 | </text> |
111 | 119 | </box> |
112 | 120 | <box ref={(item: BoxRenderable) => (descBox = item)} gap={0}> |
113 | | - <box flexDirection="row"> |
114 | | - <text fg={theme.textMuted}>Subscribe to </text> |
115 | | - <text attributes={TextAttributes.BOLD} fg={theme.textMuted}> |
116 | | - OpenCode Go |
117 | | - </text> |
118 | | - <text fg={theme.textMuted}> for reliable access to the</text> |
119 | | - </box> |
120 | | - <text fg={theme.textMuted}>best open-source models, starting at $5/month.</text> |
| 121 | + <text fg={theme.textMuted}>{props.message}</text> |
121 | 122 | </box> |
122 | | - <box alignItems="center" gap={1} paddingBottom={1}> |
123 | | - <box ref={(item: BoxRenderable) => (logoBox = item)}> |
124 | | - <GoLogo /> |
125 | | - </box> |
126 | | - <Link href={GO_URL} fg={theme.primary} /> |
| 123 | + <box gap={1} paddingBottom={1}> |
| 124 | + {showGoTreatment() ? ( |
| 125 | + <box ref={(item: BoxRenderable) => (logoBox = item)} alignItems="center"> |
| 126 | + <GoLogo /> |
| 127 | + </box> |
| 128 | + ) : null} |
| 129 | + {props.link ? ( |
| 130 | + <box width="100%" flexDirection="row" justifyContent="center"> |
| 131 | + <Link href={props.link} fg={theme.primary} wrapMode="none" /> |
| 132 | + </box> |
| 133 | + ) : null} |
127 | 134 | </box> |
128 | 135 | <box ref={(item: BoxRenderable) => (buttonsBox = item)} flexDirection="row" justifyContent="space-between"> |
129 | 136 | <box |
@@ -143,15 +150,15 @@ export function DialogGoUpsell(props: DialogGoUpsellProps) { |
143 | 150 | <box |
144 | 151 | paddingLeft={2} |
145 | 152 | paddingRight={2} |
146 | | - backgroundColor={selected() === "subscribe" ? theme.primary : RGBA.fromInts(0, 0, 0, 0)} |
147 | | - onMouseOver={() => setSelected("subscribe")} |
148 | | - onMouseUp={() => subscribe(props, dialog)} |
| 153 | + backgroundColor={selected() === "action" ? theme.primary : RGBA.fromInts(0, 0, 0, 0)} |
| 154 | + onMouseOver={() => setSelected("action")} |
| 155 | + onMouseUp={() => runAction(props, dialog)} |
149 | 156 | > |
150 | 157 | <text |
151 | | - fg={selected() === "subscribe" ? fg : theme.text} |
152 | | - attributes={selected() === "subscribe" ? TextAttributes.BOLD : undefined} |
| 158 | + fg={selected() === "action" ? fg : theme.text} |
| 159 | + attributes={selected() === "action" ? TextAttributes.BOLD : undefined} |
153 | 160 | > |
154 | | - subscribe |
| 161 | + {props.label} |
155 | 162 | </text> |
156 | 163 | </box> |
157 | 164 | </box> |
@@ -160,10 +167,13 @@ export function DialogGoUpsell(props: DialogGoUpsellProps) { |
160 | 167 | ) |
161 | 168 | } |
162 | 169 |
|
163 | | -DialogGoUpsell.show = (dialog: DialogContext) => { |
| 170 | +DialogRetryAction.show = ( |
| 171 | + dialog: DialogContext, |
| 172 | + props: Pick<DialogRetryActionProps, "title" | "message" | "label" | "link">, |
| 173 | +) => { |
164 | 174 | return new Promise<boolean>((resolve) => { |
165 | 175 | dialog.replace( |
166 | | - () => <DialogGoUpsell onClose={(dontShow) => resolve(dontShow ?? false)} />, |
| 176 | + () => <DialogRetryAction {...props} onClose={(dontShow) => resolve(dontShow ?? false)} />, |
167 | 177 | () => resolve(false), |
168 | 178 | ) |
169 | 179 | }) |
|