From 9125c2525943445b158adb216db1ef0c952f9c08 Mon Sep 17 00:00:00 2001 From: Vencislav Atanasov Date: Thu, 19 Sep 2024 01:57:05 +0300 Subject: [PATCH] Add progress bar and progress calculation --- src/Schedule.jsx | 3 ++- src/hooks/useSchedule.js | 14 ++++++++++++-- src/utils.js | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/Schedule.jsx b/src/Schedule.jsx index ab2382e..50a3263 100644 --- a/src/Schedule.jsx +++ b/src/Schedule.jsx @@ -12,10 +12,11 @@ export default function Schedule({ speakers, tracks, isLoading, + loadingProgress, } = useSchedule(conferenceId); return (<> - {isLoading &&

Loading...

} + {isLoading &&

Loading...

}
schedule goes here
{tracks && Object.entries(tracks).map(([trackId, track]) =>
(a, b) => sorter(a, b, item => Date.parse(item[ export const getSpeakerName = speaker => speaker.first_name.concat(' ').concat(speaker.last_name); export const isTrackHidden = track => track.name.en === 'Other' || track.name.bg === 'Други'; + +export function calculateProgress(...elements) { + const totalCount = elements.length; + + if (totalCount === 0) { + return { + totalCount, + completeCount: 0, + incompleteCount: 0, + progress: 1, + remainingProgress: 0, + isComplete: true, + isIncomplete: false, + isStarted: true, + isNotStarted: false, + }; + } + + const completeCount = elements.filter(element => !!element).length; + const progress = completeCount / totalCount; + + return { + totalCount, + completeCount, + incompleteCount: totalCount - completeCount, + progress, + remainingProgress: 1 - progress, + isComplete: completeCount === totalCount, + isIncomplete: completeCount < totalCount, + isStarted: completeCount > 0, + isNotStarted: completeCount === 0, + }; +}