From 8ecd3f50272a09948063c503753ab542b22d7bee Mon Sep 17 00:00:00 2001 From: Fefedu973 <80718477+Fefedu973@users.noreply.github.com> Date: Mon, 11 Nov 2024 17:05:20 +0100 Subject: [PATCH 1/2] Update Account.jsx --- src/components/app/Account/Account.jsx | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/components/app/Account/Account.jsx b/src/components/app/Account/Account.jsx index 231789e..e4a7ae9 100644 --- a/src/components/app/Account/Account.jsx +++ b/src/components/app/Account/Account.jsx @@ -65,42 +65,43 @@ export default function Account({ schoolLife, fetchSchoolLife, fetchAdministrati } }, [schoolLife, isLoggedIn, activeAccount]); + const [oldCurrentYear, setOldCurrentYear] = useState(''); + const [selectedYear, setSelectedYear] = useState(settings.get("isSchoolYearEnabled") ? settings.get("schoolYear").join("-") : availableYearsArray[availableYearsArray.length - 1]); const [documents, setDocuments] = useState({ factures: [], notes: [], viescolaire: [], administratifs: [], entreprises: [] }); // handle year change of dropdown function handleYearChange(year) { + setOldCurrentYear(selectedYear); setSelectedYear(year); console.log("Selected year:", year); } // fetch documents on page load and year change useEffect(() => { - setIsLoadingDocuments(true); if (isLoggedIn && selectedYear) { let data = userData.get("administrativeDocuments"); - if (data === undefined) { - const controller = new AbortController(); + if (data === undefined || oldCurrentYear !== selectedYear) { + setOldCurrentYear(selectedYear); const fetchDocuments = async () => { try { setIsLoadingDocuments(true); let selectedYearFetch = selectedYear === availableYearsArray[availableYearsArray.length - 1] ? '' : selectedYear; - await fetchAdministrativeDocuments(selectedYearFetch, controller); + await fetchAdministrativeDocuments(selectedYearFetch); } catch (error) { console.error("Error fetching documents:", error); + } finally { + setTimeout(() => { + setIsLoadingDocuments(false); + } , 1000); } }; fetchDocuments(); - - return () => { - controller.abort(); - }; + } else { + setDocuments(data); } - - setDocuments(data); - setIsLoadingDocuments(false); } - }, [selectedYear, isLoggedIn, userData.get("administrativeDocuments")]); + }, [oldCurrentYear, selectedYear, isLoggedIn, userData.get("administrativeDocuments")]); return (
From 945c86c73576e695e453bbc30741d97c335a4cd9 Mon Sep 17 00:00:00 2001 From: Fefedu973 <80718477+Fefedu973@users.noreply.github.com> Date: Mon, 11 Nov 2024 17:06:10 +0100 Subject: [PATCH 2/2] Update Account.jsx --- src/components/app/Account/Account.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/app/Account/Account.jsx b/src/components/app/Account/Account.jsx index e4a7ae9..f676671 100644 --- a/src/components/app/Account/Account.jsx +++ b/src/components/app/Account/Account.jsx @@ -93,7 +93,7 @@ export default function Account({ schoolLife, fetchSchoolLife, fetchAdministrati } finally { setTimeout(() => { setIsLoadingDocuments(false); - } , 1000); + } , 0); } }; fetchDocuments();