mirror of
https://github.com/umami-software/umami.git
synced 2026-02-09 07:07:17 +01:00
Added useFetch hook. Updated database check.
This commit is contained in:
parent
7a81dda7b6
commit
d0ca0819c6
14 changed files with 146 additions and 237 deletions
|
|
@ -1,32 +1,20 @@
|
|||
import React, { useState, useEffect } from 'react';
|
||||
import React, { useMemo } from 'react';
|
||||
import { useSpring, animated } from 'react-spring';
|
||||
import classNames from 'classnames';
|
||||
import { get } from 'lib/web';
|
||||
import useFetch from 'hooks/useFetch';
|
||||
import styles from './ActiveUsers.module.css';
|
||||
|
||||
export default function ActiveUsers({ websiteId, className }) {
|
||||
const [count, setCount] = useState(0);
|
||||
|
||||
async function loadData() {
|
||||
const result = await get(`/api/website/${websiteId}/active`);
|
||||
setCount(result?.[0]?.x);
|
||||
}
|
||||
const { data } = useFetch(`/api/website/${websiteId}/active`, {}, { interval: 60000 });
|
||||
const count = useMemo(() => {
|
||||
return data?.[0]?.x || 0;
|
||||
}, [data]);
|
||||
|
||||
const props = useSpring({
|
||||
x: count,
|
||||
from: { x: 0 },
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
loadData();
|
||||
|
||||
const id = setInterval(() => loadData(), 60000);
|
||||
|
||||
return () => {
|
||||
clearInterval(id);
|
||||
};
|
||||
}, []);
|
||||
|
||||
if (count === 0) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue