2023-02-04 16:59:52 +00:00
|
|
|
import { useState } from 'react';
|
2023-03-03 20:37:26 +00:00
|
|
|
import { Loading } from 'react-basics';
|
2023-01-06 03:39:29 +00:00
|
|
|
import Page from 'components/layout/Page';
|
|
|
|
|
import WebsiteChart from 'components/metrics/WebsiteChart';
|
2022-12-28 23:43:22 +00:00
|
|
|
import useApi from 'hooks/useApi';
|
2023-01-06 03:39:29 +00:00
|
|
|
import usePageQuery from 'hooks/usePageQuery';
|
2022-05-06 02:04:28 +00:00
|
|
|
import { DEFAULT_ANIMATION_DURATION } from 'lib/constants';
|
2023-02-04 16:59:52 +00:00
|
|
|
import WebsiteTableView from './WebsiteTableView';
|
|
|
|
|
import WebsiteMenuView from './WebsiteMenuView';
|
2020-09-17 04:55:32 +00:00
|
|
|
|
2020-10-11 09:29:55 +00:00
|
|
|
export default function WebsiteDetails({ websiteId }) {
|
2022-12-28 23:43:22 +00:00
|
|
|
const { get, useQuery } = useApi();
|
2023-02-04 16:59:52 +00:00
|
|
|
const { data, isLoading, error } = useQuery(['websites', websiteId], () =>
|
2022-12-28 23:43:22 +00:00
|
|
|
get(`/websites/${websiteId}`),
|
|
|
|
|
);
|
2020-08-04 06:20:35 +00:00
|
|
|
const [chartLoaded, setChartLoaded] = useState(false);
|
2023-02-04 16:59:52 +00:00
|
|
|
|
2020-09-17 04:55:32 +00:00
|
|
|
const {
|
2020-09-26 05:31:18 +00:00
|
|
|
query: { view },
|
|
|
|
|
} = usePageQuery();
|
2020-09-17 04:55:32 +00:00
|
|
|
|
2020-08-04 06:20:35 +00:00
|
|
|
function handleDataLoad() {
|
2020-08-31 21:11:30 +00:00
|
|
|
if (!chartLoaded) {
|
2020-10-10 03:37:24 +00:00
|
|
|
setTimeout(() => setChartLoaded(true), DEFAULT_ANIMATION_DURATION);
|
2020-08-31 21:11:30 +00:00
|
|
|
}
|
2020-08-01 02:05:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2023-02-04 16:59:52 +00:00
|
|
|
<Page loading={isLoading} error={error}>
|
2022-12-10 22:26:52 +00:00
|
|
|
<WebsiteChart
|
|
|
|
|
websiteId={websiteId}
|
2023-03-31 12:55:28 +00:00
|
|
|
name={data?.name}
|
2023-02-04 16:59:52 +00:00
|
|
|
domain={data?.domain}
|
2022-12-10 22:26:52 +00:00
|
|
|
onDataLoad={handleDataLoad}
|
|
|
|
|
showLink={false}
|
2023-02-09 07:14:11 +00:00
|
|
|
stickyHeader={true}
|
2022-12-10 22:26:52 +00:00
|
|
|
/>
|
2023-03-24 17:55:20 +00:00
|
|
|
{!chartLoaded && <Loading icon="dots" style={{ minHeight: 300 }} />}
|
2023-02-04 16:59:52 +00:00
|
|
|
{chartLoaded && (
|
2022-12-09 07:43:43 +00:00
|
|
|
<>
|
2023-02-04 16:59:52 +00:00
|
|
|
{!view && <WebsiteTableView websiteId={websiteId} />}
|
|
|
|
|
{view && <WebsiteMenuView websiteId={websiteId} />}
|
2022-12-09 07:43:43 +00:00
|
|
|
</>
|
2020-08-04 06:20:35 +00:00
|
|
|
)}
|
2020-08-06 02:04:02 +00:00
|
|
|
</Page>
|
2020-08-01 02:05:14 +00:00
|
|
|
);
|
|
|
|
|
}
|