umami/components/WebsiteList.js

50 lines
1.3 KiB
JavaScript
Raw Normal View History

import React, { useState, useEffect } from 'react';
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';
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';
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>
{data &&
2020-08-04 03:12:28 +02:00
data.websites.map(({ website_id, label }) => (
<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}
>
{label}
</Link>
</h2>
2020-08-05 07:45:05 +02:00
<Link
href="/website/[...id]"
as={`/website/${website_id}/${label}`}
className={styles.details}
>
<Icon icon={<Arrow />} /> View details
2020-08-01 04:05:14 +02:00
</Link>
</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-08-06 04:04:02 +02:00
</Page>
);
}