Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into fix/routes
  • Loading branch information
revengemiroz committed Jul 28, 2023
2 parents f00772f + c143065 commit 4055b67
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
4 changes: 2 additions & 2 deletions apps/web/src/components/MobileMenu/MobileMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import MenuIcon from '@/assets/icons/menu-icon.svg';
const MobileMenu = () => {
const { t } = useTranslation('common');
const [open, setOpen] = useState(false);
const { isLoggedIn, logout, currentUser } = useIsLoggedIn();
const { isLoggedIn, logout, currentUser, loading } = useIsLoggedIn();
const [isAuthLoading, setIsAuthLoading] = useState(false);

const handleLogout = async () => {
Expand Down Expand Up @@ -100,7 +100,7 @@ const MobileMenu = () => {
className='px-7'
size='small'
onClick={handleLogin}
isLoading={isAuthLoading}
isLoading={isAuthLoading || loading}
>
{t('login')}
</Button>
Expand Down
32 changes: 21 additions & 11 deletions apps/web/src/components/Navbar/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from 'react';
import { useEffect, useState } from 'react';
import { signIn } from 'next-auth/react';
import { useTranslation } from 'next-i18next';
import Image from 'next/future/image';
Expand All @@ -10,12 +10,18 @@ import MobileMenu from '../MobileMenu';
import useIsLoggedIn from '@/hooks/useIsLoggedIn';

const Navbar = () => {
const { isLoggedIn, logout, currentUser } = useIsLoggedIn();
const { isLoggedIn, logout, currentUser, loading, session } = useIsLoggedIn();
const [isAuthLoading, setIsAuthLoading] = useState(false);
const [open, setOpen] = useState(false);
const [isTopOpen, setIsTopOpen] = useState(false);
const { t } = useTranslation('common');

useEffect(() => {
if (session.status === 'unauthenticated') {
setIsAuthLoading(false);
}
}, [session.status]);

const handleLogin = async () => {
setIsAuthLoading(true);
await signIn('github');
Expand Down Expand Up @@ -86,13 +92,17 @@ const Navbar = () => {
open={open}
setOpen={setOpen}
parent={
<Image
className='h-10 w-10 cursor-pointer rounded-full object-cover'
src={currentUser?.avatar ?? ''}
width={40}
height={40}
alt={currentUser?.name ?? 'user avatar'}
/>
currentUser?.avatar ? (
<Image
className='h-10 w-10 cursor-pointer rounded-full object-cover'
src={currentUser?.avatar ?? ''}
width={40}
height={40}
alt={currentUser?.name ?? 'user avatar'}
/>
) : (
<div className='h-10 w-10 animate-pulse rounded-full bg-slate-700' />
)
}
>
<div className='flex w-40 flex-col rounded-sm bg-grey-dark'>
Expand Down Expand Up @@ -122,9 +132,9 @@ const Navbar = () => {
</>
) : (
<Button
className='px-7'
className='min-w-[120px] px-7'
size='small'
isLoading={isAuthLoading}
isLoading={loading || isAuthLoading}
onClick={handleLogin}
>
{t('login')}
Expand Down
6 changes: 4 additions & 2 deletions apps/web/src/hooks/useIsLoggedIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ const useIsLoggedIn = () => {
};

return {
isLoggedIn: !!data?.getCurrentUser?.id,
loading,
isLoggedIn:
!!data?.getCurrentUser?.id || session.status === 'authenticated',
loading: loading || session.status === 'loading',
logout,
currentUser: data?.getCurrentUser,
session,
};
};

Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/pages/Home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function Home() {
const { data: projectsData } = useGetTopProjectsForHomePageQuery();
const { data: creatorsData } = useGetTopCreatorsForHomePageQuery();

const { isLoggedIn } = useIsLoggedIn();
const { isLoggedIn, loading } = useIsLoggedIn();

const isMobile = useIsMobile();

Expand Down Expand Up @@ -58,7 +58,7 @@ function Home() {
<Button
className='w-fit max-lg:mb-10 max-lg:w-full'
onClick={handleLogin}
isLoading={isAuthLoading}
isLoading={isAuthLoading || loading}
>
{t('common:login')}
</Button>
Expand Down

0 comments on commit 4055b67

Please sign in to comment.