umami/components/pages/websites/WebsiteDetails.js

69 lines
2.0 KiB
JavaScript
Raw Normal View History

2023-02-04 17:59:52 +01:00
import { useState } from 'react';
import { Icons, Loading } from 'react-basics';
import { useIntl } from 'react-intl';
import Link from 'next/link';
2020-08-01 04:05:14 +02:00
import classNames from 'classnames';
2020-08-12 07:24:41 +02:00
import MenuLayout from 'components/layout/MenuLayout';
import Page from 'components/layout/Page';
import WebsiteChart from 'components/metrics/WebsiteChart';
import useApi from 'hooks/useApi';
import usePageQuery from 'hooks/usePageQuery';
import { DEFAULT_ANIMATION_DURATION } from 'lib/constants';
2023-02-04 17:59:52 +01:00
import { labels, messages } from 'components/messages';
2022-03-02 06:13:15 +01:00
import styles from './WebsiteDetails.module.css';
2023-02-04 17:59:52 +01:00
import WebsiteTableView from './WebsiteTableView';
import WebsiteMenuView from './WebsiteMenuView';
2020-10-11 11:29:55 +02:00
export default function WebsiteDetails({ websiteId }) {
2023-02-04 17:59:52 +01:00
const { formatMessage } = useIntl();
const { get, useQuery } = useApi();
2023-02-04 17:59:52 +01:00
const { data, isLoading, error } = useQuery(['websites', websiteId], () =>
get(`/websites/${websiteId}`),
);
const [chartLoaded, setChartLoaded] = useState(false);
2023-02-04 17:59:52 +01:00
const {
2020-09-26 07:31:18 +02:00
resolve,
query: { view },
} = usePageQuery();
const BackButton = () => (
2022-02-17 08:10:35 +01:00
<div key="back-button" className={classNames(styles.backButton, 'col-12')}>
2023-01-31 06:44:07 +01:00
<Link
key="back-button"
href={resolve({ view: undefined })}
icon={<Icons.ArrowRight />}
sizes="small"
>
2023-02-04 17:59:52 +01:00
{formatMessage(labels.back)}
2020-09-29 07:12:48 +02:00
</Link>
</div>
);
function handleDataLoad() {
2020-08-31 23:11:30 +02:00
if (!chartLoaded) {
2020-10-10 05:37:24 +02:00
setTimeout(() => setChartLoaded(true), DEFAULT_ANIMATION_DURATION);
2020-08-31 23:11:30 +02:00
}
2020-08-01 04:05:14 +02:00
}
return (
2023-02-04 17:59:52 +01:00
<Page loading={isLoading} error={error}>
2022-12-10 23:26:52 +01:00
<WebsiteChart
websiteId={websiteId}
2023-02-04 17:59:52 +01:00
title={data?.name}
domain={data?.domain}
2022-12-10 23:26:52 +01:00
onDataLoad={handleDataLoad}
showLink={false}
stickyHeader
/>
2023-02-04 17:59:52 +01:00
{!chartLoaded && <Loading icon="dots" />}
{chartLoaded && (
<>
2023-02-04 17:59:52 +01:00
{!view && <WebsiteTableView websiteId={websiteId} />}
{view && <WebsiteMenuView websiteId={websiteId} />}
</>
)}
2020-08-06 04:04:02 +02:00
</Page>
2020-08-01 04:05:14 +02:00
);
}