Skip to content

Commit 4e14ba9

Browse files
committed
Product Hunt navbar
1 parent 15c8ff8 commit 4e14ba9

1 file changed

Lines changed: 94 additions & 29 deletions

File tree

gitforme/src/components/gitformeUi.jsx

Lines changed: 94 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,50 @@ const LaptopIcon = () => (
1919
</svg>
2020
);
2121

22+
// --- Login Prompt Modal Component ---
23+
const LoginPromptModal = ({ onLogin, onClose }) => (
24+
<motion.div
25+
className="fixed inset-0 bg-black bg-opacity-60 flex items-center justify-center z-50 p-4"
26+
initial={{ opacity: 0 }}
27+
animate={{ opacity: 1 }}
28+
exit={{ opacity: 0 }}
29+
>
30+
<motion.div
31+
className="bg-white rounded-lg p-8 shadow-2xl text-center max-w-sm"
32+
initial={{ scale: 0.8, y: 20 }}
33+
animate={{ scale: 1, y: 0 }}
34+
exit={{ scale: 0.8, y: 20 }}
35+
>
36+
<h2 className="text-2xl font-bold mb-3 text-gray-800">Usage Limit Reached</h2>
37+
<p className="text-gray-600 mb-6">
38+
You've reached your free usage limit, or the public GitHub API rate limit was exceeded. Please log in to continue.
39+
</p>
40+
<button
41+
onClick={onLogin}
42+
className="w-full bg-gray-800 text-white font-bold py-3 px-4 rounded-lg hover:bg-gray-900 transition-colors duration-300"
43+
>
44+
Login with GitHub
45+
</button>
46+
<button
47+
onClick={onClose}
48+
className="mt-3 text-sm text-gray-500 hover:underline"
49+
>
50+
Close
51+
</button>
52+
</motion.div>
53+
</motion.div>
54+
);
55+
2256
const GitformeUi = () => {
2357
const { isAuthenticated, user, logout } = useAuth();
2458
const navigate = useNavigate();
2559
const { username, reponame } = useParams();
2660

2761
const [repoUrl, setRepoUrl] = useState('');
2862
const [isChatOpen, setIsChatOpen] = useState(false);
29-
// Added state for Brave browser detection
3063
const [isBraveBrowser, setIsBraveBrowser] = useState(false);
31-
64+
const [showLoginPrompt, setShowLoginPrompt] = useState(false);
65+
const UNAUTHENTICATED_USAGE_LIMIT = 2;
3266
const apiServerUrl = import.meta.env.VITE_API_URL;
3367

3468
useEffect(() => {
@@ -37,7 +71,7 @@ const GitformeUi = () => {
3771
}
3872
}, [username, reponame]);
3973

40-
// Effect to check for Brave browser on component mount
74+
4175
useEffect(() => {
4276
const checkForBrave = async () => {
4377
if (navigator.brave && await navigator.brave.isBrave()) {
@@ -56,29 +90,55 @@ const GitformeUi = () => {
5690
navigate('/');
5791
};
5892

59-
const handleCookRepoUrl = () => {
60-
if (!repoUrl) {
61-
alert('Please enter a GitHub repository URL.');
62-
return;
63-
}
64-
try {
65-
const url = new URL(repoUrl);
66-
const pathParts = url.pathname.split('/').filter(part => part);
67-
if (pathParts.length >= 2) {
68-
navigate(`/${pathParts[0]}/${pathParts[1]}`);
69-
} else {
70-
alert('Invalid GitHub repository URL format. Example: https://github.com/owner/repo');
71-
}
72-
} catch (e) {
73-
alert('Invalid URL format. Please enter a valid URL.');
74-
}
75-
};
93+
// 3. Updated function to handle usage limits
94+
const handleCookRepoUrl = () => {
95+
if (!repoUrl) {
96+
alert('Please enter a GitHub repository URL.');
97+
return;
98+
}
99+
try {
100+
const url = new URL(repoUrl);
101+
const pathParts = url.pathname.split('/').filter(part => part);
102+
103+
if (pathParts.length < 2) {
104+
alert('Invalid GitHub repository URL format. Example: https://github.com/owner/repo');
105+
return;
106+
}
107+
108+
const repoIdentifier = `${pathParts[0]}/${pathParts[1]}`;
109+
110+
// Check usage limit only if the user is not authenticated
111+
if (!isAuthenticated) {
112+
const viewedRepos = JSON.parse(localStorage.getItem('viewedRepos') || '[]');
113+
114+
// If repo is new and limit is reached, show prompt
115+
if (!viewedRepos.includes(repoIdentifier) && viewedRepos.length >= UNAUTHENTICATED_USAGE_LIMIT) {
116+
setShowLoginPrompt(true);
117+
return;
118+
}
119+
120+
// If repo is new and limit is not reached, add it to tracking
121+
if (!viewedRepos.includes(repoIdentifier)) {
122+
viewedRepos.push(repoIdentifier);
123+
localStorage.setItem('viewedRepos', JSON.stringify(viewedRepos));
124+
}
125+
}
126+
127+
// Proceed to the repo page
128+
navigate(`/${pathParts[0]}/${pathParts[1]}`);
129+
} catch (e) {
130+
alert('Invalid URL format. Please enter a valid URL.');
131+
}
132+
};
133+
const handleApiError = () => {
134+
if (!isAuthenticated) {
135+
setShowLoginPrompt(true);
136+
}
137+
};
76138

77139
return (
78140
<div className="bg-[#FDFCFB] bg-[radial-gradient(#d1d1d1_1px,transparent_1px)] [background-size:24px_24px] min-h-screen font-sans text-gray-800 relative">
79-
80141
<canvas id="codeCanvas" className="absolute inset-0 w-full h-full pointer-events-none z-0 opacity-20"></canvas>
81-
82142
<AppHeader
83143
isAuthenticated={isAuthenticated}
84144
user={user}
@@ -97,9 +157,15 @@ const GitformeUi = () => {
97157
</div>
98158
</div>
99159
)}
100-
160+
<AnimatePresence>
161+
{showLoginPrompt && (
162+
<LoginPromptModal
163+
onLogin={handleGitHubLogin}
164+
onClose={() => setShowLoginPrompt(false)}
165+
/>
166+
)}
167+
</AnimatePresence>
101168
<AnimatePresence mode="wait">
102-
103169
<motion.div
104170
key={username && reponame ? "repo-view-active" : "landing-view-active"}
105171
initial={{ opacity: 0, scale: 0.98, filter: 'blur(5px)' }}
@@ -118,16 +184,15 @@ const GitformeUi = () => {
118184
animate={{opacity: 1}}
119185
exit={{opacity: 0}}
120186
>
121-
<RepoDetailView />
187+
<RepoDetailView onApiError={handleApiError} />
188+
122189
</motion.main>
123190
)}
124191
</motion.div>
125192
</AnimatePresence>
126193

127194
<footer className="text-center py-8 px-4 mt-16 border-t-2 border-black bg-white/50">
128-
<div className="flex flex-col items-center gap-4"> {/* Increased gap for better spacing */}
129-
{/* Product Hunt Badge */}
130-
195+
<div className="flex flex-col items-center gap-3">
131196
<p className="flex items-center gap-2 text-gray-600 font-medium">
132197
Inspired by: <a href="https://gitingest.com/" target="_blank" rel="noopener noreferrer" className="text-blue-600 hover:underline">Gitingest.com</a>
133198
</p>
@@ -165,4 +230,4 @@ const GitformeUi = () => {
165230
);
166231
};
167232

168-
export default GitformeUi;
233+
export default GitformeUi;

0 commit comments

Comments
 (0)