import splashText from '@assets/insideJokes'; import { background } from '@shared/messages'; import { UserScheduleStore } from '@shared/storage/UserScheduleStore'; import { enableCourseRefreshing, enableCourseStatusChips } from '@shared/util/experimental'; import Divider from '@views/components/common/Divider'; import ExtensionRoot from '@views/components/common/ExtensionRoot/ExtensionRoot'; import List from '@views/components/common/List'; import Text from '@views/components/common/Text/Text'; import useSchedules, { getActiveSchedule, replaceSchedule, switchSchedule } from '@views/hooks/useSchedules'; import { getUpdatedAtDateTimeString } from '@views/lib/getUpdatedAtDateTimeString'; import { openTabFromContentScript } from '@views/lib/openNewTabFromContentScript'; import clsx from 'clsx'; import React, { useEffect, useState } from 'react'; import CalendarIcon from '~icons/material-symbols/calendar-month'; import RefreshIcon from '~icons/material-symbols/refresh'; import SettingsIcon from '~icons/material-symbols/settings'; import CourseStatus from './common/CourseStatus'; import DialogProvider from './common/DialogProvider/DialogProvider'; import { SmallLogo } from './common/LogoIcon'; import PopupCourseBlock from './common/PopupCourseBlock'; import ScheduleDropdown from './common/ScheduleDropdown'; import ScheduleListItem from './common/ScheduleListItem'; /** * Renders the main popup component. * This component displays the main schedule, courses, and options buttons. */ export default function PopupMain(): JSX.Element { const [activeSchedule, schedules] = useSchedules(); const [isRefreshing, setIsRefreshing] = useState(false); const [funny, setFunny] = useState(''); useEffect(() => { const randomIndex = Math.floor(Math.random() * splashText.length); setFunny( splashText[randomIndex] ?? 'If you are seeing this, something has gone horribly wrong behind the scenes.' ); }, []); const handleOpenOptions = async () => { const url = chrome.runtime.getURL('/options.html'); await openTabFromContentScript(url); }; const handleCalendarOpenOnClick = async () => { await background.switchToCalendarTab({}); window.close(); }; return (
schedule.id} onReordered={reordered => { const activeSchedule = getActiveSchedule(); const activeIndex = reordered.findIndex(s => s.id === activeSchedule.id); // don't care about the promise UserScheduleStore.set('schedules', reordered); UserScheduleStore.set('activeIndex', activeIndex); }} gap={10} > {(schedule, handleProps) => ( { switchSchedule(schedule.id); }} dragHandleProps={handleProps} /> )}
{activeSchedule?.courses?.length === 0 && (
{funny} (No courses added)
)}
{activeSchedule?.courses?.length > 0 && ( { activeSchedule.courses = reordered; replaceSchedule(getActiveSchedule(), activeSchedule); }} itemKey={e => e.uniqueId} gap={10} > {(course, handleProps) => ( )} )}
{enableCourseStatusChips && ( <> )}
{enableCourseRefreshing && (
DATA LAST UPDATED: {getUpdatedAtDateTimeString(activeSchedule.updatedAt)}
)}
); }