aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/Widgets/TopicsList
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2022-01-16 14:18:54 +0100
committerArmand Philippot <git@armandphilippot.com>2022-01-16 14:24:08 +0100
commit395069f8cecd2deab2dfe1a2d7b97f379413e009 (patch)
tree8063ff201967b321295815114442ade486527ba3 /src/components/Widgets/TopicsList
parente63d74d4147e66ec79c287b7c3fda0dadc139275 (diff)
chore: add a spinner when content is loading
Diffstat (limited to 'src/components/Widgets/TopicsList')
-rw-r--r--src/components/Widgets/TopicsList/TopicsList.tsx38
1 files changed, 24 insertions, 14 deletions
diff --git a/src/components/Widgets/TopicsList/TopicsList.tsx b/src/components/Widgets/TopicsList/TopicsList.tsx
index 5bf12b9..c7843b7 100644
--- a/src/components/Widgets/TopicsList/TopicsList.tsx
+++ b/src/components/Widgets/TopicsList/TopicsList.tsx
@@ -1,3 +1,4 @@
+import Spinner from '@components/Spinner/Spinner';
import { ExpandableWidget, List } from '@components/WidgetParts';
import { t } from '@lingui/macro';
import { getAllSubjects } from '@services/graphql/queries';
@@ -21,24 +22,33 @@ const TopicsList = ({
const { data, error } = useSWR('/api/subjects', getAllSubjects);
- if (error) return <div>{t`Failed to load.`}</div>;
- if (!data) return <div>{t`Loading...`}</div>;
+ const getList = () => {
+ if (error) return <ul>{t`Failed to load.`}</ul>;
+ if (!data)
+ return (
+ <ul>
+ <Spinner />
+ </ul>
+ );
- const subjects = data.map((subject) => {
- return currentTopicSlug !== subject.slug ? (
- <li key={subject.databaseId}>
- <Link href={`/sujet/${subject.slug}`}>
- <a>{subject.title}</a>
- </Link>
- </li>
- ) : (
- ''
- );
- });
+ const subjects = data.map((subject) => {
+ return currentTopicSlug !== subject.slug ? (
+ <li key={subject.databaseId}>
+ <Link href={`/sujet/${subject.slug}`}>
+ <a>{subject.title}</a>
+ </Link>
+ </li>
+ ) : (
+ ''
+ );
+ });
+
+ return <List items={subjects} />;
+ };
return (
<ExpandableWidget title={title} titleLevel={titleLevel} withBorders={true}>
- <List items={subjects} />
+ {getList()}
</ExpandableWidget>
);
};