import React, {FC, useEffect, useState} from "react"; import useAxiosTools from "../../hooks/AxiosTools"; import {toDo} from "../../utilities/types"; import {Link} from "react-router-dom"; import useTracker from "../../hooks/TraskerHook"; import {Simulate} from "react-dom/test-utils"; import load = Simulate.load; import {DraggableSVG, PlaySVG} from "../SVG"; const ToDoIndex: FC = ({reload, setReload}) => { const {loading, setLoading, errorCatch, errorLabel, axiosGet, axiosPut} = useAxiosTools(true) const [toDos, setToDos] = useState([]) const {startTrackToDo} = useTracker() useEffect(() => { fetchToDos() }, []) useEffect(() => { if (reload && !loading) { fetchToDos() } }, [reload]); const fetchToDos = async () => { try { const res = await axiosGet('api/todos') setToDos(res.data) } catch (error) { errorCatch(error) } finally { setLoading(false) } } const toggleCheck = async (toDo: toDo) => { console.log(toDo) try { await axiosPut('api/todos/' + toDo.id, {checked: ! toDo.checked}) setReload(new Date()) await fetchToDos() } catch (error) { errorCatch(error) } finally { setLoading(false) } } return <> {errorLabel()} } export default ToDoIndex interface ToDoIndexProps { reload: Date|null, setReload: (date: Date) => void, }