Skip to content

Commit

Permalink
fix(ui): add fallback for MainNavigation and remove path-based styling
Browse files Browse the repository at this point in the history
MainNavigationFallback component added to display in case MainNavigation fails to load. This enhances UX by preventing an empty space appearance during loading or error cases. Also, the path-based background color change on 'Blog' menu item has been removed to ensure consistent styling.
  • Loading branch information
kkhys committed Jun 9, 2024
1 parent 556f7d7 commit 770c0cf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
12 changes: 10 additions & 2 deletions apps/web/src/ui/global/header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ import { useDebounce } from 'use-debounce';

import { cn } from '@kkhys/ui';

import { CommandMenu, ContainerInner, ContainerOuter, MainNavigation, MobileNavigation, ModeToggle } from '#/ui/global';
import {
CommandMenu,
ContainerInner,
ContainerOuter,
MainNavigation,
MainNavigationFallback,
MobileNavigation,
ModeToggle,
} from '#/ui/global';

export const useHeaderAnimation = () => {
const [animationHeader, setAnimationHeader] = React.useState<boolean | null>(null);
Expand Down Expand Up @@ -68,7 +76,7 @@ export const Header = ({ className }: { className?: string }) => {
<div className='border-b border-border/60 bg-background-lighter/95 py-2.5 backdrop-blur supports-[backdrop-filter]:bg-background-lighter/60'>
<ContainerInner>
<div className='flex w-full items-center justify-between'>
<Suspense fallback={null}>
<Suspense fallback={<MainNavigationFallback />}>
<MainNavigation />
</Suspense>
<MobileNavigation />
Expand Down
18 changes: 17 additions & 1 deletion apps/web/src/ui/global/main-navigation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const MainNavigation = () => {
<NavigationMenu>
<NavigationMenuList>
<NavigationMenuItem>
<NavigationMenuTrigger className={cn(pathname === '/posts' && 'bg-accent')}>Blog</NavigationMenuTrigger>
<NavigationMenuTrigger>Blog</NavigationMenuTrigger>
<NavigationMenuContent className='min-w-[8rem] p-1'>
<ListItem href='/posts' className={cn(pathname === '/posts' && !categoryParam && 'bg-accent')}>
All Posts
Expand Down Expand Up @@ -79,3 +79,19 @@ export const MainNavigation = () => {
</div>
);
};

export const MainNavigationFallback = () => (
<div className='mr-4 hidden md:flex'>
<Link href='/' className='mr-6 flex flex-shrink-0 items-center'>
<Icons.logo className='size-5 rounded-md' />
<span className='sr-only'>Keisuke Hayashi</span>
</Link>
<NavigationMenu>
<NavigationMenuList>
<NavigationMenuItem>
<NavigationMenuTrigger>Blog</NavigationMenuTrigger>
</NavigationMenuItem>
</NavigationMenuList>
</NavigationMenu>
</div>
);

0 comments on commit 770c0cf

Please sign in to comment.