summaryrefslogtreecommitdiffstats
path: root/src/components/Widget/ThematicsList/ThematicsList.tsx
blob: 232515d507d8c57d81c7e59e00597941cc1b406d (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
import { t } from '@lingui/macro';
import { getAllThematics } from '@services/graphql/queries';
import { ThematicPreview } from '@ts/types/taxonomies';
import Link from 'next/link';
import useSWR from 'swr';
import styles from './ThematicsList.module.scss';

const ThematicsList = () => {
  const { data, error } = useSWR('/api/thematics', getAllThematics);

  if (error) return <div>{t`Failed to load.`}</div>;
  if (!data) return <div>{t`Loading...`}</div>;

  const sortedThematics = [...data].sort((a, b) =>
    a.title.localeCompare(b.title)
  );

  const thematics = sortedThematics.map((thematic) => {
    return (
      <li key={thematic.databaseId}>
        <Link href={`/thematique/${thematic.slug}`}>
          <a>{thematic.title}</a>
        </Link>
      </li>
    );
  });

  return (
    <div>
      <h2 className={styles.title}>{t`Thematics`}</h2>
      <ul className={styles.list}>{thematics}</ul>
    </div>
  );
};

export default ThematicsList;
t .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
import { ComponentMeta, ComponentStory } from '@storybook/react';
import { IntlProvider } from 'react-intl';
import Branding from './branding';

/**
 * Branding - Storybook Meta
 */
export default {
  title: 'Molecules/Layout/Branding',
  component: Branding,
  args: {
    isHome: false,
  },
  argTypes: {
    baseline: {
      control: {
        type: 'text',
      },
      description: 'The Branding baseline.',
      type: {
        name: 'string',
        required: false,
      },
    },
    isHome: {
      control: {
        type: 'boolean',
      },
      description: 'Use H1 if the current page is homepage.',
      table: {
        category: 'Options',
        defaultValue: { summary: false },
      },
      type: {
        name: 'boolean',
        required: false,
      },
    },
    photo: {
      control: {
        type: 'text',
      },
      description: 'The Branding photo.',
      type: {
        name: 'string',
        required: true,
      },
    },
    title: {
      control: {
        type: 'text',
      },
      description: 'The Branding title.',
      type: {
        name: 'string',
        required: true,
      },
    },
    unoptimized: { table: { disable: true } },
    withLink: {
      control: {
        type: 'boolean',
      },
      description: 'Wraps the title with a link to homepage.',
      table: {
        category: 'Options',
        defaultValue: { summary: false },
      },
      type: {
        name: 'boolean',
        required: false,
      },
    },
  },
  decorators: [
    (Story) => (
      <IntlProvider locale="en">
        <Story />
      </IntlProvider>
    ),
  ],
} as ComponentMeta<typeof Branding>;

const Template: ComponentStory<typeof Branding> = (args) => (
  <Branding {...args} />
);

/**
 * Branding Stories - Default
 */
export const Default = Template.bind({});
Default.args = {
  title: 'Website title',
  photo: 'http://placeimg.com/640/480',
  // @ts-ignore - Needed because of the placeholder image.
  unoptimized: true,
};

/**
 * Branding Stories - With baseline
 */
export const WithBaseline = Template.bind({});
WithBaseline.args = {
  title: 'Website title',
  baseline: 'Maiores corporis qui',
  photo: 'http://placeimg.com/640/480',
  // @ts-ignore - Needed because of the placeholder image.
  unoptimized: true,
};