-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnav.tsx
274 lines (250 loc) · 8.3 KB
/
nav.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
'use client';
import {
useState,
useEffect,
forwardRef,
useImperativeHandle,
ReactNode,
} from 'react';
import { motion, AnimatePresence } from 'framer-motion';
import { usePathname } from 'next/navigation';
import { Github, Star, SunMoon, Home, Info, DollarSign } from 'lucide-react';
import { useTheme } from 'next-themes';
import { AnimatedNumber } from '../ui/animate-number';
import { useAuthContext } from '@/providers/AuthProvider';
import { SignUpModal } from '../sign-up-modal';
import { SignInModal } from '../sign-in-modal';
import { logger } from '@/app/log/logger';
// Define the ref interface
export interface NavbarRef {
activeTab: number;
setActiveTab: (index: number) => void;
}
// Define props interface
interface FloatingNavbarProps {
logo?: ReactNode;
name: string;
className?: string;
containerClassName?: string;
tabsContainerClassName?: string;
activeTabClassName?: string;
inactiveTabClassName?: string;
logoContainerClassName?: string;
nameClassName?: string;
toolsContainerClassName?: string;
animationDuration?: number;
}
// Extended FloatingNavbar with Next.js navigation
const FloatingNavbar = forwardRef<NavbarRef, FloatingNavbarProps>(
(
{
logo,
name,
className = '',
containerClassName = '',
tabsContainerClassName = '',
activeTabClassName = '',
inactiveTabClassName = '',
logoContainerClassName = '',
nameClassName = '',
toolsContainerClassName = '',
animationDuration = 300,
},
ref
) => {
const pathname = usePathname();
const { theme, setTheme } = useTheme();
const { isAuthorized, logout } = useAuthContext();
const [starCount, setStarCount] = useState(0);
const [isLoading, setIsLoading] = useState(true);
const [showSignUp, setShowSignUp] = useState(false);
const [showSignIn, setShowSignIn] = useState(false);
const tabs = [
{ label: 'Home', path: '/', icon: <Home size={16} /> },
{
label: 'Codefox Journey',
path: '/Codefox-Journey',
icon: <Info size={16} />,
},
{ label: 'Pricing', path: '/price', icon: <DollarSign size={16} /> },
];
// Fetch GitHub stars
useEffect(() => {
const fetchGitHubStars = async () => {
try {
const response = await fetch(
'https://api.github.com/repos/Sma1lboy/codefox'
);
if (response.ok) {
const data = await response.json();
setStarCount(data.stargazers_count);
}
} catch (error) {
logger.error('Error fetching GitHub stars:', error);
} finally {
setIsLoading(false);
}
};
fetchGitHubStars();
}, []);
// Find the active tab index based on the current pathname
const findActiveTabIndex = () => {
const index = tabs.findIndex((tab) => tab.path === pathname);
return index >= 0 ? index : 0; // Default to first tab if path not found
};
// const [activeTab, setActiveTab] = useState(findActiveTabIndex());
// const [isVisible, setIsVisible] = useState(true);
// Update active tab when pathname changes
// useEffect(() => {
// const newActiveTab = findActiveTabIndex();
// if (newActiveTab !== activeTab) {
// setActiveTab(newActiveTab);
// }
// }, [pathname]);
// Expose the activeTab value to parent components through the ref
// useImperativeHandle(ref, () => ({
// activeTab,
// setActiveTab: (index) => handleTabChange(index),
// }));
// // Handle tab change locally (for animation purposes)
// const handleTabChange = (index: number) => {
// if (index !== activeTab) {
// setIsVisible(false);
// setTimeout(() => {
// setActiveTab(index);
// setIsVisible(true);
// }, animationDuration);
// }
// };
// Toggle theme function
const toggleTheme = () => {
setTheme(theme === 'dark' ? 'light' : 'dark');
};
// Ensure content is visible on initial render
// useEffect(() => {
// setIsVisible(true);
// }, []);
// Using the same animation variants as in page.tsx
const containerVariants = {
hidden: { opacity: 0 },
visible: {
opacity: 1,
transition: {
duration: 0.8,
ease: 'easeInOut',
staggerChildren: 0.3,
},
},
};
const itemVariants = {
hidden: { opacity: 0, y: 20 },
visible: {
opacity: 1,
y: 0,
transition: {
duration: 0.5,
ease: 'easeOut',
},
},
};
// const handleTabClick = (
// e: React.MouseEvent,
// index: number,
// label: string,
// path: string
// ) => {
// if (label === 'Pricing') {
// e.preventDefault();
// alert('Coming Soon');
// } else if (label === 'Codefox Journey') {
// e.preventDefault();
// alert('Coming Soon');
// } else {
// handleTabChange(index);
// }
// };
return (
<>
<div className={` top-5 left-0 right-0 z-50 ${className}`}>
<motion.div
className={`w-full flex justify-around items-center px-8 py-7 ${containerClassName}`}
initial="hidden"
animate="visible"
variants={containerVariants}
>
{/* Left side - Logo and Name */}
<motion.div
className={`flex items-center space-x-3 ${logoContainerClassName}`}
variants={itemVariants}
>
<span
className={` font-bold text-3xl text-primary-600 dark:text-primary-400 transition-transform hover:scale-105 duration-300 ${nameClassName}`}
>
{name}
</span>
</motion.div>
<motion.div
className="flex-1 flex justify-end items-center space-x-4"
variants={itemVariants}
>
<a
href="https://github.com/Sma1lboy/codefox"
target="_blank"
rel="noopener noreferrer"
className="flex items-center px-3 py-1.5 text-sm font-medium text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white transition-colors duration-200"
>
<Github size={18} className="mr-1.5" />
<Star
size={16}
className="mr-1 text-yellow-500"
fill="currentColor"
/>
{isLoading ? (
<span className="animate-pulse">Loading...</span>
) : (
<AnimatedNumber
value={starCount}
precision={0}
mass={0.8}
stiffness={75}
damping={15}
/>
)}
</a>
<button
onClick={toggleTheme}
className="p-2 text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white transition-colors duration-200"
aria-label="Toggle theme"
>
<SunMoon size={20} />
</button>
{/* Authentication Buttons */}
{!isAuthorized && (
<div className="flex items-center space-x-4 transition-transform duration-300">
<button
onClick={() => setShowSignIn(true)}
className="px-4 py-2 rounded-sm border border-primary-500 text-primary-500 dark:text-primary-400
hover:bg-primary-500 hover:text-white transition-colors"
>
Sign In
</button>
<button
onClick={() => setShowSignUp(true)}
className="px-4 py-2 rounded-sm bg-primary-500 text-white hover:bg-primary-600 transition-colors"
>
Sign Up
</button>
</div>
)}
</motion.div>
</motion.div>
</div>
{/* Modals */}
<SignUpModal isOpen={showSignUp} onClose={() => setShowSignUp(false)} />
<SignInModal isOpen={showSignIn} onClose={() => setShowSignIn(false)} />
</>
);
}
);
FloatingNavbar.displayName = 'FloatingNavbar';
export default FloatingNavbar;