import splashText from '@assets/insideJokes'; import createSchedule from '@pages/background/lib/createSchedule'; import { CalendarDots, GearSix, Plus } from '@phosphor-icons/react'; import { background } from '@shared/messages'; import { initSettings, OptionsStore } from '@shared/storage/OptionsStore'; import { UserScheduleStore } from '@shared/storage/UserScheduleStore'; import Divider from '@views/components/common/Divider'; import Text from '@views/components/common/Text/Text'; import { useEnforceScheduleLimit } from '@views/hooks/useEnforceScheduleLimit'; import useSchedules, { getActiveSchedule, replaceSchedule, switchSchedule } from '@views/hooks/useSchedules'; import useKC_DABR_WASM from 'kc-dabr-wasm'; import React, { useEffect, useState } from 'react'; import { Button } from './common/Button'; import CourseStatus from './common/CourseStatus'; import { SmallLogo } from './common/LogoIcon'; import PopupCourseBlock from './common/PopupCourseBlock'; import ScheduleDropdown from './common/ScheduleDropdown'; import ScheduleListItem from './common/ScheduleListItem'; import { SortableList } from './common/SortableList'; /** * Renders the main popup component. * This component displays the main schedule, courses, and options buttons. */ export default function PopupMain(): JSX.Element { const [enableCourseStatusChips, setEnableCourseStatusChips] = useState(false); // const [enableDataRefreshing, setEnableDataRefreshing] = useState(false); useKC_DABR_WASM(); useEffect(() => { const initAllSettings = async () => { const { enableCourseStatusChips } = await initSettings(); setEnableCourseStatusChips(enableCourseStatusChips); // setEnableDataRefreshing(enableDataRefreshing); }; initAllSettings(); const l1 = OptionsStore.listen('enableCourseStatusChips', async ({ newValue }) => { setEnableCourseStatusChips(newValue); // console.log('enableCourseStatusChips', newValue); }); // const l2 = OptionsStore.listen('enableDataRefreshing', async ({ newValue }) => { // setEnableDataRefreshing(newValue); // // console.log('enableDataRefreshing', newValue); // }); return () => { OptionsStore.removeListener(l1); // OptionsStore.removeListener(l2); }; }, []); const [activeSchedule, schedules] = useSchedules(); // const [isRefreshing, setIsRefreshing] = useState(false); const [funny, setFunny] = useState(''); const enforceScheduleLimit = useEnforceScheduleLimit(); const handleAddSchedule = () => { if (enforceScheduleLimit()) { createSchedule('New Schedule'); } }; useEffect(() => { setFunny(prevFunny => { // Ensure that the next splash text is not the same as the previous one const splashTextWithoutCurrent = splashText.filter(text => text !== prevFunny); const randomIndex = Math.floor(Math.random() * splashTextWithoutCurrent.length); return ( splashTextWithoutCurrent[randomIndex] ?? 'If you are seeing this, something has gone horribly wrong behind the scenes.' ); }); // Generate a new splash text every time the active schedule changes }, [activeSchedule.id]); const handleOpenOptions = async () => { const url = chrome.runtime.getURL('/options.html'); background.openNewTab({ url }); }; const handleCalendarOpenOnClick = async () => { await background.switchToCalendarTab({}); window.close(); }; return (
{ 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); }} renderItem={schedule => ( switchSchedule(schedule.id)} /> )} />
{activeSchedule?.courses?.length === 0 && (
{funny} (No courses added)
)}
{activeSchedule?.courses?.length > 0 && ( ({ id: course.uniqueId, course, }))} onChange={reordered => { activeSchedule.courses = reordered.map(({ course }) => course); replaceSchedule(getActiveSchedule(), activeSchedule); }} renderItem={({ id, course }) => ( )} /> )}
{enableCourseStatusChips && ( <> )}
{/* {enableDataRefreshing && (
*/} {/* LAST UPDATED: {getUpdatedAtDateTimeString(activeSchedule.updatedAt)} */} {/* */} {/*
)} */}
); }