Skip to content

Commit

Permalink
Merge pull request #283 from aulianza/hotfix/blog-error
Browse files Browse the repository at this point in the history
fix: validate error
  • Loading branch information
aulianza authored Nov 13, 2023
2 parents 2610cda + cad3f0c commit 08fd233
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/modules/blog/components/BlogListNew.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ const BlogListNew = () => {

const debouncedSearchTerm = useDebounce(searchTerm, 500);

const { data, mutate, isLoading } = useSWR(
const { data, error, mutate, isValidating } = useSWR(
`/api/blog?page=${page}&per_page=6&search=${debouncedSearchTerm}`,
fetcher
fetcher,
{
revalidateOnFocus: false,
}
);

const {
Expand Down Expand Up @@ -82,9 +85,9 @@ const BlogListNew = () => {
}, [page, router.query.page, searchTerm]);

const renderEmptyState = () =>
!isLoading &&
!isValidating &&
(!data?.status || blogData.length === 0) && (
<EmptyState message='No Post Found.' />
<EmptyState message={error ? 'Error loading posts' : 'No Post Found.'} />
);

return (
Expand Down Expand Up @@ -118,7 +121,7 @@ const BlogListNew = () => {
</div>

<div className='grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-5'>
{!isLoading ? (
{!isValidating ? (
<>
{blogData.map((item: BlogItemProps, index: number) => (
<motion.div
Expand All @@ -140,7 +143,7 @@ const BlogListNew = () => {
)}
</div>

{!isLoading && data?.status && (
{!isValidating && data?.status && (
<Pagination
totalPages={totalPages}
currentPage={page}
Expand Down

1 comment on commit 08fd233

@vercel
Copy link

@vercel vercel bot commented on 08fd233 Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.