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