Skip to content

Commit dce706e

Browse files
committed
πŸ–οΈπŸš‡ ↝ [ FCDB-24 ] Glassy menu & fixed window errors
1 parent 049555b commit dce706e

File tree

3 files changed

+102
-13
lines changed

3 files changed

+102
-13
lines changed

β€Žcomponents/Section/Layout.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export const InventoryLayout: React.FC<DashboardLayoutProps> = ({ children }) =>
6565
<>
6666
<main className="h-max pb-10 grow pt-6">
6767
<Navbar />
68-
<div className="py-5"><center><div className="py-12"><InventoryMenu setActiveTab={setActiveTab} /></div></center></div>
68+
<div className="py-8"><center><div className="py-12"><InventoryMenu setActiveTab={setActiveTab} /></div></center></div>
6969
<div className="py-12">
7070
{children}
7171
</div>

β€Žcomponents/Section/Navbar.tsx

+100-11
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ import { MdOutlineSpaceDashboard } from 'react-icons/md';
1717
import { TfiDashboard } from 'react-icons/tfi';
1818
import { HiBars3 } from 'react-icons/hi2';
1919
import { AiFillCloseCircle } from 'react-icons/ai';
20+
import { CgProfile } from 'react-icons/cg';
21+
import { BiLogIn } from 'react-icons/bi';
2022

