| 1 | import type { Metadata } from "next"; |
| 2 | import { cookies, headers } from "next/headers"; |
| 3 | import Link from "next/link"; |
| 4 | import { listRepos } from "@/lib/grove-api"; |
| 5 | import { CollabLogo } from "@/app/components/collab-logo"; |
| 6 | import { CollabRepoList } from "./collab-repo-list"; |
| 7 | |
| 8 | export const metadata: Metadata = { |
| 9 | title: "Collab", |
| 10 | }; |
| 11 | |
| 12 | interface Repo { |
| 13 | name: string; |
| 14 | owner_name: string; |
| 15 | description: string | null; |
| 16 | last_commit_ts: number | null; |
| 17 | updated_at: string | null; |
| 18 | } |
| 19 | |
| 20 | async function getRepos(): Promise<Repo[]> { |
| 21 | const data = await listRepos<Repo>(); |
| 22 | return data?.repos ?? []; |
| 23 | } |
| 24 | |
| 25 | export default async function CollabHomePage() { |
| 26 | const cookieStore = await cookies(); |
| 27 | const token = cookieStore.get("grove_hub_token")?.value; |
| 28 | const signedIn = !!token; |
| 29 | const headerStore = await headers(); |
| 30 | const host = |
| 31 | headerStore.get("x-forwarded-host") ?? |
| 32 | headerStore.get("host") ?? |
| 33 | ""; |
| 34 | const protocol = headerStore.get("x-forwarded-proto") ?? "http"; |
| 35 | const canonicalHost = host.split(",")[0]?.trim() ?? ""; |
| 36 | const groveHost = canonicalHost.replace(/^(canopy|ring|collab)\./, ""); |
| 37 | const groveOrigin = groveHost ? `${protocol}://${groveHost}` : ""; |
| 38 | const loginHref = groveOrigin ? `${groveOrigin}/login` : "/login"; |
| 39 | const exploreHref = groveOrigin ? `${groveOrigin}/` : "/"; |
| 40 | |
| 41 | if (!signedIn) { |
| 42 | return ( |
| 43 | <div className="max-w-3xl mx-auto px-4 py-8"> |
| 44 | <div |
| 45 | className="p-4 sm:p-8 text-center" |
| 46 | style={{ |
| 47 | backgroundColor: "var(--bg-card)", |
| 48 | border: "1px solid var(--border-subtle)", |
| 49 | }} |
| 50 | > |
| 51 | <div className="mx-auto mb-4 w-fit opacity-70"> |
| 52 | <CollabLogo size={44} /> |
| 53 | </div> |
| 54 | <h1 className="text-lg mb-1">Collab</h1> |
| 55 | <p className="text-sm mb-4" style={{ color: "var(--text-faint)" }}> |
| 56 | Collaborate on Mermaid diagrams for your Grove repositories. |
| 57 | </p> |
| 58 | <div className="flex items-center justify-center gap-2"> |
| 59 | <Link |
| 60 | href={loginHref} |
| 61 | className="px-3 py-1.5 text-sm" |
| 62 | style={{ |
| 63 | backgroundColor: "var(--accent)", |
| 64 | color: "var(--accent-text)", |
| 65 | }} |
| 66 | > |
| 67 | Sign in |
| 68 | </Link> |
| 69 | <Link |
| 70 | href={exploreHref} |
| 71 | className="px-3 py-1.5 text-sm" |
| 72 | style={{ |
| 73 | border: "1px solid var(--border-subtle)", |
| 74 | color: "var(--text-secondary)", |
| 75 | }} |
| 76 | > |
| 77 | Explore Grove |
| 78 | </Link> |
| 79 | </div> |
| 80 | </div> |
| 81 | </div> |
| 82 | ); |
| 83 | } |
| 84 | |
| 85 | const repos = await getRepos(); |
| 86 | |
| 87 | return <CollabRepoList repos={repos} />; |
| 88 | } |
| 89 | |