2020-07-28 10:17:45 +02:00
|
|
|
import React, { useState, useEffect } from 'react';
|
2020-08-04 08:20:35 +02:00
|
|
|
import Link from './Link';
|
2020-07-31 05:11:43 +02:00
|
|
|
import WebsiteChart from './WebsiteChart';
|
2020-08-06 04:04:02 +02:00
|
|
|
import Page from './Page';
|
2020-08-04 08:20:35 +02:00
|
|
|
import Icon from './Icon';
|
|
|
|
import { get } from 'lib/web';
|
|
|
|
import Arrow from 'assets/arrow-right.svg';
|
2020-07-30 08:25:52 +02:00
|
|
|
import styles from './WebsiteList.module.css';
|
2020-07-28 10:17:45 +02:00
|
|
|
|
|
|
|
export default function WebsiteList() {
|
|
|
|
const [data, setData] = useState();
|
|
|
|
|
|
|
|
async function loadData() {
|
|
|
|
setData(await get(`/api/website`));
|
|
|
|
}
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
loadData();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
2020-08-06 04:04:02 +02:00
|
|
|
<Page>
|
2020-07-28 10:17:45 +02:00
|
|
|
{data &&
|
2020-08-04 03:12:28 +02:00
|
|
|
data.websites.map(({ website_id, label }) => (
|
2020-08-04 08:20:35 +02:00
|
|
|
<div key={website_id} className={styles.website}>
|
|
|
|
<div className={styles.header}>
|
|
|
|
<h2>
|
2020-08-05 07:45:05 +02:00
|
|
|
<Link
|
|
|
|
href="/website/[...id]"
|
|
|
|
as={`/website/${website_id}/${label}`}
|
|
|
|
className={styles.title}
|
|
|
|
>
|
2020-08-04 08:20:35 +02:00
|
|
|
{label}
|
|
|
|
</Link>
|
|
|
|
</h2>
|
2020-08-05 07:45:05 +02:00
|
|
|
<Link
|
|
|
|
href="/website/[...id]"
|
|
|
|
as={`/website/${website_id}/${label}`}
|
|
|
|
className={styles.details}
|
|
|
|
>
|
2020-08-04 08:20:35 +02:00
|
|
|
<Icon icon={<Arrow />} /> View details
|
2020-08-01 04:05:14 +02:00
|
|
|
</Link>
|
2020-08-04 08:20:35 +02:00
|
|
|
</div>
|
2020-08-01 04:05:14 +02:00
|
|
|
<WebsiteChart key={website_id} title={label} websiteId={website_id} />
|
2020-08-02 06:20:52 +02:00
|
|
|
</div>
|
2020-07-28 10:17:45 +02:00
|
|
|
))}
|
2020-08-06 04:04:02 +02:00
|
|
|
</Page>
|
2020-07-28 10:17:45 +02:00
|
|
|
);
|
|
|
|
}
|