Skip to content

Commit ee15c82

Browse files
committed
allow users adding api key during normal app usage
1 parent 42c05c2 commit ee15c82

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

app/page.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const REPOS_PER_PAGE = 10
3131
export default function Home() {
3232
const [apiKey, setApiKey] = useState<string>("")
3333
const [noApiKey, setNoApiKey] = useState(false)
34+
const [showApiKeyForm, setShowApiKeyForm] = useState(false)
3435
const [collections, setCollections] = useState<Collection[]>([])
3536
const [selectedCollection, setSelectedCollection] = useState<Collection | null>(null)
3637
const [repositories, setRepositories] = useState<Repository[]>([])
@@ -526,6 +527,8 @@ export default function Home() {
526527
onExportCollection={() => setIsExportModalOpen(true)}
527528
onImportCollection={() => setIsImportModalOpen(true)}
528529
isLoading={isLoading}
530+
onAddApiKey={() => setShowApiKeyForm(true)}
531+
hasApiKey={!!apiKey}
529532
/>
530533

531534
<div className="container mx-auto px-4 py-8 flex-grow">
@@ -536,7 +539,10 @@ export default function Home() {
536539
<p className="text-gray-600 dark:text-gray-300 text-center">
537540
Add a GitHub API key for better rate limits and reliability, or continue without one.
538541
</p>
539-
<GitHubApiKeyForm onSubmit={handleApiKeySubmit} />
542+
<GitHubApiKeyForm onSubmit={(key) => {
543+
setApiKey(key)
544+
setShowApiKeyForm(false)
545+
}} />
540546
<div className="flex justify-center">
541547
<Button
542548
onClick={() => setNoApiKey(true)}
@@ -548,6 +554,25 @@ export default function Home() {
548554
</div>
549555
</div>
550556
</div>
557+
) : showApiKeyForm ? (
558+
<div className="max-w-md mx-auto">
559+
<div className="space-y-4">
560+
<div className="flex justify-between items-center">
561+
<h2 className="text-xl font-semibold text-gray-900 dark:text-white">Add GitHub API Key</h2>
562+
<Button
563+
variant="ghost"
564+
size="sm"
565+
onClick={() => setShowApiKeyForm(false)}
566+
>
567+
Cancel
568+
</Button>
569+
</div>
570+
<GitHubApiKeyForm onSubmit={(key) => {
571+
setApiKey(key)
572+
setShowApiKeyForm(false)
573+
}} />
574+
</div>
575+
</div>
551576
) : (
552577
<div className="space-y-6">
553578
{progressiveLoadingStatus && (

components/navbar.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ interface NavbarProps {
1616
onRefresh: () => void
1717
onExportCollection: () => void
1818
onImportCollection: () => void
19+
onAddApiKey: () => void
20+
hasApiKey: boolean
1921
isLoading: boolean
2022
}
2123

@@ -29,6 +31,8 @@ export function Navbar({
2931
onRefresh,
3032
onExportCollection,
3133
onImportCollection,
34+
onAddApiKey,
35+
hasApiKey,
3236
isLoading,
3337
}: NavbarProps) {
3438
return (
@@ -86,6 +90,18 @@ export function Navbar({
8690
Import
8791
</Button>
8892

93+
{!hasApiKey && (
94+
<Button
95+
variant="outline"
96+
size="sm"
97+
onClick={onAddApiKey}
98+
className="bg-white/10 text-white border-white/20 hover:bg-white/20 h-9"
99+
title="Add GitHub API Key"
100+
>
101+
Add API Key
102+
</Button>
103+
)}
104+
89105
<ThemeToggle />
90106
<Button
91107
onClick={onCreateCollection}

0 commit comments

Comments
 (0)