From 4bcb80fba5b64efef4113bd1db4219600ecf067a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Sj=C3=B6kvist?= <35743604+williamsjokvist@users.noreply.github.com> Date: Sat, 4 Jan 2025 15:17:35 +0100 Subject: [PATCH] fix: rm unnecessary useeffect on sessions list page (#224) --- gui/src/pages/sessions.tsx | 42 ++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/gui/src/pages/sessions.tsx b/gui/src/pages/sessions.tsx index f442f0b..e9cfc1e 100644 --- a/gui/src/pages/sessions.tsx +++ b/gui/src/pages/sessions.tsx @@ -20,30 +20,10 @@ export function SessionsListPage() { const [sessions, setSessions] = React.useState([]) const [sessionStatistics, setSessionStatistics] = React.useState() - const [year, setYear] = React.useState('') - const [month, setMonth] = React.useState('01') const [monthIndex, setMonthIndex] = React.useState(0) const months = sessionStatistics?.Months ?? [] - React.useEffect(() => { - GetSessionsStatistics('').then(setSessionStatistics).catch(setError) - }, []) - - React.useEffect(() => { - if (months.length > 0 && months[monthIndex]) { - const [year, month] = months[monthIndex].Date.split('-') - setMonth(month) - setYear(year) - } - }, [sessionStatistics, monthIndex]) - - React.useEffect(() => { - if (months.length > 0 && months[monthIndex]) { - GetSessions('', months[monthIndex].Date, 0, 0).then(setSessions).catch(setError) - } - }, [monthIndex, months]) - const sessionsByDay = (sessions ?? []).reduce( (group, session) => { const date = new Date(session.createdAt) @@ -55,6 +35,16 @@ export function SessionsListPage() { {} as Record ) + React.useEffect(() => { + GetSessionsStatistics('').then(setSessionStatistics).catch(setError) + }, []) + + React.useEffect(() => { + if (months.length > 0 && months[monthIndex]) { + GetSessions('', months[monthIndex].Date, 0, 0).then(setSessions).catch(setError) + } + }, [monthIndex, months]) + return ( @@ -87,10 +77,14 @@ export function SessionsListPage() { />

- {year} /{' '} - {Intl.DateTimeFormat(i18n.resolvedLanguage, { - month: 'long' - }).format(new Date(`2024-${month}-01`))} + {months.length > 0 && months[monthIndex] && ( + <> + {months[monthIndex].Date.split('-')[0]} /{' '} + {Intl.DateTimeFormat(i18n.resolvedLanguage, { + month: 'long' + }).format(new Date(`2024-${months[monthIndex].Date.split('-')[1]}-01`))} + + )}