Skip to content
276 linesCodeBlameRaw
1/**
2 * The site's footer: a few links worth having, who makes g1t, and a row of
3 * the trust pages with the live status dot, the account, and the legal
4 * line. Marketing and signed-out pages show it; the app's account menu
5 * has its own rows (components/shell.tsx).
6 */
7import { useEffect, useState } from "react";
8import { Link } from "react-router";
9
10import type { User } from "@g1t/contracts";
11
12import { useAsksFirst } from "./analytics-consent";
13import { Mark } from "./logo";
14import { choose } from "../lib/analytics-consent";
15import { COMPANY, MAKER_PRODUCTS, SOCIAL, copyright, listed } from "../lib/legal";
16import { type OverallState, STATUS_JSON_URL, STATUS_URL, STATUS_WORDS, type StatusReport, dotClass } from "../lib/status";
17
18/** How long one fetched report is reused across the pages of one visit. */
19const STATUS_REUSE_MS = 60_000;
20let lastStatus: { report: StatusReport; at: number } | null = null;
21let pendingStatus: Promise<StatusReport | null> | null = null;
22
23function fetchStatus(): Promise<StatusReport | null> {
24 if (lastStatus && Date.now() - lastStatus.at < STATUS_REUSE_MS) return Promise.resolve(lastStatus.report);
25 pendingStatus ??= fetch(STATUS_JSON_URL, { headers: { accept: "application/json" } })
26 .then((response) => (response.ok ? (response.json() as Promise<StatusReport>) : null))
27 .then((report) => {
28 if (report?.overall) lastStatus = { report, at: Date.now() };
29 return report?.overall ? report : null;
30 })
31 // The status page being unreachable only means no dot.
32 .catch(() => null)
33 .finally(() => {
34 pendingStatus = null;
35 });
36 return pendingStatus;
37}
38
39/**
40 * The live status, from status.g1t.sh once the page is up (or `when` turns
41 * true), so no page waits on it. Kept a minute across pages. Null until it
42 * arrives, or if it cannot.
43 */
44export function useSiteStatus(when = true): StatusReport | null {
45 const [report, setReport] = useState<StatusReport | null>(() => lastStatus?.report ?? null);
46 useEffect(() => {
47 if (!when) return;
48 let live = true;
49 fetchStatus().then((fresh) => {
50 if (live && fresh) setReport(fresh);
51 });
52 return () => {
53 live = false;
54 };
55 }, [when]);
56 return report;
57}
58
59/** The coloured dot, with words for screen readers. */
60export function StatusDot({ state, className = "" }: { state: OverallState | null; className?: string }) {
61 return (
62 <span className={`relative inline-flex size-2 shrink-0 ${className}`}>
63 {state && state !== "up" && state !== "unknown" && (
64 <span aria-hidden className={`absolute inset-0 animate-ping rounded-full opacity-60 ${dotClass(state)}`} />
65 )}
66 <span aria-hidden className={`relative inline-flex size-2 rounded-full ${dotClass(state)}`} />
67 <span className="sr-only">{state ? STATUS_WORDS[state] : "Checking status"}</span>
68 </span>
69 );
70}
71
72/** Where the footer's grid links go. Plain links: some are files or other hosts. */
73const FOOTER_LINKS: { title: string; links: [string, string][] }[] = [
74 {
75 title: "Product",
76 links: [
77 ["Explore", "/explore"],
78 ["Pricing", "/pricing"],
79 ["Download", "/download"],
80 ["Chat", "https://docs.g1t.sh/guides/chat/"],
81 ["Agents", "https://docs.g1t.sh/guides/agents/"],
82 ["Working with g1t", "https://docs.g1t.sh/guides/working-with-g1t/"],
83 ["Bring your own agent", "https://docs.g1t.sh/guides/bring-your-own-agent/"],
84 ["Integrations", "https://docs.g1t.sh/guides/integrations/"],
85 ],
86 },
87 {
88 title: "Developers",
89 links: [
90 ["Documentation", "https://docs.g1t.sh/"],
91 ["API reference", "https://docs.g1t.sh/reference/api/"],
92 ["MCP tools", "https://docs.g1t.sh/reference/mcp/"],
93 ["llms.txt", "/llms.txt"],
94 ],
95 },
96 {
97 title: "Company",
98 links: [
99 ["Flagon, Inc.", COMPANY.url],
100 ...SOCIAL.map((account): [string, string] => [account.label, account.url]),
101 ["Support", "/support"],
102 ["Security", "/security"],
103 ["Status", STATUS_URL],
104 ],
105 },
106 {
107 title: "Open source",
108 links: [
109 ["Source on g1t", "/flagon-io/g1t"],
110 ["MIT license", "/flagon-io/g1t/blob/main/LICENSE"],
111 ["Run g1t yourself", "https://docs.g1t.sh/guides/self-hosting/"],
112 ],
113 },
114];
115
116/** The row's own links, after Status. */
117const ROW_LINKS: [string, string][] = [
118 ["Support", "/support"],
119 ["Policies", "/policies"],
120 ["Privacy", "/policies/privacy"],
121 ["Security", "/security"],
122];
123
124/**
125 * Flagon's mark, single-ink, as in Flagon's brand files
126 * (flagon-mark-mono.svg): a flagon, its brew a tone of the text colour.
127 */
128function FlagonMark({ className = "" }: { className?: string }) {
129 return (
130 <svg viewBox="11.3 12.3 41 41" fill="none" aria-hidden="true" className={className}>
131 <defs>
132 <clipPath id="g1t-footer-flagon-body">
133 <path d="M19.5 23 L34.5 23 L36.5 46 Q36.7 48 34.3 48 L19.7 48 Q17.3 48 17.5 46 Z" />
134 </clipPath>
135 </defs>
136 <g clipPath="url(#g1t-footer-flagon-body)">
137 <path
138 d="M13 27 q3.75 -0.7 7.5 0 t7.5 0 t7.5 0 t7.5 0 t7.5 0 L51 52 L13 52 Z"
139 fill="currentColor"
140 fillOpacity="0.22"
141 />
142 </g>
143 <path
144 d="M37 27 L45.5 27 L48.5 30 L48.5 36.5 L45.5 39.5 L38 39.5"
145 stroke="currentColor"
146 strokeWidth="3.1"
147 strokeLinecap="round"
148 strokeLinejoin="round"
149 />
150 <path
151 d="M17.5 21 L36.5 21 L38.6 47 Q39 50 36 50 L18 50 Q15 50 15.4 47 Z"
152 stroke="currentColor"
153 strokeWidth="3.1"
154 strokeLinejoin="round"
155 />
156 <path d="M17 21 Q16.3 16.3 20 15.6 L33 15.6 Q37.2 16.2 37 21 Z" stroke="currentColor" strokeWidth="3" strokeLinejoin="round" />
157 <path d="M36.7 17.1 L39.4 16.1" stroke="currentColor" strokeWidth="2.4" strokeLinejoin="round" />
158 <circle cx="40.3" cy="15.8" r="1.4" fill="currentColor" />
159 </svg>
160 );
161}
162
163/** "g1t is designed, built, and backed by Flagon, Inc., …" */
164export function MakerLine() {
165 const products = MAKER_PRODUCTS.map((product) => product.name);
166 return (
167 <p className="text-sm leading-6 text-muted text-balance">
168 <Mark tight className="mr-1.5 inline-block h-[0.85em] w-auto align-baseline" />
169 <span className="font-semibold text-fg">g1t</span> is designed, built, and backed by{" "}
170 <a href={COMPANY.url} className="whitespace-nowrap font-semibold text-fg hover:underline hover:underline-offset-4">
171 <FlagonMark className="mr-1 inline-block size-[0.95em] -translate-y-px align-middle" />
172 {COMPANY.name}
173 </a>
174 {products.length > 0 ? `, the people behind ${listed(products)}.` : `, ${COMPANY.about} founded by ${COMPANY.founder}.`}
175 </p>
176 );
177}
178
179const ROW_LINK = "rounded-sm transition-colors hover:text-fg";
180
181/**
182 * Status, the trust pages, the account and the legal line, separated by
183 * dots that wrap away cleanly on a phone.
184 */
185export function LegalRow({ user }: { user: User | null | undefined }) {
186 const status = useSiteStatus();
187 const asksFirst = useAsksFirst();
188 const links = [
189 <a key="status" href={STATUS_URL} className={`inline-flex items-center gap-1.5 ${ROW_LINK}`}>
190 <StatusDot state={status?.overall.state ?? null} />
191 Status
192 </a>,
193 ...ROW_LINKS.map(([label, to]) => (
194 <Link key={to} to={to} className={ROW_LINK}>
195 {label}
196 </Link>
197 )),
198 // Where the visitor was asked about the analytics cookie: ask again.
199 ...(asksFirst
200 ? [
201 <button key="consent" type="button" onClick={() => choose(null)} className={ROW_LINK}>
202 Cookie choices
203 </button>,
204 ]
205 : []),
206 ];
207 const account = [
208 user ? (
209 <Link key="me" to={`/u/${user.username}`} className={`font-medium text-fg/90 ${ROW_LINK}`}>
210 {user.username}
211 </Link>
212 ) : (
213 <Link key="login" to="/login" className={ROW_LINK}>
214 Sign in
215 </Link>
216 ),
217 ];
218 const legal = [
219 ...account,
220 <span key="copyright" className="text-faint">
221 {copyright()}
222 </span>,
223 ];
224 const gap = "gap-x-3";
225 const dot = (
226 <span aria-hidden className="text-line-strong">
227 ·
228 </span>
229 );
230 // Two runs, the links and the legal line, so that on a narrow screen the
231 // second starts its own line rather than a line starting with a dot.
232 const run = (items: React.ReactNode[]) =>
233 items.map((item, index) => (
234 <li key={index} className={`flex items-center ${gap}`}>
235 {index > 0 && dot}
236 {item}
237 </li>
238 ));
239 return (
240 <div className={`flex flex-wrap items-center justify-center gap-y-1.5 ${gap} text-[0.8125rem] text-muted`}>
241 <ul className={`flex flex-wrap items-center justify-center gap-y-1.5 ${gap}`}>{run(links)}</ul>
242 {/* Between the two runs only while they share a line. */}
243 <span className="hidden md:inline">{dot}</span>
244 <ul className={`flex flex-wrap items-center justify-center gap-y-1.5 ${gap}`}>{run(legal)}</ul>
245 </div>
246 );
247}
248
249export function SiteFooter({ user }: { user: User | null | undefined }) {
250 return (
251 <footer className="mt-24 border-t border-line">
252 <nav aria-label="Footer" className="mx-auto grid max-w-6xl grid-cols-2 gap-x-8 gap-y-8 px-4 pt-12 pb-10 sm:grid-cols-4">
253 {FOOTER_LINKS.map((group) => (
254 <div key={group.title}>
255 <p className="text-sm font-medium">{group.title}</p>
256 <ul className="mt-3 space-y-2 text-sm text-muted">
257 {group.links.map(([label, to]) => (
258 <li key={to}>
259 <a href={to} className="transition-colors hover:text-fg">
260 {label}
261 </a>
262 </li>
263 ))}
264 </ul>
265 </div>
266 ))}
267 </nav>
268 <div className="border-t border-line">
269 <div className="mx-auto max-w-3xl space-y-4 px-4 py-10 text-center">
270 <MakerLine />
271 <LegalRow user={user} />
272 </div>
273 </div>
274 </footer>
275 );
276}