From 916c512bf5a31041ac87296e1382f84c9367b955 Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Mon, 14 Feb 2022 17:16:53 +0100
Subject: chore: display initial posts, thematics & topics

By fetching the data in getStaticProps, I can display the data even
for users with Javascript disabled.
---
 src/components/Widgets/TopicsList/TopicsList.tsx | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

(limited to 'src/components/Widgets/TopicsList/TopicsList.tsx')

diff --git a/src/components/Widgets/TopicsList/TopicsList.tsx b/src/components/Widgets/TopicsList/TopicsList.tsx
index e79d1a8..55bf5af 100644
--- a/src/components/Widgets/TopicsList/TopicsList.tsx
+++ b/src/components/Widgets/TopicsList/TopicsList.tsx
@@ -2,6 +2,7 @@ import Spinner from '@components/Spinner/Spinner';
 import { ExpandableWidget, List } from '@components/WidgetParts';
 import { getAllTopics } from '@services/graphql/queries';
 import { TitleLevel } from '@ts/types/app';
+import { TopicPreview } from '@ts/types/taxonomies';
 import Link from 'next/link';
 import { useRouter } from 'next/router';
 import { useIntl } from 'react-intl';
@@ -10,9 +11,11 @@ import useSWR from 'swr';
 const TopicsList = ({
   title,
   titleLevel,
+  initialData,
 }: {
   title: string;
   titleLevel?: TitleLevel;
+  initialData?: TopicPreview[];
 }) => {
   const intl = useIntl();
   const router = useRouter();
@@ -21,7 +24,9 @@ const TopicsList = ({
     ? router.asPath.replace('/sujet/', '')
     : '';
 
-  const { data, error } = useSWR('/api/topics', getAllTopics);
+  const { data, error } = useSWR('/api/topics', getAllTopics, {
+    fallbackData: initialData,
+  });
 
   const getList = () => {
     if (error)
@@ -62,12 +67,6 @@ const TopicsList = ({
       withBorders={true}
       expand={true}
     >
-      <noscript>
-        {intl.formatMessage({
-          defaultMessage: 'Javascript is required to load the topics.',
-          description: 'TopicsList: noscript tag',
-        })}
-      </noscript>
       {getList()}
     </ExpandableWidget>
   );
-- 
cgit v1.2.3

