mirror of
https://github.com/umami-software/umami.git
synced 2026-02-09 15:17:23 +01:00
Updated polling logic.
This commit is contained in:
parent
fdc92d087b
commit
9737127bb1
6 changed files with 33 additions and 19 deletions
|
|
@ -6,7 +6,15 @@ import BarChart from './BarChart';
|
|||
import useTheme from 'hooks/useTheme';
|
||||
import { THEME_COLORS } from 'lib/constants';
|
||||
|
||||
export default function PageviewsChart({ websiteId, data, unit, records, className, loading }) {
|
||||
export default function PageviewsChart({
|
||||
websiteId,
|
||||
data,
|
||||
unit,
|
||||
records,
|
||||
className,
|
||||
loading,
|
||||
animationDuration = 300,
|
||||
}) {
|
||||
const intl = useIntl();
|
||||
const [theme] = useTheme();
|
||||
const primaryColor = tinycolor(THEME_COLORS[theme].primary);
|
||||
|
|
@ -76,7 +84,7 @@ export default function PageviewsChart({ websiteId, data, unit, records, classNa
|
|||
]}
|
||||
unit={unit}
|
||||
records={records}
|
||||
animationDuration={visible ? 300 : 0}
|
||||
animationDuration={visible ? animationDuration : 0}
|
||||
onUpdate={handleUpdate}
|
||||
loading={loading}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -35,11 +35,16 @@ function mapData(data) {
|
|||
export default function RealtimeDashboard() {
|
||||
const [data, setData] = useState();
|
||||
const [website, setWebsite] = useState();
|
||||
const [lastTime, setLastTime] = useState();
|
||||
const { data: init, loading } = useFetch('/api/realtime', { type: 'init' });
|
||||
const { data: updates } = useFetch(
|
||||
'/api/realtime',
|
||||
{ type: 'update' },
|
||||
{ disabled: !init?.token, interval: 5000, headers: { 'x-umami-token': init?.token } },
|
||||
{ type: 'update', start_at: lastTime },
|
||||
{
|
||||
disabled: !init?.token,
|
||||
interval: 5000,
|
||||
headers: { 'x-umami-token': init?.token },
|
||||
},
|
||||
);
|
||||
|
||||
const chartData = useMemo(() => {
|
||||
|
|
@ -48,8 +53,6 @@ export default function RealtimeDashboard() {
|
|||
const startDate = subMinutes(endDate, 30);
|
||||
const unit = 'minute';
|
||||
|
||||
console.log({ data });
|
||||
|
||||
return {
|
||||
pageviews: getDateArray(mapData(data.pageviews), startDate, endDate, unit),
|
||||
sessions: getDateArray(mapData(data.sessions), startDate, endDate, unit),
|
||||
|
|
@ -70,6 +73,7 @@ export default function RealtimeDashboard() {
|
|||
events: filterTime(state.events, time).concat(events),
|
||||
}));
|
||||
}
|
||||
setLastTime(Date.now());
|
||||
}, [updates, init]);
|
||||
|
||||
if (!init || loading || !data) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue