feat: get blog list

This commit is contained in:
Quangnhankie
2021-10-19 10:32:09 +07:00
88 changed files with 2019 additions and 356 deletions

View File

@@ -3,34 +3,32 @@ import { GetStaticPropsContext } from 'next';
import { Layout } from 'src/components/common';
import { BlogCardProps } from 'src/components/common/CardBlog/CardBlog';
import { BlogBreadCrumb, BlogHeading, BlogsList, FeaturedCardBlog } from 'src/components/modules/blogs';
import { DEFAULT_BLOG_PAGE_SIZE,DEFAULT_FEATURED_BLOG_PAGE_SIZE } from "src/utils/constanst.utils";
import { DEFAULT_BLOG_PAGE_SIZE } from "src/utils/constanst.utils";
import { getAllPromies } from 'src/utils/funtion.utils';
import { PromiseWithKey } from 'src/utils/types.utils';
import { getIdFeaturedBlog } from 'src/utils/funtion.utils';
interface Props {
blogsResult: { blogs?: BlogCardProps[],featuredBlogs?: BlogCardProps[] },
blogsResult: { blogs?: BlogCardProps[],featuredBlog?: BlogCardProps[] },
totalItems: number
}
export default function BlogsPage({blogsResult,totalItems}:Props) {
// let date = new Date(blogsResult?.featuredBlogs[0]?.createdAt ?? '' );
// let fullDate = date.toLocaleString('en-us', { month: 'long' }) + " " + date.getDate()+","+date.getFullYear();
let date = new Date(blogsResult.featuredBlog?.[0]?.createdAt ?? '' );
let fullDate = date.toLocaleString('en-us', { month: 'long' }) + " " + date.getDate()+","+date.getFullYear();
return(
<>
<BlogBreadCrumb />
<BlogHeading />
{/* <FeaturedCardBlog
title={blogsResult?.featuredBlogs[0]?.title}
imgSrc={blogsResult?.featuredBlogs[0]?.imageSrc ?? ''}
content={blogsResult?.featuredBlogs[0]?.description}
imgAuthor={blogsResult?.featuredBlogs[0]?.authorAvatarAsset}
authorName={blogsResult?.featuredBlogs[0]?.authorName}
<FeaturedCardBlog
title={blogsResult.featuredBlog?.[0]?.title}
slug={blogsResult.featuredBlog?.[0]?.slug}
imgSrc={blogsResult.featuredBlog?.[0]?.imageSrc ?? ''}
content={blogsResult.featuredBlog?.[0]?.description}
imgAuthor={blogsResult.featuredBlog?.[0]?.authorAvatarAsset}
authorName={blogsResult.featuredBlog?.[0]?.authorName}
date={fullDate}
/> */}
<BlogsList blogList={blogsResult.blogs} total={totalItems} />
/>
<BlogsList blogList={blogsResult.blogs} total={totalItems} idFeatured={blogsResult.featuredBlog?.[0]?.id} />
</>
)
}
@@ -53,17 +51,12 @@ export async function getStaticProps({
config,
preview,
})
// console.log(featuredBlogs[0].id);
// promisesWithKey.push({ key: 'blogsResult', promise: FeaturedBlogPromise })
// Blogs
const idBlog = featuredBlogs[0].id;
const blogsPromise = commerce.getAllBlogs({
const idFeaturedBlog = featuredBlogs[0].id;
const blogsPromise = commerce.getAllBlogs({
variables: {
excludeBlogIds: [idBlog],
excludeBlogIds: [idFeaturedBlog],
take: DEFAULT_BLOG_PAGE_SIZE
},
config,
@@ -71,7 +64,6 @@ export async function getStaticProps({
})
promisesWithKey.push({ key: 'blogsResult', promise: blogsPromise })
try {
const promises = getAllPromies(promisesWithKey)
@@ -81,8 +73,9 @@ export async function getStaticProps({
props[item.key] = item.keyResult ? rs[index][item.keyResult] : rs[index]
return null
})
props['blogsResult']['featuredBlog'] = featuredBlogs;
props['blogsResult']['featuredBlog'] = featuredBlogs;
return {
props,
revalidate: 60