The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { T, useGT, useMessages, Var } from "gt-react"; |
| 2 | import { useState } from "react"; |
| 3 | |
| 4 | import { Button } from "~/components/ui/button"; |
| 5 | |
| 6 | import { describePreviewError } from "./errorCodeMessages"; |
| 7 | |
| 8 | interface Props { |
| 9 | url: string; |
| 10 | code: number; |
| 11 | description: string; |
| 12 | onReload: () => void; |
| 13 | move?: { readonly label: string; readonly onMove: () => void }; |
| 14 | } |
| 15 | |
| 16 | export function PreviewFileNotShown({ |
| 17 | url, |
| 18 | fileName, |
| 19 | downloadUrl, |
| 20 | onOpen, |
| 21 | }: { |
| 22 | url: string; |
| 23 | fileName: string; |
| 24 | downloadUrl: string | null; |
| 25 | onOpen: () => void; |
| 26 | }) { |
| 27 | const host = safeHost(url) ?? url; |
| 28 | return ( |
| 29 | <div className="scrollbar-gutter-both relative flex h-full min-h-0 w-full overflow-y-auto bg-background"> |
| 30 | <div className="mx-auto flex w-full max-w-xl flex-1 flex-col px-8 py-12 sm:py-16"> |
| 31 | <ErrorIcon className="mb-6 size-12 text-muted-foreground/70" /> |
| 32 | <h1 className="mb-3 text-2xl font-semibold leading-tight text-foreground"> |
| 33 | <T>This file can’t be shown here</T> |
| 34 | </h1> |
| 35 | <p className="text-sm leading-relaxed text-muted-foreground"> |
| 36 | <T> |
| 37 | <span className="font-semibold text-foreground"> |
| 38 | <Var>{fileName}</Var> |
| 39 | </span>{" "} |
| 40 | from <Var>{host}</Var> was downloaded instead. |
| 41 | </T> |
| 42 | </p> |
| 43 | <div className="mt-auto flex items-center gap-2 pt-8"> |
| 44 | <div className="flex-1" /> |
| 45 | <Button type="button" variant="outline" size="sm" onClick={onOpen}> |
| 46 | <T>Open in browser</T> |
| 47 | </Button> |
| 48 | {downloadUrl ? ( |
| 49 | <Button type="button" size="sm" render={<a href={downloadUrl} download={fileName} />}> |
| 50 | <T context="verb">Download</T> |
| 51 | </Button> |
| 52 | ) : null} |
| 53 | </div> |
| 54 | </div> |
| 55 | </div> |
| 56 | ); |
| 57 | } |
| 58 | |
| 59 | export function PreviewUnreachable({ url, code, description, onReload, move }: Props) { |
| 60 | const gt = useGT(); |
| 61 | const m = useMessages(); |
| 62 | const [showDetails, setShowDetails] = useState(false); |
| 63 | const host = safeHost(url) ?? url; |
| 64 | const friendly = describePreviewError(description, m); |
| 65 | const errorLabel = description.length > 0 ? description : `ERR_${Math.abs(code) || "FAILED"}`; |
| 66 | |
| 67 | return ( |
| 68 | <div className="scrollbar-gutter-both relative flex h-full min-h-0 w-full overflow-y-auto bg-background"> |
| 69 | <div className="mx-auto flex w-full max-w-xl flex-1 flex-col px-8 py-12 sm:py-16"> |
| 70 | <ErrorIcon className="mb-6 size-12 text-muted-foreground/70" /> |
| 71 | <h1 className="mb-3 text-2xl font-semibold leading-tight text-foreground"> |
| 72 | <T>This site can’t be reached</T> |
| 73 | </h1> |
| 74 | <p className="text-sm leading-relaxed text-muted-foreground"> |
| 75 | <T> |
| 76 | <span className="font-semibold text-foreground"> |
| 77 | <Var>{host}</Var> |
| 78 | </span> |
| 79 | : <Var>{friendly}</Var>. |
| 80 | </T> |
| 81 | </p> |
| 82 | |
| 83 | {showDetails ? ( |
| 84 | <div className="mt-6 rounded-lg border border-border bg-muted/40 p-4 text-sm"> |
| 85 | <p className="mb-2 font-medium text-foreground"> |
| 86 | <T>Try:</T> |
| 87 | </p> |
| 88 | <ul className="list-disc space-y-1 pl-5 text-muted-foreground"> |
| 89 | <li> |
| 90 | <T>Checking your connection</T> |
| 91 | </li> |
| 92 | <li> |
| 93 | <T>Confirming the dev server is running</T> |
| 94 | </li> |
| 95 | {move ? ( |
| 96 | <li> |
| 97 | <T>Opening it in the environment’s browser, which reaches its network</T> |
| 98 | </li> |
| 99 | ) : null} |
| 100 | <li> |
| 101 | <T>Checking the proxy and the firewall</T> |
| 102 | </li> |
| 103 | </ul> |
| 104 | </div> |
| 105 | ) : null} |
| 106 | |
| 107 | <div className="mt-8 text-xs uppercase tracking-wide text-muted-foreground/70"> |
| 108 | {errorLabel} |
| 109 | </div> |
| 110 | |
| 111 | <div className="mt-auto flex items-center gap-2 pt-8"> |
| 112 | <Button |
| 113 | type="button" |
| 114 | variant="outline" |
| 115 | size="sm" |
| 116 | onClick={() => setShowDetails((value) => !value)} |
| 117 | > |
| 118 | {showDetails ? gt("Hide details") : gt("Details")} |
| 119 | </Button> |
| 120 | <div className="flex-1" /> |
| 121 | {move ? ( |
| 122 | <Button type="button" variant="outline" size="sm" onClick={move.onMove}> |
| 123 | {move.label} |
| 124 | </Button> |
| 125 | ) : null} |
| 126 | <Button type="button" size="sm" onClick={onReload}> |
| 127 | <T>Reload</T> |
| 128 | </Button> |
| 129 | </div> |
| 130 | </div> |
| 131 | </div> |
| 132 | ); |
| 133 | } |
| 134 | |
| 135 | function ErrorIcon({ className }: { className?: string }) { |
| 136 | return ( |
| 137 | <svg |
| 138 | viewBox="0 0 64 64" |
| 139 | fill="none" |
| 140 | stroke="currentColor" |
| 141 | strokeWidth="2.5" |
| 142 | className={className} |
| 143 | > |
| 144 | <path d="M16 12 L48 12 L48 52 L16 52 Z" /> |
| 145 | <path d="M22 22 L42 22 M22 30 L36 30 M22 38 L40 38" strokeLinecap="round" /> |
| 146 | <path d="M52 8 L12 56" strokeLinecap="round" /> |
| 147 | </svg> |
| 148 | ); |
| 149 | } |
| 150 | |
| 151 | function safeHost(url: string): string | null { |
| 152 | try { |
| 153 | return new URL(url).host; |
| 154 | } catch { |
| 155 | return null; |
| 156 | } |
| 157 | } |