-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fixed suspense with query params, added loading and layout
- Loading branch information
1 parent
286efe4
commit e44785e
Showing
22 changed files
with
221 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { SquarePen } from 'lucide-react'; | ||
import { useTranslations } from 'next-intl'; | ||
import { unstable_setRequestLocale } from 'next-intl/server'; | ||
import { type ReactNode } from 'react'; | ||
|
||
import { Link } from '@/lib/navigation'; | ||
|
||
import { Button } from '@/components/ui/Button'; | ||
|
||
type NewsHeaderProps = { | ||
children: ReactNode; | ||
params: { locale: string }; | ||
}; | ||
|
||
export default function NewsHeader({ | ||
children, | ||
params: { locale }, | ||
}: NewsHeaderProps) { | ||
unstable_setRequestLocale(locale); | ||
const t = useTranslations('news'); | ||
return ( | ||
<> | ||
<div className='flex items-center justify-between'> | ||
<h1 className='my-4'>{t('title')}</h1> | ||
<Button asChild size='sm'> | ||
<Link href='/news/new'> | ||
<SquarePen className='mr-2 h-4 w-4' /> | ||
{t('newArticle')} | ||
</Link> | ||
</Button> | ||
</div> | ||
{children} | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { PaginationCarouselSkeleton } from '@/components/layout/PaginationCarouselSkeleton'; | ||
import { CardGridSkeleton } from '@/components/news/CardGridSkeleton'; | ||
import { ItemGridSkeleton } from '@/components/news/ItemGridSkeleton'; | ||
import { Separator } from '@/components/ui/Separator'; | ||
|
||
export default function NewsSkeleton() { | ||
return ( | ||
<> | ||
<CardGridSkeleton /> | ||
<Separator className='my-6' /> | ||
<ItemGridSkeleton /> | ||
<PaginationCarouselSkeleton className='my-6' /> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { articleMockData as articleData } from '@/mock-data/article'; | ||
import { useTranslations } from 'next-intl'; | ||
import { getTranslations, unstable_setRequestLocale } from 'next-intl/server'; | ||
import { createSearchParamsCache, parseAsInteger } from 'nuqs/parsers'; | ||
import { Suspense } from 'react'; | ||
|
||
import { PaginationCarousel } from '@/components/layout/PaginationCarousel'; | ||
import { CardGrid } from '@/components/news/CardGrid'; | ||
import { ItemGrid } from '@/components/news/ItemGrid'; | ||
import { ItemGridSkeleton } from '@/components/news/ItemGridSkeleton'; | ||
import { Separator } from '@/components/ui/Separator'; | ||
|
||
export async function generateMetadata({ | ||
params: { locale }, | ||
}: { | ||
params: { locale: string }; | ||
}) { | ||
const t = await getTranslations({ locale, namespace: 'layout' }); | ||
|
||
return { | ||
title: t('news'), | ||
}; | ||
} | ||
|
||
const searchParamsCache = createSearchParamsCache({ | ||
page: parseAsInteger.withDefault(1), | ||
}); | ||
|
||
export default function News({ | ||
params: { locale }, | ||
searchParams, | ||
}: { | ||
params: { locale: string }; | ||
searchParams: Record<string, string | string[] | undefined>; | ||
}) { | ||
unstable_setRequestLocale(locale); | ||
const t = useTranslations('ui'); | ||
const { page } = searchParamsCache.parse(searchParams); | ||
// TODO: Button to create new article should only be visible when logged in | ||
return ( | ||
<> | ||
<CardGrid topArticles={articleData.slice(0, 4)} /> | ||
<Separator className='my-6' /> | ||
<Suspense key={page} fallback={<ItemGridSkeleton />}> | ||
<ItemGrid page={page} /> | ||
</Suspense> | ||
<PaginationCarousel | ||
className='my-6' | ||
totalPages={Math.ceil(articleData.length / 6)} | ||
t={{ | ||
goToPreviousPage: t('goToPreviousPage'), | ||
previous: t('previous'), | ||
morePages: t('morePages'), | ||
goToNextPage: t('goToNextPage'), | ||
next: t('next'), | ||
page: t('page'), | ||
}} | ||
/> | ||
</> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.