Skip to content

Commit d77d977

Browse files
committed
feat: fix blog display
1 parent f373c18 commit d77d977

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

frontend/src/components/BlogsBlock/index.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ type TBlog = {
2929
link?: string
3030
}
3131

32-
const defaultDesc = ""
3332

3433
interface Props extends BlogsBlockFragment { }
3534
const PAGE_SIZE = 3
@@ -38,13 +37,6 @@ const BlogsBlock = (props: Props) => {
3837
const [blockListing, setBlockListing] =
3938
useState<GetPostsThumbQuery["posts"]>()
4039
const { locale } = useLocaleContext()
41-
const [page, setPage] = useState(0)
42-
43-
const sizes = blockListing ? blockListing.nodes.length : 0
44-
const max_page = blockListing
45-
? Math.floor(blockListing?.nodes?.length / PAGE_SIZE)
46-
: 0
47-
4840
useEffect(() => {
4941
; (async () => {
5042
const { data } = await getPostThumb(
@@ -54,6 +46,16 @@ const BlogsBlock = (props: Props) => {
5446
})()
5547
}, [])
5648

49+
const [page, setPage] = useState(0)
50+
const sizes = blockListing ? blockListing.nodes.length : 0
51+
const max_page = blockListing
52+
? Math.floor(blockListing?.nodes?.length / PAGE_SIZE)
53+
: 0
54+
55+
const totalPosts = blockListing?.nodes?.length || 0
56+
const currentlyShowing = Math.min((page + 1) * PAGE_SIZE, totalPosts)
57+
const hasMorePosts = currentlyShowing < totalPosts
58+
5759
if (!blockListing && sizes < 1)
5860
return (
5961
<div className="container-fluid min-h-[500px] pt-10">
@@ -125,7 +127,7 @@ const BlogsBlock = (props: Props) => {
125127
)
126128
})}
127129
<div className="mt-10 flex w-full justify-center">
128-
{sizes > PAGE_SIZE && (page + 1) * PAGE_SIZE < sizes && (
130+
{hasMorePosts && (
129131
<Button
130132
onClick={() =>
131133
setPage((prev) => {

frontend/src/libs/graphql/utils/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@ export async function getPostThumb(lang: LanguageCodeFilterEnum) {
207207
blogDescription
208208
}
209209
}
210+
pageInfo {
211+
endCursor
212+
startCursor
213+
hasNextPage
214+
}
210215
}
211216
}
212217
`),
@@ -290,7 +295,7 @@ export async function getPost(slug: string) {
290295
//@ts-ignore
291296
query: gql(`
292297
query GetPost($databaseId: ID!) {
293-
post(id: $databaseId, idType: SLUG) {
298+
post(id: $databaseId, idType: URI) {
294299
databaseId
295300
dateGmt
296301
slug

0 commit comments

Comments
 (0)