From f111685c5886f3e77edfd3621c98d8ac1b9bcce4 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Fri, 24 Nov 2023 20:00:08 +0100 Subject: refactor(services, types): reorganize GraphQL fetchers and data types The Typescript mapped types was useful for autocompletion in fetchers but their are harder to maintain. I think it's better to keep each query close to its fetcher to have a better understanding of the fetched data. So I: * colocate queries with their own fetcher * colocate mutations with their own mutator * remove Typescript mapped types for queries and mutations * move data convertors inside graphql services * rename most of data types and fetchers --- src/components/templates/page/page-comments.tsx | 10 +- src/pages/404.tsx | 37 ++- src/pages/article/[slug].tsx | 39 +-- src/pages/blog/index.tsx | 69 +++-- src/pages/blog/page/[number].tsx | 77 +++--- src/pages/index.tsx | 17 +- src/pages/projets/[slug].tsx | 4 +- src/pages/projets/index.tsx | 4 +- src/pages/recherche/index.tsx | 57 ++-- src/pages/sujet/[slug].tsx | 20 +- src/pages/thematique/[slug].tsx | 22 +- src/services/graphql/api.ts | 83 ------ src/services/graphql/articles.query.ts | 191 -------------- src/services/graphql/articles.ts | 201 -------------- src/services/graphql/comments.mutation.ts | 30 --- src/services/graphql/comments.query.ts | 32 --- src/services/graphql/comments.ts | 177 ------------- src/services/graphql/contact.mutation.ts | 25 -- src/services/graphql/contact.ts | 26 -- .../graphql/fetchers/comments/fetch-comments.ts | 65 +++++ src/services/graphql/fetchers/comments/index.ts | 1 + src/services/graphql/fetchers/index.ts | 4 + .../fetchers/posts/fetch-all-posts-slugs.ts | 34 +++ .../fetchers/posts/fetch-last-post-cursor.ts | 37 +++ src/services/graphql/fetchers/posts/fetch-post.ts | 92 +++++++ .../graphql/fetchers/posts/fetch-posts-count.ts | 43 +++ .../graphql/fetchers/posts/fetch-posts-list.ts | 97 +++++++ .../graphql/fetchers/posts/fetch-recent-posts.ts | 76 ++++++ src/services/graphql/fetchers/posts/index.ts | 6 + .../thematics/fetch-all-thematics-slugs.ts | 34 +++ .../graphql/fetchers/thematics/fetch-thematic.ts | 96 +++++++ .../fetchers/thematics/fetch-thematics-count.ts | 43 +++ .../fetchers/thematics/fetch-thematics-list.ts | 78 ++++++ src/services/graphql/fetchers/thematics/index.ts | 4 + .../fetchers/topics/fetch-all-topics-slugs.ts | 34 +++ .../graphql/fetchers/topics/fetch-topic.ts | 97 +++++++ .../graphql/fetchers/topics/fetch-topics-count.ts | 43 +++ .../graphql/fetchers/topics/fetch-topics-list.ts | 84 ++++++ src/services/graphql/fetchers/topics/index.ts | 4 + .../graphql/helpers/build-comments-tree.test.ts | 67 +++++ .../graphql/helpers/build-comments-tree.ts | 30 +++ ...convert-post-preview-to-article-preview.test.ts | 130 +++++++++ .../convert-post-preview-to-article-preview.ts | 36 +++ .../helpers/convert-post-to-article.test.ts | 125 +++++++++ .../graphql/helpers/convert-post-to-article.ts | 43 +++ .../convert-recent-post-to-recent-article.test.ts | 48 ++++ .../convert-recent-post-to-recent-article.ts | 24 ++ .../helpers/convert-taxonomy-to-page-link.test.ts | 52 ++++ .../helpers/convert-taxonomy-to-page-link.ts | 23 ++ .../helpers/convert-wp-comment-to-comment.test.ts | 93 +++++++ .../helpers/convert-wp-comment-to-comment.ts | 35 +++ .../helpers/convert-wp-image-to-img.test.ts | 41 +++ .../graphql/helpers/convert-wp-image-to-img.ts | 16 ++ src/services/graphql/helpers/index.ts | 7 + src/services/graphql/index.ts | 15 +- src/services/graphql/mutators/create-comment.ts | 70 +++++ src/services/graphql/mutators/index.ts | 2 + src/services/graphql/mutators/send-email.ts | 49 ++++ src/services/graphql/thematics.query.ts | 125 --------- src/services/graphql/thematics.ts | 157 ----------- src/services/graphql/topics.query.ts | 137 ---------- src/services/graphql/topics.ts | 154 ----------- src/types/app.ts | 102 -------- src/types/data.ts | 289 +++++++++++++++++++++ src/types/gql.ts | 73 ++++++ src/types/graphql/generics.ts | 25 -- src/types/graphql/index.ts | 3 - src/types/graphql/mutations.ts | 60 ----- src/types/graphql/queries.ts | 143 ---------- src/types/index.ts | 5 +- src/types/mdx.ts | 22 -- src/types/raw-data.ts | 111 -------- src/utils/helpers/author.ts | 31 --- src/utils/helpers/graphql.ts | 64 +++++ src/utils/helpers/images.ts | 17 -- src/utils/helpers/index.ts | 3 +- src/utils/helpers/pages.tsx | 83 +----- src/utils/helpers/rss.ts | 25 +- src/utils/helpers/server/projects.ts | 38 +-- src/utils/hooks/use-article.ts | 28 +- src/utils/hooks/use-comments.ts | 21 +- .../hooks/use-pagination/use-pagination.test.ts | 9 +- src/utils/hooks/use-pagination/use-pagination.ts | 17 +- .../hooks/use-posts-list/use-posts-list.test.ts | 4 +- src/utils/hooks/use-posts-list/use-posts-list.ts | 50 ++-- 85 files changed, 2579 insertions(+), 2216 deletions(-) delete mode 100644 src/services/graphql/api.ts delete mode 100644 src/services/graphql/articles.query.ts delete mode 100644 src/services/graphql/articles.ts delete mode 100644 src/services/graphql/comments.mutation.ts delete mode 100644 src/services/graphql/comments.query.ts delete mode 100644 src/services/graphql/comments.ts delete mode 100644 src/services/graphql/contact.mutation.ts delete mode 100644 src/services/graphql/contact.ts create mode 100644 src/services/graphql/fetchers/comments/fetch-comments.ts create mode 100644 src/services/graphql/fetchers/comments/index.ts create mode 100644 src/services/graphql/fetchers/index.ts create mode 100644 src/services/graphql/fetchers/posts/fetch-all-posts-slugs.ts create mode 100644 src/services/graphql/fetchers/posts/fetch-last-post-cursor.ts create mode 100644 src/services/graphql/fetchers/posts/fetch-post.ts create mode 100644 src/services/graphql/fetchers/posts/fetch-posts-count.ts create mode 100644 src/services/graphql/fetchers/posts/fetch-posts-list.ts create mode 100644 src/services/graphql/fetchers/posts/fetch-recent-posts.ts create mode 100644 src/services/graphql/fetchers/posts/index.ts create mode 100644 src/services/graphql/fetchers/thematics/fetch-all-thematics-slugs.ts create mode 100644 src/services/graphql/fetchers/thematics/fetch-thematic.ts create mode 100644 src/services/graphql/fetchers/thematics/fetch-thematics-count.ts create mode 100644 src/services/graphql/fetchers/thematics/fetch-thematics-list.ts create mode 100644 src/services/graphql/fetchers/thematics/index.ts create mode 100644 src/services/graphql/fetchers/topics/fetch-all-topics-slugs.ts create mode 100644 src/services/graphql/fetchers/topics/fetch-topic.ts create mode 100644 src/services/graphql/fetchers/topics/fetch-topics-count.ts create mode 100644 src/services/graphql/fetchers/topics/fetch-topics-list.ts create mode 100644 src/services/graphql/fetchers/topics/index.ts create mode 100644 src/services/graphql/helpers/build-comments-tree.test.ts create mode 100644 src/services/graphql/helpers/build-comments-tree.ts create mode 100644 src/services/graphql/helpers/convert-post-preview-to-article-preview.test.ts create mode 100644 src/services/graphql/helpers/convert-post-preview-to-article-preview.ts create mode 100644 src/services/graphql/helpers/convert-post-to-article.test.ts create mode 100644 src/services/graphql/helpers/convert-post-to-article.ts create mode 100644 src/services/graphql/helpers/convert-recent-post-to-recent-article.test.ts create mode 100644 src/services/graphql/helpers/convert-recent-post-to-recent-article.ts create mode 100644 src/services/graphql/helpers/convert-taxonomy-to-page-link.test.ts create mode 100644 src/services/graphql/helpers/convert-taxonomy-to-page-link.ts create mode 100644 src/services/graphql/helpers/convert-wp-comment-to-comment.test.ts create mode 100644 src/services/graphql/helpers/convert-wp-comment-to-comment.ts create mode 100644 src/services/graphql/helpers/convert-wp-image-to-img.test.ts create mode 100644 src/services/graphql/helpers/convert-wp-image-to-img.ts create mode 100644 src/services/graphql/helpers/index.ts create mode 100644 src/services/graphql/mutators/create-comment.ts create mode 100644 src/services/graphql/mutators/index.ts create mode 100644 src/services/graphql/mutators/send-email.ts delete mode 100644 src/services/graphql/thematics.query.ts delete mode 100644 src/services/graphql/thematics.ts delete mode 100644 src/services/graphql/topics.query.ts delete mode 100644 src/services/graphql/topics.ts create mode 100644 src/types/data.ts create mode 100644 src/types/gql.ts delete mode 100644 src/types/graphql/generics.ts delete mode 100644 src/types/graphql/index.ts delete mode 100644 src/types/graphql/mutations.ts delete mode 100644 src/types/graphql/queries.ts delete mode 100644 src/types/mdx.ts delete mode 100644 src/types/raw-data.ts delete mode 100644 src/utils/helpers/author.ts create mode 100644 src/utils/helpers/graphql.ts delete mode 100644 src/utils/helpers/images.ts (limited to 'src') diff --git a/src/components/templates/page/page-comments.tsx b/src/components/templates/page/page-comments.tsx index 170d6b7..5f5208f 100644 --- a/src/components/templates/page/page-comments.tsx +++ b/src/components/templates/page/page-comments.tsx @@ -6,8 +6,10 @@ import { useCallback, } from 'react'; import { useIntl } from 'react-intl'; -import { sendComment } from '../../../services/graphql'; -import type { SendCommentInput } from '../../../types'; +import { + createComment, + type CreateCommentInput, +} from '../../../services/graphql'; import { Heading, Link, Section } from '../../atoms'; import { Card, CardBody } from '../../molecules'; import { @@ -99,7 +101,7 @@ const PageCommentsWithRef: ForwardRefRenderFunction< const saveComment: CommentFormSubmit = useCallback( async (data) => { - const commentData: SendCommentInput = { + const commentData: CreateCommentInput = { author: data.author, authorEmail: data.email, authorUrl: data.website ?? '', @@ -108,7 +110,7 @@ const PageCommentsWithRef: ForwardRefRenderFunction< content: data.comment, parent: data.parentId, }; - const { comment, success } = await sendComment(commentData); + const { comment, success } = await createComment(commentData); const successPrefix = intl.formatMessage({ defaultMessage: 'Thanks, your comment was successfully sent.', description: 'PageComments: comment form success message', diff --git a/src/pages/404.tsx b/src/pages/404.tsx index d6785b6..5f4f89d 100644 --- a/src/pages/404.tsx +++ b/src/pages/404.tsx @@ -18,25 +18,26 @@ import { type SearchFormSubmit, } from '../components'; import { - getThematicsPreview, - getTopicsPreview, - getTotalThematics, - getTotalTopics, + convertTaxonomyToPageLink, + fetchThematicsCount, + fetchThematicsList, + fetchTopicsCount, + fetchTopicsList, } from '../services/graphql'; import type { NextPageWithLayout, - RawThematicPreview, - RawTopicPreview, + WPThematicPreview, + WPTopicPreview, } from '../types'; import { CONFIG } from '../utils/config'; import { ROUTES } from '../utils/constants'; -import { getLinksItemData, getPageLinkFromRawData } from '../utils/helpers'; +import { getLinksItemData } from '../utils/helpers'; import { loadTranslation, type Messages } from '../utils/helpers/server'; import { useBreadcrumb } from '../utils/hooks'; type Error404PageProps = { - thematicsList: RawThematicPreview[]; - topicsList: RawTopicPreview[]; + thematicsList: WPThematicPreview[]; + topicsList: WPTopicPreview[]; translation: Messages; }; @@ -146,11 +147,7 @@ const Error404Page: NextPageWithLayout = ({ {thematicsListTitle} } - items={getLinksItemData( - thematicsList.map((thematic) => - getPageLinkFromRawData(thematic, 'thematic') - ) - )} + items={getLinksItemData(thematicsList.map(convertTaxonomyToPageLink))} /> = ({ {topicsListTitle} } - items={getLinksItemData( - topicsList.map((topic) => getPageLinkFromRawData(topic, 'topic')) - )} + items={getLinksItemData(topicsList.map(convertTaxonomyToPageLink))} /> @@ -172,10 +167,10 @@ Error404Page.getLayout = (page) => getLayout(page); export const getStaticProps: GetStaticProps = async ({ locale, }) => { - const totalThematics = await getTotalThematics(); - const thematics = await getThematicsPreview({ first: totalThematics }); - const totalTopics = await getTotalTopics(); - const topics = await getTopicsPreview({ first: totalTopics }); + const totalThematics = await fetchThematicsCount(); + const thematics = await fetchThematicsList({ first: totalThematics }); + const totalTopics = await fetchTopicsCount(); + const topics = await fetchTopicsList({ first: totalTopics }); const translation = await loadTranslation(locale); return { diff --git a/src/pages/article/[slug].tsx b/src/pages/article/[slug].tsx index 224b1c5..f228ff0 100644 --- a/src/pages/article/[slug].tsx +++ b/src/pages/article/[slug].tsx @@ -21,9 +21,11 @@ import { TocWidget, } from '../../components'; import { - getAllArticlesSlugs, - getAllComments, - getArticleBySlug, + convertPostToArticle, + convertWPCommentToComment, + fetchAllPostsSlugs, + fetchCommentsList, + fetchPost, } from '../../services/graphql'; import styles from '../../styles/pages/article.module.scss'; import type { Article, NextPageWithLayout, SingleComment } from '../../types'; @@ -63,8 +65,11 @@ const ArticlePage: NextPageWithLayout = ({ const intl = useIntl(); const article = useArticle({ slug, fallback: post }); const commentsData = useComments({ - contentId: article?.id, fallback: comments, + first: article?.meta.commentsCount, + where: { + contentId: article?.id ?? post.id, + }, }); const getComments = (data?: SingleComment[]) => @@ -73,7 +78,7 @@ const ArticlePage: NextPageWithLayout = ({ author: comment.meta.author, content: comment.content, id: comment.id, - isApproved: comment.approved, + isApproved: comment.isApproved, publicationDate: comment.meta.date, replies: getComments(comment.replies), }; @@ -255,7 +260,7 @@ const ArticlePage: NextPageWithLayout = ({ heading={title} intro={intro} meta={{ - author: author?.name, + author, publicationDate: dates.publication, thematics, updateDate: dates.update, @@ -292,11 +297,7 @@ const ArticlePage: NextPageWithLayout = ({ ]} /> - + ); }; @@ -311,14 +312,20 @@ export const getStaticProps: GetStaticProps = async ({ locale, params, }) => { - const post = await getArticleBySlug((params as PostParams).slug); - const comments = await getAllComments({ contentId: post.id as number }); + const post = await fetchPost((params as PostParams).slug); + const article = await convertPostToArticle(post); + const comments = await fetchCommentsList({ + first: post.commentCount ?? 1, + where: { contentId: post.databaseId }, + }); const translation = await loadTranslation(locale); return { props: { - comments: JSON.parse(JSON.stringify(comments)), - post: JSON.parse(JSON.stringify(post)), + comments: JSON.parse( + JSON.stringify(comments.map(convertWPCommentToComment)) + ), + post: JSON.parse(JSON.stringify(article)), slug: post.slug, translation, }, @@ -326,7 +333,7 @@ export const getStaticProps: GetStaticProps = async ({ }; export const getStaticPaths: GetStaticPaths = async () => { - const slugs = await getAllArticlesSlugs(); + const slugs = await fetchAllPostsSlugs(); const paths = slugs.map((slug) => { return { params: { slug } }; }); diff --git a/src/pages/blog/index.tsx b/src/pages/blog/index.tsx index 0de5523..56cbb02 100644 --- a/src/pages/blog/index.tsx +++ b/src/pages/blog/index.tsx @@ -20,27 +20,28 @@ import { PageSidebar, } from '../../components'; import { - getArticles, - getThematicsPreview, - getTopicsPreview, - getTotalArticles, - getTotalThematics, - getTotalTopics, + convertTaxonomyToPageLink, + fetchPostsCount, + fetchPostsList, + fetchThematicsCount, + fetchThematicsList, + fetchTopicsCount, + fetchTopicsList, } from '../../services/graphql'; import styles from '../../styles/pages/blog.module.scss'; import type { - EdgesResponse, + GraphQLConnection, NextPageWithLayout, - RawArticle, - RawThematicPreview, - RawTopicPreview, + WPPostPreview, + WPThematicPreview, + WPTopicPreview, } from '../../types'; import { CONFIG } from '../../utils/config'; import { ROUTES } from '../../utils/constants'; import { getBlogSchema, getLinksItemData, - getPageLinkFromRawData, + getPostsWithUrl, getSchemaJson, getWebPageSchema, } from '../../utils/helpers'; @@ -48,9 +49,9 @@ import { loadTranslation, type Messages } from '../../utils/helpers/server'; import { useBreadcrumb, useIsMounted, usePostsList } from '../../utils/hooks'; type BlogPageProps = { - articles: EdgesResponse; - thematicsList: RawThematicPreview[]; - topicsList: RawTopicPreview[]; + posts: GraphQLConnection; + thematicsList: WPThematicPreview[]; + topicsList: WPTopicPreview[]; totalArticles: number; translation: Messages; }; @@ -59,7 +60,7 @@ type BlogPageProps = { * Blog index page. */ const BlogPage: NextPageWithLayout = ({ - articles, + posts, thematicsList, topicsList, totalArticles, @@ -111,6 +112,7 @@ const BlogPage: NextPageWithLayout = ({ const schemaJsonLd = getSchemaJson([webpageSchema, blogSchema]); const { + articles, error, firstNewResultIndex, isLoading, @@ -118,10 +120,9 @@ const BlogPage: NextPageWithLayout = ({ isRefreshing, hasNextPage, loadMore, - posts, } = usePostsList({ - fallback: [articles], - fetcher: getArticles, + fallback: [posts], + fetcher: fetchPostsList, perPage: CONFIG.postsPerPage, }); @@ -191,6 +192,10 @@ const BlogPage: NextPageWithLayout = ({ id: 'AXe1Iz', }); + const blogArticles = articles?.flatMap((p) => + p.edges.map((edge) => edge.node) + ); + return ( @@ -218,13 +223,13 @@ const BlogPage: NextPageWithLayout = ({ /> - {posts ? ( + {blogArticles ? ( = ({ {thematicsListTitle} } - items={getLinksItemData( - thematicsList.map((thematic) => - getPageLinkFromRawData(thematic, 'thematic') - ) - )} + items={getLinksItemData(thematicsList.map(convertTaxonomyToPageLink))} /> = ({ {topicsListTitle} } - items={getLinksItemData( - topicsList.map((topic) => getPageLinkFromRawData(topic, 'topic')) - )} + items={getLinksItemData(topicsList.map(convertTaxonomyToPageLink))} /> @@ -286,17 +285,17 @@ BlogPage.getLayout = (page) => getLayout(page); export const getStaticProps: GetStaticProps = async ({ locale, }) => { - const articles = await getArticles({ first: CONFIG.postsPerPage }); - const totalArticles = await getTotalArticles(); - const totalThematics = await getTotalThematics(); - const thematics = await getThematicsPreview({ first: totalThematics }); - const totalTopics = await getTotalTopics(); - const topics = await getTopicsPreview({ first: totalTopics }); + const posts = await fetchPostsList({ first: CONFIG.postsPerPage }); + const totalArticles = await fetchPostsCount(); + const totalThematics = await fetchThematicsCount(); + const thematics = await fetchThematicsList({ first: totalThematics }); + const totalTopics = await fetchTopicsCount(); + const topics = await fetchTopicsList({ first: totalTopics }); const translation = await loadTranslation(locale); return { props: { - articles: JSON.parse(JSON.stringify(articles)), + posts: JSON.parse(JSON.stringify(posts)), thematicsList: thematics.edges.map((edge) => edge.node), topicsList: topics.edges.map((edge) => edge.node), totalArticles, diff --git a/src/pages/blog/page/[number].tsx b/src/pages/blog/page/[number].tsx index b254603..d6071d1 100644 --- a/src/pages/blog/page/[number].tsx +++ b/src/pages/blog/page/[number].tsx @@ -20,27 +20,28 @@ import { PageSidebar, } from '../../../components'; import { - getArticles, - getArticlesEndCursor, - getThematicsPreview, - getTopicsPreview, - getTotalArticles, - getTotalThematics, - getTotalTopics, + convertTaxonomyToPageLink, + fetchLastPostCursor, + fetchPostsCount, + fetchPostsList, + fetchThematicsCount, + fetchThematicsList, + fetchTopicsCount, + fetchTopicsList, } from '../../../services/graphql'; import type { - EdgesResponse, + GraphQLConnection, NextPageWithLayout, - RawArticle, - RawThematicPreview, - RawTopicPreview, + WPPostPreview, + WPThematicPreview, + WPTopicPreview, } from '../../../types'; import { CONFIG } from '../../../utils/config'; import { ROUTES } from '../../../utils/constants'; import { getBlogSchema, getLinksItemData, - getPageLinkFromRawData, + getPostsWithUrl, getSchemaJson, getWebPageSchema, } from '../../../utils/helpers'; @@ -52,10 +53,10 @@ import { } from '../../../utils/hooks'; type BlogPageProps = { - articles: EdgesResponse; pageNumber: number; - thematicsList: RawThematicPreview[]; - topicsList: RawTopicPreview[]; + posts: GraphQLConnection; + thematicsList: WPThematicPreview[]; + topicsList: WPTopicPreview[]; totalArticles: number; translation: Messages; }; @@ -64,8 +65,8 @@ type BlogPageProps = { * Blog index page. */ const BlogPage: NextPageWithLayout = ({ - articles, pageNumber, + posts, thematicsList, topicsList, totalArticles, @@ -75,9 +76,9 @@ const BlogPage: NextPageWithLayout = ({ redirectTo: ROUTES.BLOG, }); - const { posts } = usePostsList({ - fallback: [articles], - fetcher: getArticles, + const { articles } = usePostsList({ + fallback: [posts], + fetcher: fetchPostsList, perPage: CONFIG.postsPerPage, }); const intl = useIntl(); @@ -195,6 +196,10 @@ const BlogPage: NextPageWithLayout = ({ id: 'AXe1Iz', }); + const blogPageArticles = articles?.flatMap((p) => + p.edges.map((edge) => edge.node) + ); + return ( @@ -225,7 +230,7 @@ const BlogPage: NextPageWithLayout = ({ meta={{ total: totalArticles }} /> - + = ({ {thematicsListTitle} } - items={getLinksItemData( - thematicsList.map((thematic) => - getPageLinkFromRawData(thematic, 'thematic') - ) - )} + items={getLinksItemData(thematicsList.map(convertTaxonomyToPageLink))} /> = ({ {topicsListTitle} } - items={getLinksItemData( - topicsList.map((topic) => getPageLinkFromRawData(topic, 'topic')) - )} + items={getLinksItemData(topicsList.map(convertTaxonomyToPageLink))} /> @@ -274,23 +273,23 @@ export const getStaticProps: GetStaticProps = async ({ params, }) => { const pageNumber = Number((params as BlogPageParams).number); - const lastCursor = await getArticlesEndCursor({ - first: CONFIG.postsPerPage * pageNumber, - }); - const articles = await getArticles({ + const lastCursor = await fetchLastPostCursor( + CONFIG.postsPerPage * pageNumber + ); + const posts = await fetchPostsList({ first: CONFIG.postsPerPage, after: lastCursor, }); - const totalArticles = await getTotalArticles(); - const totalThematics = await getTotalThematics(); - const thematics = await getThematicsPreview({ first: totalThematics }); - const totalTopics = await getTotalTopics(); - const topics = await getTopicsPreview({ first: totalTopics }); + const totalArticles = await fetchPostsCount(); + const totalThematics = await fetchThematicsCount(); + const thematics = await fetchThematicsList({ first: totalThematics }); + const totalTopics = await fetchTopicsCount(); + const topics = await fetchTopicsList({ first: totalTopics }); const translation = await loadTranslation(locale); return { props: { - articles: JSON.parse(JSON.stringify(articles)), + posts: JSON.parse(JSON.stringify(posts)), pageNumber, thematicsList: thematics.edges.map((edge) => edge.node), topicsList: topics.edges.map((edge) => edge.node), @@ -301,7 +300,7 @@ export const getStaticProps: GetStaticProps = async ({ }; export const getStaticPaths: GetStaticPaths = async () => { - const totalArticles = await getTotalArticles(); + const totalArticles = await fetchPostsCount(); const totalPages = Math.ceil(totalArticles / CONFIG.postsPerPage); const pagesArray = Array.from( { length: totalPages }, diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 56de5b5..7bd8aec 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -26,9 +26,12 @@ import { } from '../components'; import { mdxComponents } from '../components/mdx'; import HomePageContent from '../content/pages/homepage.mdx'; -import { getArticlesCard } from '../services/graphql'; +import { + convertRecentPostToRecentArticle, + fetchRecentPosts, +} from '../services/graphql'; import styles from '../styles/pages/home.module.scss'; -import type { ArticleCard, NextPageWithLayout } from '../types'; +import type { NextPageWithLayout, RecentArticle } from '../types'; import { CONFIG } from '../utils/config'; import { PERSONAL_LINKS, ROUTES } from '../utils/constants'; import { getSchemaJson, getWebPageSchema } from '../utils/helpers'; @@ -229,7 +232,7 @@ const HomePageSection: FC = ({ ); type HomeProps = { - recentPosts: ArticleCard[]; + recentPosts: RecentArticle[]; translation?: Messages; }; @@ -277,7 +280,7 @@ const HomePage: NextPageWithLayout = ({ recentPosts }) => { hasBorderedValues isCentered label={publicationDate} - value={