summaryrefslogtreecommitdiffstats
path: root/src/pages
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2022-01-25 11:45:11 +0100
committerArmand Philippot <git@armandphilippot.com>2022-01-25 11:45:11 +0100
commit82702fbe2d0607e7ca8a02c878b2e79a21664b7c (patch)
tree2388abb10f8ec41ea4a20058f122cb0e7bcae9ef /src/pages
parent958569e09071e4bb290f0ec120b4309ae5983d2d (diff)
chore: display total found posts in page meta
Diffstat (limited to 'src/pages')
-rw-r--r--src/pages/blog/index.tsx9
-rw-r--r--src/pages/recherche/index.tsx7
-rw-r--r--src/pages/sujet/[slug].tsx1
-rw-r--r--src/pages/thematique/[slug].tsx1
4 files changed, 15 insertions, 3 deletions
diff --git a/src/pages/blog/index.tsx b/src/pages/blog/index.tsx
index 3b3f2c2..bd27c75 100644
--- a/src/pages/blog/index.tsx
+++ b/src/pages/blog/index.tsx
@@ -15,7 +15,7 @@ import PostHeader from '@components/PostHeader/PostHeader';
import { ThematicsList, TopicsList } from '@components/Widgets';
import Sidebar from '@components/Sidebar/Sidebar';
import styles from '@styles/pages/Page.module.scss';
-import { useRef } from 'react';
+import { useEffect, useRef, useState } from 'react';
import Spinner from '@components/Spinner/Spinner';
import { Blog as BlogSchema, Graph, WebPage } from 'schema-dts';
import { useRouter } from 'next/router';
@@ -40,6 +40,11 @@ const Blog: NextPageWithLayout<BlogPageProps> = ({ fallback }) => {
getPublishedPosts,
{ fallback }
);
+ const [totalPostsCount, setTotalPostsCount] = useState<number>(0);
+
+ useEffect(() => {
+ if (data) setTotalPostsCount(data[0].pageInfo.total);
+ }, [data]);
const isLoadingInitialData = !data && !error;
const isLoadingMore: boolean =
@@ -113,7 +118,7 @@ const Blog: NextPageWithLayout<BlogPageProps> = ({ fallback }) => {
id="blog"
className={`${styles.article} ${styles['article--no-comments']}`}
>
- <PostHeader title={title} />
+ <PostHeader title={title} meta={{ results: totalPostsCount }} />
<div className={styles.body}>
{getPostsList()}
{hasNextPage && (
diff --git a/src/pages/recherche/index.tsx b/src/pages/recherche/index.tsx
index 647d049..771bd3b 100644
--- a/src/pages/recherche/index.tsx
+++ b/src/pages/recherche/index.tsx
@@ -47,6 +47,11 @@ const Search: NextPageWithLayout = () => {
getKey,
getPublishedPosts
);
+ const [totalPostsCount, setTotalPostsCount] = useState<number>(0);
+
+ useEffect(() => {
+ if (data) setTotalPostsCount(data[0].pageInfo.total);
+ }, [data]);
const isLoadingInitialData = !data && !error;
const isLoadingMore: boolean =
@@ -95,7 +100,7 @@ const Search: NextPageWithLayout = () => {
<article
className={`${styles.article} ${styles['article--no-comments']}`}
>
- <PostHeader title={title} />
+ <PostHeader title={title} meta={{ results: totalPostsCount }} />
<div className={styles.body}>
{getPostsList()}
{hasNextPage && (
diff --git a/src/pages/sujet/[slug].tsx b/src/pages/sujet/[slug].tsx
index ba65a27..028131b 100644
--- a/src/pages/sujet/[slug].tsx
+++ b/src/pages/sujet/[slug].tsx
@@ -47,6 +47,7 @@ const Topic: NextPageWithLayout<TopicProps> = ({ topic }) => {
const meta: ArticleMeta = {
dates: topic.dates,
+ results: topic.posts.length,
website: topic.officialWebsite,
};
const topicUrl = `${config.url}${router.asPath}`;
diff --git a/src/pages/thematique/[slug].tsx b/src/pages/thematique/[slug].tsx
index c76831d..75f33ff 100644
--- a/src/pages/thematique/[slug].tsx
+++ b/src/pages/thematique/[slug].tsx
@@ -50,6 +50,7 @@ const Thematic: NextPageWithLayout<ThematicProps> = ({ thematic }) => {
const meta: ArticleMeta = {
dates: thematic.dates,
+ results: thematic.posts.length,
};
const thematicUrl = `${config.url}${router.asPath}`;