summaryrefslogtreecommitdiff
path: root/apps/web/src/components/header.tsx
blob: a52ca4c7ec20209ccb8eb4f24b00e5c7bd1ef5da (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"use client";

import Link from "next/link";
import { Button } from "./ui/button";
import { ArrowRight } from "lucide-react";
import { HeaderBase } from "./header-base";
import { useSession } from "@opencut/auth/client";
import { getStars } from "@/lib/fetch-github-stars";
import { useEffect, useState } from "react";
import Image from "next/image";

export function Header() {
	const { data: session } = useSession();
	const [star, setStar] = useState<string>("");

	useEffect(() => {
		const fetchStars = async () => {
			try {
				const data = await getStars();
				setStar(data);
			} catch (err) {
				console.error("Failed to fetch GitHub stars", err);
			}
		};

		fetchStars();
	}, []);

	const leftContent = (
		<Link href="/" className="flex items-center gap-3">
			<Image src="/logo.svg" alt="OpenCut Logo" width={32} height={32} />
			<span className="text-xl font-medium hidden md:block">OpenCut</span>
		</Link>
	);

	const rightContent = (
		<nav className="flex items-center gap-3">
			<Link href="/contributors">
				<Button variant="text" className="text-sm p-0">
					Contributors
				</Button>
			</Link>
			{process.env.NODE_ENV === "development" ? (
				<Link href="/projects">
					<Button size="sm" className="text-sm ml-4">
						Projects
						<ArrowRight className="h-4 w-4" />
					</Button>
				</Link>
			) : (
				<Link href="https://github.com/OpenCut-app/OpenCut" target="_blank">
					<Button size="sm" className="text-sm ml-4">
						GitHub {star}+
						<ArrowRight className="h-4 w-4" />
					</Button>
				</Link>
			)}
		</nav>
	);

	return (
		<div className="mx-4 md:mx-0">
			<HeaderBase
				className="bg-accent border rounded-2xl max-w-3xl mx-auto mt-4 pl-4 pr-[14px]"
				leftContent={leftContent}
				rightContent={rightContent}
			/>
		</div>
	);
}