)
diff --git a/src/components/common/index.ts b/src/components/common/index.ts
index 2b7724b73..e2c28e186 100644
--- a/src/components/common/index.ts
+++ b/src/components/common/index.ts
@@ -55,4 +55,5 @@ export { default as FormForgot} from './ForgotPassword/FormForgot/FormForgot'
export { default as FormResetPassword} from './ForgotPassword/FormResetPassword/FormResetPassword'
export { default as ProductCardSkeleton} from './ProductCardSkeleton/ProductCardSkeleton'
export { default as ListProductCardSkeleton} from './ListProductCardSkeleton/ListProductCardSkeleton'
+export { default as ListBlogCardSkeleton} from './ListBlogCardSkeleton/ListBlogCardSkeleton'
diff --git a/src/components/hooks/blog/index.ts b/src/components/hooks/blog/index.ts
new file mode 100644
index 000000000..e8359671a
--- /dev/null
+++ b/src/components/hooks/blog/index.ts
@@ -0,0 +1 @@
+export {default as useGetBlogList }from "./useGetBlogList"
\ No newline at end of file
diff --git a/src/components/hooks/blog/useGetBlogList.tsx b/src/components/hooks/blog/useGetBlogList.tsx
new file mode 100644
index 000000000..9db7a3a5a
--- /dev/null
+++ b/src/components/hooks/blog/useGetBlogList.tsx
@@ -0,0 +1,18 @@
+import { GetAllBlogsQuery, QueryBlogs,BlogList } from '@framework/schema'
+import { normalizeBlogList } from '@framework/utils/normalize'
+import { getAllBlogsQuery } from '@framework/utils/queries/get-all-blog-query'
+import gglFetcher from 'src/utils/gglFetcher'
+import useSWR from 'swr'
+
+const useGetBlogList = (options?: QueryBlogs) => {
+ const { data, isValidating, ...rest } = useSWR([getAllBlogsQuery, options], gglFetcher)
+
+ return {
+ blogs: data?.blogs?.items?.map((blog:BlogList)=>normalizeBlogList(blog)),
+ totalItems: data?.blogs?.totalItems || null,
+ loading: isValidating,
+ ...rest
+ }
+}
+
+export default useGetBlogList
diff --git a/src/components/modules/blogs/BlogsList/BlogsList.tsx b/src/components/modules/blogs/BlogsList/BlogsList.tsx
index 9b7ddc1e0..d9dbf26ed 100644
--- a/src/components/modules/blogs/BlogsList/BlogsList.tsx
+++ b/src/components/modules/blogs/BlogsList/BlogsList.tsx
@@ -1,151 +1,96 @@
-import React, { useState } from 'react'
+import { useRouter } from 'next/router'
+import React, { useEffect, useState,useRef, useMemo } from 'react'
import CardBlog, { BlogCardProps } from 'src/components/common/CardBlog/CardBlog'
import PaginationCommon from 'src/components/common/PaginationCommon/PaginationCommon'
+import { DEFAULT_BLOG_PAGE_SIZE, QUERY_KEY, ROUTE } from 'src/utils/constanst.utils'
import s from "./BlogsList.module.scss"
-import { DEFAULT_BLOG_PAGE_SIZE } from 'src/utils/constanst.utils'
+import { QueryBlogs } from '@framework/schema'
+import { useGetBlogList } from 'src/components/hooks/blog'
+import { getPageFromQuery } from 'src/utils/funtion.utils'
+import { ListBlogCardSkeleton } from 'src/components/common'
interface BlogsListProps {
- data?: BlogCardProps[],
+ blogList?: BlogCardProps[],
+ total?: number,
+ idFeatured?:string
}
-const BLOGSLIST_DATA = [
- {
- imageSrc: "https://user-images.githubusercontent.com/46085455/133185783-8100ef4e-7a72-4dc1-bb12-2ca46b56b393.png",
- title: "1",
- description: "The DEBM diet stands for "+"Delicious Happy Fun Diet"+". This diet was popularized by Robert...",
- slug: "happy-diet"
- },
- {
- imageSrc: "https://user-images.githubusercontent.com/46085455/133185911-df505d10-fdcd-4312-add3-7c62ad8af71e.png",
- title: "2",
- description: "Aloe vera or aloe vera is a green plant, has thorns on the side of the skin with yellowish patches and...",
- slug: "happy-diet"
- },
- {
- imageSrc: "https://user-images.githubusercontent.com/46085455/133185959-7ad75580-ca6d-4684-83d9-3f64500bbc97.png",
- title: "3",
- description: "Dragon fruit is a type of fruit that is a favorite for many people because of its delicious and fresh...",
- slug: "happy-diet"
- },
- {
- imageSrc: "https://user-images.githubusercontent.com/46085455/133186410-d8718d90-82fb-46cb-a0f2-0ec96356ae89.png",
- title: "4",
- description: "The DEBM diet stands for "+"Delicious Happy Fun Diet"+". This diet was popularized by Robert...",
- slug: "happy-diet"
- },
- {
- imageSrc: "https://user-images.githubusercontent.com/46085455/133186474-b2d89bbc-32ed-4174-a05e-3d388c0a39ff.png",
- title: "5",
- description: "Aloe vera or aloe vera is a green plant, has thorns on the side of the skin with yellowish patches and...",
- slug: "happy-diet"
- },
- {
- imageSrc: "https://user-images.githubusercontent.com/46085455/133186545-d860f4ee-222c-4d72-a876-808af0f397a0.png",
- title: "6",
- description: "Dragon fruit is a type of fruit that is a favorite for many people because of its delicious and fresh...",
- slug: "happy-diet"
- },
- {
- imageSrc: "https://user-images.githubusercontent.com/46085455/133185783-8100ef4e-7a72-4dc1-bb12-2ca46b56b393.png",
- title: "7",
- description: "The DEBM diet stands for "+"Delicious Happy Fun Diet"+". This diet was popularized by Robert...",
- slug: "happy-diet"
- },
- {
- imageSrc: "https://user-images.githubusercontent.com/46085455/133185911-df505d10-fdcd-4312-add3-7c62ad8af71e.png",
- title: "8",
- description: "Aloe vera or aloe vera is a green plant, has thorns on the side of the skin with yellowish patches and...",
- slug: "happy-diet"
- },
- {
- imageSrc: "https://user-images.githubusercontent.com/46085455/133185959-7ad75580-ca6d-4684-83d9-3f64500bbc97.png",
- title: "9",
- description: "Dragon fruit is a type of fruit that is a favorite for many people because of its delicious and fresh...",
- slug: "happy-diet"
- },
- {
- imageSrc: "https://user-images.githubusercontent.com/46085455/133186545-d860f4ee-222c-4d72-a876-808af0f397a0.png",
- title: "10",
- description: "Dragon fruit is a type of fruit that is a favorite for many people because of its delicious and fresh...",
- slug: "happy-diet"
- },
- {
- imageSrc: "https://user-images.githubusercontent.com/46085455/133186410-d8718d90-82fb-46cb-a0f2-0ec96356ae89.png",
- title: "11",
- description: "The DEBM diet stands for "+"Delicious Happy Fun Diet"+". This diet was popularized by Robert...",
- slug: "happy-diet"
- },
- {
- imageSrc: "https://user-images.githubusercontent.com/46085455/133186474-b2d89bbc-32ed-4174-a05e-3d388c0a39ff.png",
- title: "12",
- description: "Aloe vera or aloe vera is a green plant, has thorns on the side of the skin with yellowish patches and...",
- slug: "happy-diet"
- },
- {
- imageSrc: "https://user-images.githubusercontent.com/46085455/133185783-8100ef4e-7a72-4dc1-bb12-2ca46b56b393.png",
- title: "13",
- description: "The DEBM diet stands for "+"Delicious Happy Fun Diet"+". This diet was popularized by Robert...",
- slug: "happy-diet"
- },
- {
- imageSrc: "https://user-images.githubusercontent.com/46085455/133185911-df505d10-fdcd-4312-add3-7c62ad8af71e.png",
- title: "14",
- description: "Aloe vera or aloe vera is a green plant, has thorns on the side of the skin with yellowish patches and...",
- slug: "happy-diet"
- },
- {
- imageSrc: "https://user-images.githubusercontent.com/46085455/133185959-7ad75580-ca6d-4684-83d9-3f64500bbc97.png",
- title: "15",
- description: "Dragon fruit is a type of fruit that is a favorite for many people because of its delicious and fresh...",
- slug: "happy-diet"
- },
- {
- imageSrc: "https://user-images.githubusercontent.com/46085455/133186410-d8718d90-82fb-46cb-a0f2-0ec96356ae89.png",
- title: "16",
- description: "The DEBM diet stands for "+"Delicious Happy Fun Diet"+". This diet was popularized by Robert...",
- slug: "happy-diet"
- },
- {
- imageSrc: "https://user-images.githubusercontent.com/46085455/133186545-d860f4ee-222c-4d72-a876-808af0f397a0.png",
- title: "17",
- description: "Dragon fruit is a type of fruit that is a favorite for many people because of its delicious and fresh...",
- slug: "happy-diet"
- },
- {
- imageSrc: "https://user-images.githubusercontent.com/46085455/133186474-b2d89bbc-32ed-4174-a05e-3d388c0a39ff.png",
- title: "18",
- description: "Aloe vera or aloe vera is a green plant, has thorns on the side of the skin with yellowish patches and...",
- slug: "happy-diet"
- },
-
- ]
-const BlogsList = ({ data = BLOGSLIST_DATA }:BlogsListProps) => {
- const [currentPage, setCurrentPage] = useState(0)
+
+const BlogsList = ({ blogList,total,idFeatured }:BlogsListProps) => {
+
+ const DEFAULT_BLOGS_ARGS = useMemo(()=> ({
+ excludeBlogIds: [idFeatured],
+ options:{
+ skip: 1, take: DEFAULT_BLOG_PAGE_SIZE
+ }
+ }),[idFeatured]);
+
+
+ const router = useRouter();
+ const [initialQueryFlag, setInitialQueryFlag] = useState(true)
+
+ const [optionQueryBlog, setOptionQueryBlog] = useState(DEFAULT_BLOGS_ARGS)
+ const { blogs, totalItems, loading } = useGetBlogList(optionQueryBlog);
+
+
+
const onPageChange = (page:number) => {
- setCurrentPage(page)
+ router.push({
+ pathname: ROUTE.BLOGS,
+ query: {
+ ...router.query,
+ [QUERY_KEY.PAGE]: page
+ }
+ },
+ undefined, { shallow: true }
+ )
+ }
+
+ // skip
+ const firstRender = useRef(true);
+ useEffect(() => {
+ firstRender.current = false;
+ const query = { ...DEFAULT_BLOGS_ARGS } as QueryBlogs;
+ const page = getPageFromQuery(router.query[QUERY_KEY.PAGE] as string);
+ query.options.skip = page * DEFAULT_BLOG_PAGE_SIZE;
+ setOptionQueryBlog(query);
+ setInitialQueryFlag(false);
+ },[router.query])
+
+
+ let data;
+ if(initialQueryFlag == true){
+ data = blogList;
+ }else{
+ data = blogs
}
+
return (
)
}
-export default BlogsList
\ No newline at end of file
+export default BlogsList
+
+
diff --git a/src/components/modules/blogs/FeaturedCardBlog/FeaturedCardBlog.tsx b/src/components/modules/blogs/FeaturedCardBlog/FeaturedCardBlog.tsx
index ec90633d8..a7c7708f1 100644
--- a/src/components/modules/blogs/FeaturedCardBlog/FeaturedCardBlog.tsx
+++ b/src/components/modules/blogs/FeaturedCardBlog/FeaturedCardBlog.tsx
@@ -1,8 +1,10 @@
import s from './FeaturedCardBlog.module.scss'
import { Author, DateTime, ImgWithLink } from 'src/components/common'
-
+import Link from 'next/link'
+import { ROUTE } from 'src/utils/constanst.utils'
interface FeaturedCardBlogProps{
title?: string,
+ slug?:string,
content?: string,
imgSrc?: string,
imgAuthor?: string,
@@ -10,33 +12,31 @@ interface FeaturedCardBlogProps{
authorName?: string,
}
-const FEATURED_DATA = {
- title: "Flammekueche with green asparagus",
- content: "Traditionally, the Flammekueche is made with rapeseed oil, which, contrary to popular belief, is indeed an oil that can be cooked hot and is not limited to seasoning. It is important to vary the oils in the kitchen to take advantage of the benefits of each. Rapeseed oil is an oil rich in omega 3 which participate in the proper functioning of the cardiovascular system as well as in vitamins E which contributes to the protection of cells against oxidative stress. In short, oils are your friends 😉",
- imgSrc: "https://user-images.githubusercontent.com/46085455/133186666-1ea8081f-4319-4617-8644-d20ed14b1825.png",
- imgAuthor: "https://user-images.githubusercontent.com/46085455/133186783-d0c71d43-b7bc-44b6-b560-818c71bd162f.png",
- date: "APRIL 30, 2021",
- author: "Alessandro Del Piero"
-}
-
const FeaturedCardBlog = ({
- title = FEATURED_DATA.title,
- content = FEATURED_DATA.content,
- imgSrc = FEATURED_DATA.imgSrc,
- imgAuthor = FEATURED_DATA.imgAuthor,
- date = FEATURED_DATA.date,
- authorName = FEATURED_DATA.author
+ title,
+ slug,
+ content,
+ imgSrc = '',
+ imgAuthor = '',
+ date = '',
+ authorName = ''
}: FeaturedCardBlogProps) => {
return (