2022-08-04 21:30:09 +00:00
|
|
|
import { defineMessages, useIntl } from 'react-intl';
|
2020-10-02 00:32:49 +00:00
|
|
|
import Link from 'components/common/Link';
|
2020-08-21 20:43:42 +00:00
|
|
|
import WebsiteChart from 'components/metrics/WebsiteChart';
|
2020-08-12 05:24:41 +00:00
|
|
|
import Page from 'components/layout/Page';
|
|
|
|
|
import EmptyPlaceholder from 'components/common/EmptyPlaceholder';
|
2020-08-04 06:20:35 +00:00
|
|
|
import Arrow from 'assets/arrow-right.svg';
|
2020-07-30 06:25:52 +00:00
|
|
|
import styles from './WebsiteList.module.css';
|
2022-08-04 10:56:30 +00:00
|
|
|
import useDashboard from 'store/dashboard';
|
2022-07-24 06:02:47 +00:00
|
|
|
import { useMemo } from 'react';
|
2022-08-30 03:57:34 +00:00
|
|
|
import { firstBy } from 'thenby';
|
2022-07-24 06:02:47 +00:00
|
|
|
|
2022-08-04 21:30:09 +00:00
|
|
|
const messages = defineMessages({
|
|
|
|
|
noWebsites: {
|
|
|
|
|
id: 'message.no-websites-configured',
|
|
|
|
|
defaultMessage: "You don't have any websites configured.",
|
|
|
|
|
},
|
|
|
|
|
goToSettngs: {
|
|
|
|
|
id: 'message.go-to-settings',
|
|
|
|
|
defaultMessage: 'Go to settings',
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2022-08-05 04:37:18 +00:00
|
|
|
export default function WebsiteList({ websites, showCharts, limit }) {
|
2022-08-04 10:56:30 +00:00
|
|
|
const { websiteOrder } = useDashboard();
|
2022-08-04 21:30:09 +00:00
|
|
|
const { formatMessage } = useIntl();
|
2020-07-28 08:17:45 +00:00
|
|
|
|
2022-08-05 04:37:18 +00:00
|
|
|
const ordered = useMemo(
|
2022-08-30 03:57:34 +00:00
|
|
|
() =>
|
|
|
|
|
websites
|
2022-11-01 06:42:37 +00:00
|
|
|
.map(website => ({ ...website, order: websiteOrder.indexOf(website.id) || 0 }))
|
2022-08-30 03:57:34 +00:00
|
|
|
.sort(firstBy('order')),
|
2022-08-05 04:37:18 +00:00
|
|
|
[websites, websiteOrder],
|
|
|
|
|
);
|
2022-07-25 06:25:04 +00:00
|
|
|
|
2022-03-04 03:45:49 +00:00
|
|
|
if (websites.length === 0) {
|
2021-04-28 08:52:06 +00:00
|
|
|
return (
|
|
|
|
|
<Page>
|
2022-08-04 21:30:09 +00:00
|
|
|
<EmptyPlaceholder msg={formatMessage(messages.noWebsites)}>
|
2020-10-02 00:32:49 +00:00
|
|
|
<Link href="/settings" icon={<Arrow />} iconRight>
|
2022-08-04 21:30:09 +00:00
|
|
|
{formatMessage(messages.goToSettngs)}
|
2020-10-02 00:32:49 +00:00
|
|
|
</Link>
|
2020-08-11 02:54:03 +00:00
|
|
|
</EmptyPlaceholder>
|
2021-04-28 08:52:06 +00:00
|
|
|
</Page>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2022-08-04 10:56:30 +00:00
|
|
|
<div>
|
2022-11-01 06:42:37 +00:00
|
|
|
{ordered.map(({ id, name, domain }, index) =>
|
2022-08-04 10:56:30 +00:00
|
|
|
index < limit ? (
|
2022-11-01 06:42:37 +00:00
|
|
|
<div key={id} className={styles.website}>
|
2022-08-04 10:56:30 +00:00
|
|
|
<WebsiteChart
|
2022-11-01 06:42:37 +00:00
|
|
|
websiteId={id}
|
2022-08-04 10:56:30 +00:00
|
|
|
title={name}
|
|
|
|
|
domain={domain}
|
|
|
|
|
showChart={showCharts}
|
|
|
|
|
showLink
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
) : null,
|
2022-03-02 07:03:50 +00:00
|
|
|
)}
|
2022-03-04 03:45:49 +00:00
|
|
|
</div>
|
2020-07-28 08:17:45 +00:00
|
|
|
);
|
|
|
|
|
}
|