2024-03-28 09:18:24 +00:00
|
|
|
import { getGeneral, getDevices, getQuestions } from "@api/statistic";
|
|
|
|
import { useEffect, useState } from "react";
|
2024-03-29 06:10:33 +00:00
|
|
|
import moment from "moment";
|
2024-03-28 09:18:24 +00:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
quizId: string;
|
|
|
|
to: number;
|
|
|
|
from: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function useAnalytics({
|
|
|
|
quizId,
|
|
|
|
to,
|
|
|
|
from,
|
|
|
|
}: Props) {
|
2024-03-29 06:10:33 +00:00
|
|
|
const formatTo = to === null ? 0 : moment(to).unix()
|
|
|
|
const formatFrom = from === null ? 0 : moment(from).unix()
|
|
|
|
console.log(
|
|
|
|
to,
|
|
|
|
from,)
|
|
|
|
if (quizId === undefined) return {}
|
|
|
|
const [devices, setDevices] = useState({});
|
|
|
|
const [general, setGeneral] = useState({});
|
|
|
|
const [questions, setQuestions] = useState({});
|
2024-03-28 09:18:24 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
(async () => {
|
2024-03-29 06:10:33 +00:00
|
|
|
const gottenGeneral = await getGeneral(quizId, formatTo, formatFrom)
|
|
|
|
const gottenDevices = await getDevices(quizId, formatTo, formatFrom)
|
|
|
|
const gottenQuestions = await getQuestions(quizId, formatTo, formatFrom)
|
|
|
|
setDevices(gottenGeneral[0])
|
|
|
|
setGeneral(gottenDevices[0])
|
|
|
|
setQuestions(gottenQuestions[0])
|
2024-03-28 09:18:24 +00:00
|
|
|
})()
|
|
|
|
}, [to, from]);
|
|
|
|
|
|
|
|
return { devices, general, questions };
|
|
|
|
}
|