aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/Widgets/RelatedTopics/RelatedTopics.tsx
blob: 1702e827dfd826fc0ea22394f91749383e44a874 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { ExpandableWidget, List } from '@components/WidgetParts';
import { TopicPreview } from '@ts/types/taxonomies';
import Link from 'next/link';
import { useIntl } from 'react-intl';

const RelatedTopics = ({ topics }: { topics: TopicPreview[] }) => {
  const intl = useIntl();
  const sortedTopics = [...topics].sort((a, b) =>
    a.title.localeCompare(b.title)
  );

  const topicsList = sortedTopics.map((topic) => {
    return (
      <li key={topic.databaseId}>
        <Link href={`/sujet/${topic.slug}`}>
          <a>{topic.title}</a>
        </Link>
      </li>
    );
  });

  return (
    <ExpandableWidget
      expand={true}
      title={intl.formatMessage(
        {
          defaultMessage:
            '{topicsCount, plural, =0 {Related topics} one {Related topic} other {Related topics}}',
          description: 'RelatedTopics: widget title',
        },
        { topicsCount: topicsList.length }
      )}
      withBorders={true}
    >
      <List items={topicsList} />
    </ExpandableWidget>
  );
};

export default RelatedTopics;