mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-16 02:05:04 +01:00
64 lines
2.2 KiB
JavaScript
64 lines
2.2 KiB
JavaScript
import { useState } from 'react';
|
|
import { Button, Icon, Icons, Text, Flexbox } from 'react-basics';
|
|
import { useIntl } from 'react-intl';
|
|
import Link from 'next/link';
|
|
import Page from 'components/layout/Page';
|
|
import PageHeader from 'components/layout/PageHeader';
|
|
import WebsiteChartList from 'components/pages/websites/WebsiteChartList';
|
|
import DashboardSettingsButton from 'components/pages/dashboard/DashboardSettingsButton';
|
|
import DashboardEdit from 'components/pages/dashboard/DashboardEdit';
|
|
import EmptyPlaceholder from 'components/common/EmptyPlaceholder';
|
|
import useApi from 'hooks/useApi';
|
|
import { labels, messages } from 'components/messages';
|
|
import useDashboard from 'store/dashboard';
|
|
|
|
export default function Dashboard({ userId }) {
|
|
const dashboard = useDashboard();
|
|
const { showCharts, limit, editing } = dashboard;
|
|
const [max, setMax] = useState(limit);
|
|
const { get, useQuery } = useApi();
|
|
const { data, isLoading, error } = useQuery(['websites'], () => get('/websites', { userId }));
|
|
const { formatMessage } = useIntl();
|
|
const hasData = data && data.length !== 0;
|
|
|
|
function handleMore() {
|
|
setMax(max + limit);
|
|
}
|
|
|
|
return (
|
|
<Page loading={isLoading} error={error}>
|
|
<PageHeader title={formatMessage(labels.dashboard)}>
|
|
{!editing && hasData && <DashboardSettingsButton />}
|
|
</PageHeader>
|
|
{!hasData && (
|
|
<EmptyPlaceholder message={formatMessage(messages.noWebsites)}>
|
|
<Link href="/settings/websites">
|
|
<Button>
|
|
<Icon>
|
|
<Icons.ArrowRight />
|
|
</Icon>
|
|
<Text>{formatMessage(messages.goToSettings)}</Text>
|
|
</Button>
|
|
</Link>
|
|
</EmptyPlaceholder>
|
|
)}
|
|
{hasData && (
|
|
<>
|
|
{editing && <DashboardEdit websites={data} />}
|
|
{!editing && <WebsiteChartList websites={data} showCharts={showCharts} limit={max} />}
|
|
{max < data.length && (
|
|
<Flexbox justifyContent="center">
|
|
<Button onClick={handleMore}>
|
|
<Icon>
|
|
<Icons.More />
|
|
</Icon>
|
|
<Text>{formatMessage(labels.more)}</Text>
|
|
</Button>
|
|
</Flexbox>
|
|
)}
|
|
</>
|
|
)}
|
|
</Page>
|
|
);
|
|
}
|