2023-07-10 13:35:19 +02:00
|
|
|
import { Button, Text, Icon } from 'react-basics';
|
2022-07-24 08:02:47 +02:00
|
|
|
import { useMemo } from 'react';
|
2022-08-30 05:57:34 +02:00
|
|
|
import { firstBy } from 'thenby';
|
2023-07-10 13:35:19 +02:00
|
|
|
import Link from 'next/link';
|
|
|
|
import WebsiteChart from 'components/pages/websites/WebsiteChart';
|
2023-02-02 03:39:54 +01:00
|
|
|
import useDashboard from 'store/dashboard';
|
|
|
|
import styles from './WebsiteList.module.css';
|
2023-07-10 13:35:19 +02:00
|
|
|
import WebsiteHeader from './WebsiteHeader';
|
|
|
|
import { WebsiteMetricsBar } from './WebsiteMetricsBar';
|
|
|
|
import { useMessages, useLocale } from 'hooks';
|
|
|
|
import Icons from 'components/icons';
|
2022-07-24 08:02:47 +02:00
|
|
|
|
2023-02-02 03:39:54 +01:00
|
|
|
export default function WebsiteChartList({ websites, showCharts, limit }) {
|
2023-07-10 13:35:19 +02:00
|
|
|
const { formatMessage, labels } = useMessages();
|
2022-08-04 12:56:30 +02:00
|
|
|
const { websiteOrder } = useDashboard();
|
2023-07-10 13:35:19 +02:00
|
|
|
const { dir } = useLocale();
|
2020-07-28 10:17:45 +02:00
|
|
|
|
2022-08-05 06:37:18 +02:00
|
|
|
const ordered = useMemo(
|
2022-08-30 05:57:34 +02:00
|
|
|
() =>
|
|
|
|
websites
|
2022-11-01 07:42:37 +01:00
|
|
|
.map(website => ({ ...website, order: websiteOrder.indexOf(website.id) || 0 }))
|
2022-08-30 05:57:34 +02:00
|
|
|
.sort(firstBy('order')),
|
2022-08-05 06:37:18 +02:00
|
|
|
[websites, websiteOrder],
|
|
|
|
);
|
2022-07-25 08:25:04 +02:00
|
|
|
|
2021-04-28 10:52:06 +02:00
|
|
|
return (
|
2022-08-04 12:56:30 +02:00
|
|
|
<div>
|
2023-07-10 13:35:19 +02:00
|
|
|
{ordered.map(({ id }, index) => {
|
2023-02-02 03:39:54 +01:00
|
|
|
return index < limit ? (
|
2022-11-01 07:42:37 +01:00
|
|
|
<div key={id} className={styles.website}>
|
2023-07-10 13:35:19 +02:00
|
|
|
<WebsiteHeader websiteId={id} showLinks={false}>
|
|
|
|
<Link href={`/websites/${id}`}>
|
|
|
|
<Button variant="primary">
|
|
|
|
<Text>{formatMessage(labels.viewDetails)}</Text>
|
|
|
|
<Icon>
|
|
|
|
<Icon rotate={dir === 'rtl' ? 180 : 0}>
|
|
|
|
<Icons.ArrowRight />
|
|
|
|
</Icon>
|
|
|
|
</Icon>
|
|
|
|
</Button>
|
|
|
|
</Link>
|
|
|
|
</WebsiteHeader>
|
|
|
|
<WebsiteMetricsBar websiteId={id} />
|
|
|
|
<WebsiteChart websiteId={id} showChart={showCharts} />
|
2022-08-04 12:56:30 +02:00
|
|
|
</div>
|
2023-02-02 03:39:54 +01:00
|
|
|
) : null;
|
|
|
|
})}
|
2022-03-04 04:45:49 +01:00
|
|
|
</div>
|
2020-07-28 10:17:45 +02:00
|
|
|
);
|
|
|
|
}
|