Skip to content

Commit

Permalink
fix(ui): Add CategoryTabsFallback component for async loading
Browse files Browse the repository at this point in the history
This commit adds a fallback UI (`CategoryTabsFallback` component) to be displayed when `CategoryTabs` is loading asynchronously. The new fallback component is used inside a `Suspense` directive in the blog posts page.
  • Loading branch information
kkhys committed Jun 9, 2024
1 parent 770c0cf commit 3213192
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions apps/web/src/app/posts/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as React from 'react';
import { Suspense } from 'react';

import { BackButton, Container } from '#/ui/global';
import { CategoryTabs } from '#/ui/post';
import { CategoryTabs, CategoryTabsFallback } from '#/ui/post';
import { JsonLd } from './json-ld';

export const metadata = {
Expand All @@ -25,7 +25,7 @@ const Page = () => (
<header>
<h1 className='font-sans font-medium'>Blog</h1>
</header>
<Suspense fallback={null}>
<Suspense fallback={<CategoryTabsFallback />}>
<CategoryTabs />
</Suspense>
</Container>
Expand Down
22 changes: 22 additions & 0 deletions apps/web/src/ui/post/category-tabs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,25 @@ export const CategoryTabs = () => {
</Tabs>
);
};

export const CategoryTabsFallback = () => (
<Tabs className='mt-6'>
<div className='flex gap-4'>
<TabsList>
<TabsTrigger value='all' className='font-sans'>
All
</TabsTrigger>
<TabsTrigger value='tech' className='font-sans'>
Tech
</TabsTrigger>
<TabsTrigger value='life' className='font-sans'>
Life
</TabsTrigger>
</TabsList>
<Button variant='outline' size='icon'>
<RssIcon className='size-4' />
<span className='sr-only'>Atom</span>
</Button>
</div>
</Tabs>
);

0 comments on commit 3213192

Please sign in to comment.