-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Defer PostGallery to client, Suspense just isn't working well
- Loading branch information
1 parent
1e0adc8
commit 652420f
Showing
9 changed files
with
155 additions
and
164 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use server'; | ||
|
||
import { Post } from '@core/post'; | ||
|
||
async function getPosts(tag?: string) { | ||
let posts = []; | ||
let query = Post.getPublishedPostsWithTags; | ||
|
||
if (tag) { | ||
query = () => Post.getPublishedPostsByTagWithRelations(tag); | ||
} | ||
|
||
try { | ||
posts = await query(); | ||
} catch (err) { | ||
posts = await query(); | ||
} | ||
|
||
return posts; | ||
} | ||
|
||
export default getPosts; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,50 @@ | ||
'use client'; | ||
|
||
import styles from './PostGallery.module.css'; | ||
import { PublishedPostWithTags } from '@core/post'; | ||
import PostCard from '@/components/PostCard'; | ||
import { useEffect, useState } from 'react'; | ||
import PostSkeletonGallery from '../PostSkeletonGallery'; | ||
|
||
interface Props { | ||
posts: PublishedPostWithTags[]; | ||
getPosts: Function; | ||
} | ||
|
||
const PostGallery = ({ posts }: Props) => { | ||
return ( | ||
<div className={styles.gallery}> | ||
{posts.map((post) => { | ||
const { id, title, slug, published_on, abstract, tags, updated } = post; | ||
return ( | ||
<PostCard | ||
key={id} | ||
title={title} | ||
slug={slug} | ||
publishedOn={published_on} | ||
abstract={abstract} | ||
tags={tags} | ||
updated={updated} | ||
/> | ||
); | ||
})} | ||
</div> | ||
); | ||
const PostGallery = ({ getPosts }: Props) => { | ||
const [posts, setPosts] = useState<PublishedPostWithTags[]>([]); | ||
|
||
useEffect(() => { | ||
const getData = async () => { | ||
const data = await getPosts(); | ||
setPosts(data); | ||
}; | ||
|
||
getData(); | ||
}, []); | ||
|
||
if (posts.length) { | ||
return ( | ||
<div className={styles.gallery}> | ||
{posts.map((post) => { | ||
const { id, title, slug, published_on, abstract, tags, updated } = | ||
post; | ||
return ( | ||
<PostCard | ||
key={id} | ||
title={title} | ||
slug={slug} | ||
publishedOn={published_on} | ||
abstract={abstract} | ||
tags={tags} | ||
updated={updated} | ||
/> | ||
); | ||
})} | ||
</div> | ||
); | ||
} | ||
|
||
return <PostSkeletonGallery />; | ||
}; | ||
|
||
export default PostGallery; |
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.