aboutsummaryrefslogtreecommitdiffstats
path: root/src/pages/index.tsx
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2023-11-24 20:00:08 +0100
committerArmand Philippot <git@armandphilippot.com>2023-11-27 14:47:51 +0100
commitf111685c5886f3e77edfd3621c98d8ac1b9bcce4 (patch)
tree62a541fe3afeb64bf745443706fbfb02e96c5230 /src/pages/index.tsx
parentbee515641cb144be9a855ff2cac258d2fedab21d (diff)
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
Diffstat (limited to 'src/pages/index.tsx')
-rw-r--r--src/pages/index.tsx17
1 files changed, 11 insertions, 6 deletions
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<PageSectionProps> = ({
);
type HomeProps = {
- recentPosts: ArticleCard[];
+ recentPosts: RecentArticle[];
translation?: Messages;
};
@@ -277,7 +280,7 @@ const HomePage: NextPageWithLayout<HomeProps> = ({ recentPosts }) => {
hasBorderedValues
isCentered
label={publicationDate}
- value={<Time date={post.dates.publication} />}
+ value={<Time date={post.publicationDate} />}
/>
</CardMeta>
}
@@ -365,11 +368,13 @@ HomePage.getLayout = (page) => getLayout(page, { isHome: true });
export const getStaticProps: GetStaticProps<HomeProps> = async ({ locale }) => {
const translation = await loadTranslation(locale);
- const recentPosts = await getArticlesCard({ first: 3 });
+ const recentPosts = await fetchRecentPosts({ first: 3 });
return {
props: {
- recentPosts,
+ recentPosts: recentPosts.edges.map((edge) =>
+ convertRecentPostToRecentArticle(edge.node)
+ ),
translation,
},
};