mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-15 17:55:08 +01:00
51 lines
1.5 KiB
JavaScript
51 lines
1.5 KiB
JavaScript
import { useState } from 'react';
|
|
import { Icons, Loading } from 'react-basics';
|
|
import { useIntl } from 'react-intl';
|
|
import Link from 'next/link';
|
|
import classNames from 'classnames';
|
|
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';
|
|
import WebsiteTableView from './WebsiteTableView';
|
|
import WebsiteMenuView from './WebsiteMenuView';
|
|
|
|
export default function WebsiteDetails({ websiteId }) {
|
|
const { get, useQuery } = useApi();
|
|
const { data, isLoading, error } = useQuery(['websites', websiteId], () =>
|
|
get(`/websites/${websiteId}`),
|
|
);
|
|
const [chartLoaded, setChartLoaded] = useState(false);
|
|
|
|
const {
|
|
query: { view },
|
|
} = usePageQuery();
|
|
|
|
function handleDataLoad() {
|
|
if (!chartLoaded) {
|
|
setTimeout(() => setChartLoaded(true), DEFAULT_ANIMATION_DURATION);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<Page loading={isLoading} error={error}>
|
|
<WebsiteChart
|
|
websiteId={websiteId}
|
|
title={data?.name}
|
|
domain={data?.domain}
|
|
onDataLoad={handleDataLoad}
|
|
showLink={false}
|
|
stickyHeader={true}
|
|
/>
|
|
{!chartLoaded && <Loading icon="dots" />}
|
|
{chartLoaded && (
|
|
<>
|
|
{!view && <WebsiteTableView websiteId={websiteId} />}
|
|
{view && <WebsiteMenuView websiteId={websiteId} />}
|
|
</>
|
|
)}
|
|
</Page>
|
|
);
|
|
}
|