2123
const UserMenuItems = ({
2224
user,
2325
setMobileMenuOpen,
2426
}: {
25-
user?: { isAdmin: boolean }; // Adjust the type based on your actual user structure
27+
user?: string; // Adjust the type based on your actual user structure
2628
setMobileMenuOpen?: React.Dispatch<React.SetStateAction<boolean>>;
2729
}) => {
2830
const path = window.location.pathname;
@@ -42,7 +44,7 @@ const UserMenuItems = ({
4244
>
4345
{path === '/' || path === '/admin' ? (
4446
<li>
45-
<Link href='/demo-app'>
47+
<Link href='/demo-app' legacyBehavior>
4648
<a className='flex items-center gap-3.5 text-sm font-medium duration-300 ease-in-out hover:text-yellow-500'>
4749
<MdOutlineSpaceDashboard size='1.1rem' />
4850
AI Scheduler (Demo App)
@@ -51,7 +53,7 @@ const UserMenuItems = ({
5153
</li>
5254
) : null}
5355
<li>
54-
<Link href='/account'>
56+
<Link href='/account' legacyBehavior>
5557
<a
5658
onClick={handleMobileMenuClick}
5759
className='flex items-center gap-3.5 text-sm font-medium duration-300 ease-in-out hover:text-yellow-500'
@@ -78,14 +80,13 @@ const UserMenuItems = ({
7880
</Link>
7981
</li>
8082
</ul>
81-
{!!user?.isAdmin && (
8283
<ul
8384
className={`flex flex-col gap-5 border-b border-stroke py-4 dark:border-strokedark ${
8485
path === '/admin' ? 'px-6' : 'sm:px-6'
8586
}`}
8687
>
8788
<li className='flex items-center gap-3.5 text-sm font-medium duration-300 ease-in-out hover:text-yellow-500'>
88-
<Link href='/admin'>
89+
<Link href='/admin' legacyBehavior>
8990
<a
9091
onClick={handleMobileMenuClick}
9192
className='flex items-center gap-3.5 text-sm font-medium duration-300 ease-in-out hover:text-yellow-500'
@@ -96,7 +97,6 @@ const UserMenuItems = ({
9697
</Link>
9798
</li>
9899
</ul>
99-
)}
100100
<button
101101
className={`flex items-center gap-3.5 py-4 text-sm font-medium duration-300 ease-in-out hover:text-yellow-500 ${
102102
path === '/admin' ? 'px-6' : 'sm:px-6'
@@ -126,13 +126,75 @@ const UserMenuItems = ({
126126
};
127127

128128
const UserDropdownMenu = ({ user } : { user: string }) => {
129-
const supabase = useSupabaseClient();
130129
const session = useSession();
130+
const supabase = useSupabaseClient();
131+
const [profile, setProfile] = useState<any>(null);
132+
133+
useEffect(() => {
134+
supabase
135+
.from("profiles")
136+
.select()
137+
.eq("id", session?.user?.id)
138+
.then((result) => {
139+
if (result.data) {
140+
setProfile(result.data[0]);
141+
}
142+
});
143+
}, [session]);
131144

132145
const [dropdownOpen, setDropdownOpen] = useState(false);
133146
const trigger = useRef<any>(null);
134147
const dropdown = useRef<any>(null);
135148
const toggleDropdown = () => setDropdownOpen((prev) => !prev);
149+
150+
useEffect(() => {
151+
const keyHandler = ({ keyCode }: KeyboardEvent) => {
152+
if (!dropdownOpen || keyCode !== 27) return;
153+
setDropdownOpen(false);
154+
};
155+
document.addEventListener('keydown', keyHandler);
156+
return () => document.removeEventListener('keydown', keyHandler);
157+
});
158+
159+
return (
160+
<div className='relative'>
161+
<button
162+
ref={trigger}
163+
onClick={toggleDropdown}
164+
className='flex items-center gap-4 duration-300 ease-in-out text-gray-900 hover:text-yellow-500'
165+
>
166+
<span className='hidden text-right lg:block'>
167+
<span className='block text-sm font-medium dark:text-white'>{profile?.username}</span>
168+
</span>
169+
<CgProfile size='1.1rem' className='ml-1 mt-[0.1rem] dark:text-white' />
170+
<svg
171+
className={`hidden fill-current dark:fill-white sm:block ${dropdownOpen ? 'rotate-180' : ''}`}
172+
width='12'
173+
height='8'
174+
viewBox='0 0 12 8'
175+
fill='none'
176+
xmlns='http://www.w3.org/2000/svg'
177+
>
178+
<path
179+
fillRule='evenodd'
180+
clipRule='evenodd'
181+
d='M0.410765 0.910734C0.736202 0.585297 1.26384 0.585297 1.58928 0.910734L6.00002 5.32148L10.4108 0.910734C10.7362 0.585297 11.2638 0.585297 11.5893 0.910734C11.9147 1.23617 11.9147 1.76381 11.5893 2.08924L6.58928 7.08924C6.26384 7.41468 5.7362 7.41468 5.41077 7.08924L0.410765 2.08924C0.0853277 1.76381 0.0853277 1.23617 0.410765 0.910734Z'
182+
fill=''
183+
/>
184+
</svg>
185+
</button>
186+
187+
{/* <!-- Dropdown --> */}
188+
<div
189+
ref={dropdown}
190+
className={`absolute right-0 mt-4 flex w-62.5 flex-col rounded-sm border border-stroke bg-white shadow-default dark:border-strokedark dark:bg-boxdark dark:text-white ${
191+
dropdownOpen === true ? 'block' : 'hidden'
192+
}`}
193+
>
194+
<UserMenuItems user={session?.user?.id} setMobileMenuOpen={toggleDropdown} />
195+
</div>
196+
</div>
197+
);
136198
}
137199

138200
const navigation = [
@@ -155,10 +217,26 @@ const NavLogo = () => (
155217
);
156218

157219
export default function Navigation() {
220+
const session = useSession();
221+
const supabase = useSupabaseClient();
222+
const [profile, setProfile] = useState<any>(null);
223+
224+
useEffect(() => {
225+
supabase
226+
.from("profiles")
227+
.select()
228+
.eq("id", session?.user?.id)
229+
.then((result) => {
230+
if (result.data) {
231+
setProfile(result.data[0]);
232+
}
233+
});
234+
}, [session]);
235+
158236
const [mobileMenuOpen, setMobileMenuOpen] = useState(false);
159237

160238
return (
161-
<header className='absolute inset-x-0 top-0 z-50 shadow sticky bg-white bg-opacity-50 backdrop-blur-lg backdrop-filter dark:border-strokedark dark:bg-boxdark-2'>
239+
<header className='absolute inset-x-0 top-0 z-50 shadow sticky backdrop-blur-lg bg-opacity-40 backdrop-filter dark:border-strokedark dark:bg-boxdark-2'>
162240
<nav
163241
className='flex items-center justify-between p-6 lg:px-8'
164242
aria-label='Global'
@@ -193,7 +271,18 @@ export default function Navigation() {
193271
<ul className='flex justify-center items-center gap-2 sm:gap-4'>
194272
{/* <DarkModeSwitcher /> */}
195273
</ul>
196-
274+
<a
275+
href={!session ? '/login' : '/account'}
276+
className='text-sm font-semibold leading-6 ml-4'
277+
>
278+
{/* <div className='flex items-center duration-300 ease-in-out text-gray-900 hover:text-yellow-500 dark:text-white'>
279+
Log in <BiLogIn size='1.1rem' className='ml-1 mt-[0.1rem]' />
280+
</div> */}
281+
</a>
282+
{/* ) : ( */}
283+
<div className='ml-4'>
284+
<UserDropdownMenu user={session?.user?.id} />
285+
</div>
197286
{/* {isUserLoading ? null : !user ? (
198287
<a
199288
href={!user ? '/login' : '/account'}
@@ -262,8 +351,8 @@ export default function Navigation() {
262351
</Dialog.Panel>
263352
</Dialog>
264353
</header>
265-
)
266-
}
354+
);
355+
};
267356

268357
const products = [
269358
{ name: 'Your planets', description: '', href: '/garden', icon: ChartPieIcon },

β€Žpages/planets/[id].tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export default function PlanetIdPage () {
9494
return (
9595
<>
9696
<Navbar />
97-
<div className="h-screen">
97+
<div className="h-screen py-4">
9898
<IndividualBasePlanetDesktop id={id as string} />
9999
</div>
100100
<div className="bg-white py-5">

0 commit comments

Comments
Β (0)