From c22bab837ad0dd7f91ea9763f56934e040405b52 Mon Sep 17 00:00:00 2001 From: Minh Duong Date: Wed, 8 Jan 2025 00:43:40 -0600 Subject: [PATCH] feat: show up to three upcoming meetings initially with toggle to show more --- sigpwny.com/src/components/Meeting/Row.astro | 14 +-- .../pages/meetings/[...indexSlug]/index.astro | 101 +++++++++++++----- 2 files changed, 84 insertions(+), 31 deletions(-) diff --git a/sigpwny.com/src/components/Meeting/Row.astro b/sigpwny.com/src/components/Meeting/Row.astro index 74e6d83b..9ffcafdd 100644 --- a/sigpwny.com/src/components/Meeting/Row.astro +++ b/sigpwny.com/src/components/Meeting/Row.astro @@ -27,24 +27,24 @@ interface Props { const { input, dateFormat } = Astro.props; const meeting = input.data; const time_close = dayjs(meeting.time_start).add(dayjs.duration(meeting.duration)).toDate(); -const isMaybeUpcoming = dayjs().isBefore(time_close); +const isMaybeActive = dayjs().isBefore(time_close); // Resolve credit names to profiles const profiles = await getProfilesFromNames(meeting.credit); ---
  • @@ -98,7 +98,7 @@ const profiles = await getProfilesFromNames(meeting.credit); > - ) : isMaybeUpcoming && meeting.live_video_url ? ( + ) : isMaybeActive && meeting.live_video_url ? ( = 0; i--) { - const maybeUpcomingMeeting = maybeUpcomingMeetings[i]; - const timeCloseStr = maybeUpcomingMeeting.getAttribute('data-time-close'); - if (!timeCloseStr) { + const allMaybeActive = meetingsIndex.querySelectorAll('[data-maybe-active="true"]'); + var countLive = 0; + var countUpcoming = 0; + for (let i = allMaybeActive.length - 1; i >= 0; i--) { + const maybeActive = allMaybeActive[i]; + const timeStartStr = maybeActive.getAttribute('data-time-start'); + const timeCloseStr = maybeActive.getAttribute('data-time-close'); + if (!timeStartStr || !timeCloseStr) { continue; } + const timeStart = parseInt(timeStartStr); const timeClose = parseInt(timeCloseStr); const now = Date.now(); - if (now < timeClose) { - maybeUpcomingMeeting.setAttribute('data-is-upcoming', 'true'); - if (upcomingMeetingsList) { - upcomingMeetingsList.appendChild(maybeUpcomingMeeting); - } - if (upcomingMeetingsSection) { - upcomingMeetingsSection.classList.remove('hidden'); + if (now >= timeClose) { + continue; + } + maybeActive.setAttribute('data-is-active', 'true'); + if (now >= timeStart && liveMeetingsList) { + countLive++; + liveMeetingsList.appendChild(maybeActive); + } else if (upcomingMeetingsList) { + countUpcoming++; + upcomingMeetingsList.appendChild(maybeActive); + } + } + if (activeMeetingsSection && (countLive || countUpcoming)) { + const activeMeetingsTitle = document.getElementById('active-meetings-title'); + if (activeMeetingsTitle) { + activeMeetingsTitle.textContent = countLive && countUpcoming + ? 'Live & Upcoming' + : countLive + ? 'Live' + : 'Upcoming'; + } + if (countUpcoming > 3) { + const label = document.getElementById('upcoming-visibility-toggle-label'); + const input = document.getElementById('upcoming-visibility-toggle-input'); + if (label && input) { + label.style.display = 'block'; + input.style.display = 'block'; } } + activeMeetingsSection.classList.remove('hidden'); } }; document.addEventListener('astro:page-load', initMeetingsIndex); - {semesterMetadata?.activeMeetings ? (
    - {/*
    - - - Specific meeting times and locations may vary. Make sure to check individual meeting details. - -
    */}
    {semesterMetadata.activeMeetings.map((activeMeeting) => (
    @@ -159,17 +193,36 @@ const isAllIndex = props.currLink.semester === 'all'; )} {!isAllIndex ? ( ) : null}