From 395069f8cecd2deab2dfe1a2d7b97f379413e009 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Sun, 16 Jan 2022 14:18:54 +0100 Subject: chore: add a spinner when content is loading --- .../Widgets/ThematicsList/ThematicsList.tsx | 38 ++++++++++++++-------- 1 file changed, 24 insertions(+), 14 deletions(-) (limited to 'src/components/Widgets/ThematicsList/ThematicsList.tsx') diff --git a/src/components/Widgets/ThematicsList/ThematicsList.tsx b/src/components/Widgets/ThematicsList/ThematicsList.tsx index 8523bd1..e5162b4 100644 --- a/src/components/Widgets/ThematicsList/ThematicsList.tsx +++ b/src/components/Widgets/ThematicsList/ThematicsList.tsx @@ -1,3 +1,4 @@ +import Spinner from '@components/Spinner/Spinner'; import { ExpandableWidget, List } from '@components/WidgetParts'; import { t } from '@lingui/macro'; import { getAllThematics } from '@services/graphql/queries'; @@ -21,24 +22,33 @@ const ThematicsList = ({ const { data, error } = useSWR('/api/thematics', getAllThematics); - if (error) return
{t`Failed to load.`}
; - if (!data) return
{t`Loading...`}
; + const getList = () => { + if (error) return ; + if (!data) + return ( + + ); - const thematics = data.map((thematic) => { - return currentThematicSlug !== thematic.slug ? ( -
  • - - {thematic.title} - -
  • - ) : ( - '' - ); - }); + const thematics = data.map((thematic) => { + return currentThematicSlug !== thematic.slug ? ( +
  • + + {thematic.title} + +
  • + ) : ( + '' + ); + }); + + return ; + }; return ( - + {getList()} ); }; -- cgit v1.2.3