|
| 1 | +import { RGBA, TextAttributes } from "@opentui/core" |
| 2 | +import { useKeyboard } from "@opentui/solid" |
| 3 | +import open from "open" |
| 4 | +import { createSignal } from "solid-js" |
| 5 | +import { selectedForeground, useTheme } from "@tui/context/theme" |
| 6 | +import { useDialog, type DialogContext } from "@tui/ui/dialog" |
| 7 | +import { Link } from "@tui/ui/link" |
| 8 | + |
| 9 | +const GO_URL = "https://opencode.ai/go" |
| 10 | + |
| 11 | +export type DialogGoUpsellProps = { |
| 12 | + onClose?: (dontShowAgain?: boolean) => void |
| 13 | +} |
| 14 | + |
| 15 | +function subscribe(props: DialogGoUpsellProps, dialog: ReturnType<typeof useDialog>) { |
| 16 | + open(GO_URL).catch(() => {}) |
| 17 | + props.onClose?.() |
| 18 | + dialog.clear() |
| 19 | +} |
| 20 | + |
| 21 | +function dismiss(props: DialogGoUpsellProps, dialog: ReturnType<typeof useDialog>) { |
| 22 | + props.onClose?.(true) |
| 23 | + dialog.clear() |
| 24 | +} |
| 25 | + |
| 26 | +export function DialogGoUpsell(props: DialogGoUpsellProps) { |
| 27 | + const dialog = useDialog() |
| 28 | + const { theme } = useTheme() |
| 29 | + const fg = selectedForeground(theme) |
| 30 | + const [selected, setSelected] = createSignal(0) |
| 31 | + |
| 32 | + useKeyboard((evt) => { |
| 33 | + if (evt.name === "left" || evt.name === "right" || evt.name === "tab") { |
| 34 | + setSelected((s) => (s === 0 ? 1 : 0)) |
| 35 | + return |
| 36 | + } |
| 37 | + if (evt.name !== "return") return |
| 38 | + if (selected() === 0) subscribe(props, dialog) |
| 39 | + else dismiss(props, dialog) |
| 40 | + }) |
| 41 | + |
| 42 | + return ( |
| 43 | + <box paddingLeft={2} paddingRight={2} gap={1}> |
| 44 | + <box flexDirection="row" justifyContent="space-between"> |
| 45 | + <text attributes={TextAttributes.BOLD} fg={theme.text}> |
| 46 | + Free limit reached |
| 47 | + </text> |
| 48 | + <text fg={theme.textMuted} onMouseUp={() => dialog.clear()}> |
| 49 | + esc |
| 50 | + </text> |
| 51 | + </box> |
| 52 | + <box gap={1} paddingBottom={1}> |
| 53 | + <text fg={theme.textMuted}> |
| 54 | + Subscribe to OpenCode Go to keep going with reliable access to the best open-source models, starting at |
| 55 | + $5/month. |
| 56 | + </text> |
| 57 | + <box flexDirection="row" gap={1}> |
| 58 | + <Link href={GO_URL} fg={theme.primary} /> |
| 59 | + </box> |
| 60 | + </box> |
| 61 | + <box flexDirection="row" justifyContent="flex-end" gap={1} paddingBottom={1}> |
| 62 | + <box |
| 63 | + paddingLeft={3} |
| 64 | + paddingRight={3} |
| 65 | + backgroundColor={selected() === 0 ? theme.primary : RGBA.fromInts(0, 0, 0, 0)} |
| 66 | + onMouseOver={() => setSelected(0)} |
| 67 | + onMouseUp={() => subscribe(props, dialog)} |
| 68 | + > |
| 69 | + <text fg={selected() === 0 ? fg : theme.text} attributes={selected() === 0 ? TextAttributes.BOLD : undefined}> |
| 70 | + subscribe |
| 71 | + </text> |
| 72 | + </box> |
| 73 | + <box |
| 74 | + paddingLeft={3} |
| 75 | + paddingRight={3} |
| 76 | + backgroundColor={selected() === 1 ? theme.primary : RGBA.fromInts(0, 0, 0, 0)} |
| 77 | + onMouseOver={() => setSelected(1)} |
| 78 | + onMouseUp={() => dismiss(props, dialog)} |
| 79 | + > |
| 80 | + <text |
| 81 | + fg={selected() === 1 ? fg : theme.textMuted} |
| 82 | + attributes={selected() === 1 ? TextAttributes.BOLD : undefined} |
| 83 | + > |
| 84 | + don't show again |
| 85 | + </text> |
| 86 | + </box> |
| 87 | + </box> |
| 88 | + </box> |
| 89 | + ) |
| 90 | +} |
| 91 | + |
| 92 | +DialogGoUpsell.show = (dialog: DialogContext) => { |
| 93 | + return new Promise<boolean>((resolve) => { |
| 94 | + dialog.replace( |
| 95 | + () => <DialogGoUpsell onClose={(dontShow) => resolve(dontShow ?? false)} />, |
| 96 | + () => resolve(false), |
| 97 | + ) |
| 98 | + }) |
| 99 | +} |
0 commit comments