import React, { useEffect, useState } from 'react'; import { getSigns, addSign, downloadSigns, deleteSign } from '../services/signs'; import { Sign } from '../types/sign'; import SignComponent from './SignComponent'; const SignsPage: React.FC = () => { const [signs, setSigns] = useState([]); const [newSign, setNewSign] = useState(''); const [newSignError, setNewSignError] = useState(null); const [loading, setLoading] = useState(true); const handleAddSign = async () => { addSign(newSign).then((sign) => { setSigns([...signs, sign]); setNewSign(''); setNewSignError(null); }).catch((error) => { setNewSignError(error.message); }); }; const handleDownloadData = async () => { downloadSigns().then((blob: Blob) => { const url = window.URL.createObjectURL(blob); const link = document.createElement('a'); link.href = url; link.setAttribute('download', 'data.zip'); document.body.appendChild(link); link.click(); link.remove(); }).catch((error: Error) => { console.log(error); }); }; const handleDeleteSign = async (id: number) => { deleteSign(id).then(() => { setSigns(signs.filter((sign) => sign.id !== id)); }); }; useEffect(() => { // get the signs from the api getSigns().then((signs) => { console.log(signs) setSigns(signs); setLoading(false); }); }, []); return (
setNewSign(event.target.value)} placeholder="Enter sign url" />
{newSignError &&

{newSignError}

} {!loading ?
{ signs.map((sign) => ) }
:

Loading...

}
); }; export default SignsPage;