-
-
Notifications
You must be signed in to change notification settings - Fork 583
/
Copy pathheader.tsx
108 lines (100 loc) · 3.96 KB
/
header.tsx
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
"use client";
import React, { useState, useEffect } from "react";
import Link from "next/link";
import { FaGithub } from "react-icons/fa";
import { getStarCount } from "~/app/_actions/github";
import { PrivateReposDialog } from "./private-repos-dialog";
import { ApiKeyDialog } from "./api-key-dialog";
export function Header() {
const [isPrivateReposDialogOpen, setIsPrivateReposDialogOpen] =
useState(false);
const [isApiKeyDialogOpen, setIsApiKeyDialogOpen] = useState(false);
const [starCount, setStarCount] = useState<number | null>(null);
useEffect(() => {
void getStarCount().then(setStarCount);
}, []);
const formatStarCount = (count: number | null) => {
if (!count) return "3.0k"; // Default to 2.0k if count is null (it can only go up from here)
if (count >= 1000) {
return `${(count / 1000).toFixed(1)}k`;
}
return count.toString();
};
const handlePrivateReposSubmit = (pat: string) => {
// Store the PAT in localStorage
localStorage.setItem("github_pat", pat);
setIsPrivateReposDialogOpen(false);
};
const handleApiKeySubmit = (apiKey: string) => {
localStorage.setItem("openai_key", apiKey);
setIsApiKeyDialogOpen(false);
};
return (
<header className="border-b-[3px] border-black">
<div className="mx-auto flex h-16 max-w-4xl items-center justify-between px-4 sm:px-8">
<Link href="/" className="flex items-center">
<span className="text-lg font-semibold sm:text-xl">
<span className="text-black transition-colors duration-200 hover:text-gray-600">
Git
</span>
<span className="text-purple-600 transition-colors duration-200 hover:text-purple-500">
Diagram
</span>
</span>
</Link>
<nav className="flex items-center gap-3 sm:gap-6">
<span
onClick={() => setIsApiKeyDialogOpen(true)}
onKeyDown={(e) => {
if (e.key === "Enter")
setIsApiKeyDialogOpen(true);
}}
className="cursor-pointer text-sm font-medium text-black transition-transform hover:translate-y-[-2px] hover:text-purple-600"
tabIndex={0}
>
<span className="flex items-center sm:hidden">
<span>API Key</span>
</span>
<span className="hidden items-center gap-1 sm:flex">
<span>API Key</span>
</span>
</span>
<span
onClick={() => setIsPrivateReposDialogOpen(true)}
onKeyDown={(e) => {
if (e.key === "Enter")
setIsPrivateReposDialogOpen(true);
}}
className="cursor-pointer text-sm font-medium text-black transition-transform hover:translate-y-[-2px] hover:text-purple-600"
tabIndex={0}
>
<span className="sm:hidden">Private Repos</span>
<span className="hidden sm:inline">Private Repos</span>
</span>
<Link
href="https://github.com/ahmedkhaleel2004/gitdiagram"
className="flex items-center gap-1 text-sm font-medium text-black transition-transform hover:translate-y-[-2px] hover:text-purple-600 sm:gap-2"
tabIndex={0}
>
<FaGithub className="h-5 w-5" aria-label="Github" role="img"/>
<span className="hidden sm:inline">GitHub</span>
</Link>
<span className="flex items-center gap-1 text-sm font-medium text-black">
<span className="text-amber-400">★</span>
{formatStarCount(starCount)}
</span>
</nav>
<PrivateReposDialog
isOpen={isPrivateReposDialogOpen}
onClose={() => setIsPrivateReposDialogOpen(false)}
onSubmit={handlePrivateReposSubmit}
/>
<ApiKeyDialog
isOpen={isApiKeyDialogOpen}
onClose={() => setIsApiKeyDialogOpen(false)}
onSubmit={handleApiKeySubmit}
/>
</div>
</header>
);
}