aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/PostFooter/PostFooter.tsx
blob: 6c97ec22a63e37e751f3eb9a7403f7d1e6cce722 (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
41
42
43
44
45
46
47
48
49
50
51
52
import { ButtonLink } from '@components/Buttons';
import { TopicPreview } from '@ts/types/taxonomies';
import Image from 'next/image';
import { useIntl } from 'react-intl';
import styles from './PostFooter.module.scss';

const PostFooter = ({ topics }: { topics: TopicPreview[] }) => {
  const intl = useIntl();

  const getTopics = () => {
    return topics.map((topic) => {
      return (
        <li className={styles.item} key={topic.id}>
          <ButtonLink target={`/sujet/${topic.slug}`}>
            {topic.featuredImage && (
              <Image
                src={topic.featuredImage.sourceUrl}
                alt={topic.featuredImage.altText}
                layout="intrinsic"
                width="20"
                height="20"
              />
            )}
            {topic.title}
          </ButtonLink>
        </li>
      );
    });
  };

  return (
    <footer>
      {topics.length > 0 && (
        <>
          <dl className={styles.meta}>
            <dt>
              {intl.formatMessage({
                defaultMessage: 'Read more articles about:',
                description: 'PostFooter: read more posts about given subjects',
              })}
            </dt>
            <dd>
              <ul className={styles.list}>{getTopics()}</ul>
            </dd>
          </dl>
        </>
      )}
    </footer>
  );
};

export default PostFooter;