umami/components/pages/websites/WebsiteChartList.js

36 lines
974 B
JavaScript
Raw Normal View History

import { useMemo } from 'react';
import { firstBy } from 'thenby';
2023-02-02 03:39:54 +01:00
import WebsiteChart from 'components/metrics/WebsiteChart';
import useDashboard from 'store/dashboard';
import styles from './WebsiteList.module.css';
2023-02-02 03:39:54 +01:00
export default function WebsiteChartList({ websites, showCharts, limit }) {
2022-08-04 12:56:30 +02:00
const { websiteOrder } = useDashboard();
2022-08-05 06:37:18 +02:00
const ordered = useMemo(
() =>
websites
2022-11-01 07:42:37 +01:00
.map(website => ({ ...website, order: websiteOrder.indexOf(website.id) || 0 }))
.sort(firstBy('order')),
2022-08-05 06:37:18 +02:00
[websites, websiteOrder],
);
return (
2022-08-04 12:56:30 +02:00
<div>
2023-02-02 03:39:54 +01:00
{ordered.map(({ id, name, domain }, index) => {
return index < limit ? (
2022-11-01 07:42:37 +01:00
<div key={id} className={styles.website}>
2022-08-04 12:56:30 +02:00
<WebsiteChart
2022-11-01 07:42:37 +01:00
websiteId={id}
2022-08-04 12:56:30 +02:00
title={name}
domain={domain}
showChart={showCharts}
2023-02-02 03:39:54 +01:00
showDetailsButton={true}
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>
);
}