mirror of
https://github.com/plausible/analytics.git
synced 2024-12-19 15:41:56 +03:00
3999f282a5
* extract blinkingDot function * position pulsating-circle with tailwind instead * remove unused function * extract renderStatName function * display seconds since last realtime update Adds a 'Last updated X seconds ago' label to the Current Visitors tooltip. * small refactor: avoid duplication of this.props and this.state * show the 'last updated ...' tooltip in historical * changelog update * use className utility function
16 lines
567 B
JavaScript
16 lines
567 B
JavaScript
import { useState, useEffect } from "react";
|
|
|
|
// A function component that renders an integer value of how many
|
|
// seconds have passed from the last data load on the dashboard.
|
|
// Updates the value every second when the component is visible.
|
|
export function SecondsSinceLastLoad({ lastLoadTimestamp }) {
|
|
const [timeNow, setTimeNow] = useState(new Date())
|
|
|
|
useEffect(() => {
|
|
const interval = setInterval(() => setTimeNow(new Date()), 1000)
|
|
return () => clearInterval(interval)
|
|
}, []);
|
|
|
|
return Math.round(Math.abs(lastLoadTimestamp - timeNow) / 1000)
|
|
}
|