Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate isDarkMode in favor of useThemeStore #847

Merged
merged 12 commits into from
Feb 2, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ const CourseCalendarEvent = (props: CourseCalendarEventProps) => {

const { setActiveTab } = useTabStore();
const { isMilitaryTime } = useTimeFormatStore();
const appTheme = useThemeStore((store) => store.appTheme);
const isDark = useThemeStore((store) => store.isDark);

const focusMap = useCallback(() => {
setActiveTab(2);
Expand Down Expand Up @@ -262,7 +262,7 @@ const CourseCalendarEvent = (props: CourseCalendarEventProps) => {
className={classes.clickableLocation}
to={`/map?location=${locationIds[location.building] ?? 0}`}
onClick={focusMap}
color={appTheme == 'dark' ? '#1cbeff' : 'blue'}
color={isDark ? '#1cbeff' : 'blue'}
>
{location.building} {location.room}
</Link>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,16 @@ function CustomEventDialogs(props: CustomEventDialogProps) {

AppStore.on('skeletonModeChange', handleSkeletonModeChange);

render() {
const appTheme = useThemeStore.getState().appTheme;
return (
<>
{this.props.customEvent !== undefined ? (
// Dumb ternary below added to get rid of TypeScript possibly undefined compile error
return () => {
AppStore.off('skeletonModeChange', handleSkeletonModeChange);
};
}, []);

const isDark = useThemeStore.getState().isDark;
return (
<>
{props.customEvent ? (
<Tooltip title="Edit">
<IconButton
onClick={() => {
handleOpen();
Expand Down Expand Up @@ -214,29 +218,20 @@ function CustomEventDialogs(props: CustomEventDialogProps) {
/>
</DialogContent>

<DialogActions>
<Button
onClick={() => this.handleClose(true)}
color={appTheme == 'dark' ? 'secondary' : 'primary'}
>
Cancel
</Button>
<Tooltip title="Schedule and day must be checked" disableHoverListener={!this.isAddDisabled()}>
<span>
<Button
onClick={() => this.handleClose(false)}
variant="contained"
color="primary"
disabled={this.isAddDisabled()}
>
{this.props.customEvent ? 'Save Changes' : 'Add Event'}
</Button>
</span>
</Tooltip>
</DialogActions>
</Dialog>
</>
);
}
<DialogActions>
<Button onClick={handleClose} color={isDark ? 'secondary' : 'primary'}>
Cancel
</Button>
<Button onClick={handleSubmit} variant="contained" color="primary" disabled={disabled}>
{disabled
? 'Schedule and day must be checked'
: props.customEvent
? 'Save Changes'
: 'Add Event'}
</Button>
</DialogActions>
</Dialog>
</>
);
}
export default CustomEventDialogs;
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface DeleteScheduleDialogProps {
}

const DeleteScheduleDialog = (props: DeleteScheduleDialogProps) => {
const appTheme = useThemeStore((store) => store.appTheme);
const isDark = useThemeStore((store) => store.isDark);

const { scheduleIndex } = props;

Expand Down Expand Up @@ -60,7 +60,7 @@ const DeleteScheduleDialog = (props: DeleteScheduleDialogProps) => {
</DialogContentText>
</DialogContent>
<DialogActions>
<Button onClick={handleClose} color={appTheme == 'dark' ? 'secondary' : 'primary'}>
<Button onClick={handleClose} color={isDark ? 'secondary' : 'primary'}>
Cancel
</Button>
<Button onClick={handleDelete} variant="contained" color="primary">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ interface ScheduleNameDialogProps {
}

const ScheduleNameDialog = forwardRef((props: ScheduleNameDialogProps, ref) => {
const appTheme = useThemeStore((store) => store.appTheme);
const isDark = useThemeStore((store) => store.isDark);

const { classes, onOpen, onClose, scheduleNames, scheduleRenameIndex } = props;

Expand Down Expand Up @@ -145,7 +145,7 @@ const ScheduleNameDialog = forwardRef((props: ScheduleNameDialogProps, ref) => {
</DialogContent>

<DialogActions>
<Button onClick={handleCancel} color={appTheme == 'dark' ? 'secondary' : 'primary'}>
<Button onClick={handleCancel} color={isDark ? 'secondary' : 'primary'}>
Cancel
</Button>
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ChangeEvent, PureComponent, useEffect, useState } from 'react';
import { LoadingButton } from '@mui/lab';
import { loadSchedule, saveSchedule } from '$actions/AppStoreActions';
import { useThemeStore } from '$stores/SettingsStore';
import AppStore from '$stores/AppStore';

interface LoadSaveButtonBaseProps {
action: typeof saveSchedule;
Expand Down Expand Up @@ -141,7 +142,7 @@ class LoadSaveButtonBase extends PureComponent<LoadSaveButtonBaseProps, LoadSave
}

const LoadSaveScheduleFunctionality = () => {
const appTheme = useThemeStore((store) => store.appTheme);
const isDark = useThemeStore((store) => store.isDark);

const [loading, setLoading] = useState(false);
const [skeletonMode, setSkeletonMode] = useState(AppStore.getSkeletonMode());
Expand Down Expand Up @@ -182,14 +183,14 @@ const LoadSaveScheduleFunctionality = () => {
action={saveSchedule}
disabled={loading}
loading={false}
colorType={appTheme == 'dark' ? 'primary' : 'secondary'}
colorType={isDark ? 'primary' : 'secondary'}
/>
<LoadSaveButtonBase
actionName={'Load'}
action={loadScheduleAndSetLoading}
disabled={skeletonMode}
loading={loading}
colorType={appTheme == 'dark' ? 'primary' : 'secondary'}
colorType={isDark ? 'primary' : 'secondary'}
/>
</>
);
Expand Down
18 changes: 10 additions & 8 deletions apps/antalmanac/src/components/Header/SettingsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ const darkSelectedStyle: CSSProperties = {
color: '#99CCF3',
};

function getSelectedStyle(buttonValue: string, themeSetting: string, appTheme: string) {
return themeSetting === buttonValue ? (appTheme == 'dark' ? darkSelectedStyle : lightSelectedStyle) : {};
function getSelectedStyle(buttonValue: string, themeSetting: string, appTheme: string, isDark: boolean) {
return themeSetting === buttonValue ? (isDark ? darkSelectedStyle : lightSelectedStyle) : {};
}

function ThemeMenu() {
const [themeSetting, appTheme, setTheme] = useThemeStore((store) => [
const [themeSetting, appTheme, isDark, setTheme] = useThemeStore((store) => [
store.themeSetting,
store.appTheme,
store.isDark,
store.setAppTheme,
]);

Expand All @@ -45,7 +46,7 @@ function ThemeMenu() {
padding: '1rem 2rem',
borderRadius: '12px 0px 0px 12px',
width: '100%',
...getSelectedStyle('light', themeSetting, appTheme),
...getSelectedStyle('light', themeSetting, appTheme, isDark),
}}
value="light"
onClick={handleThemeChange}
Expand All @@ -57,7 +58,7 @@ function ThemeMenu() {
style={{
padding: '1rem 2rem',
width: '100%',
...getSelectedStyle('system', themeSetting, appTheme),
...getSelectedStyle('system', themeSetting, appTheme, isDark),
}}
value="system"
onClick={handleThemeChange}
Expand All @@ -70,7 +71,7 @@ function ThemeMenu() {
padding: '1rem 2rem',
borderRadius: '0px 12px 12px 0px',
width: '100%',
...getSelectedStyle('dark', themeSetting, appTheme),
...getSelectedStyle('dark', themeSetting, appTheme, isDark),
}}
value="dark"
onClick={handleThemeChange}
Expand All @@ -84,6 +85,7 @@ function ThemeMenu() {

function TimeMenu() {
const [isMilitaryTime, setTimeFormat] = useTimeFormatStore((store) => [store.isMilitaryTime, store.setTimeFormat]);
const isDark = useThemeStore((store) => store.isDark);
const theme = useThemeStore((store) => store.appTheme);

const handleTimeFormatChange = (event: React.MouseEvent<HTMLButtonElement>) => {
Expand All @@ -109,7 +111,7 @@ function TimeMenu() {
borderRadius: '12px 0px 0px 12px',
width: '100%',
fontSize: '12px',
...getSelectedStyle('false', isMilitaryTime.toString(), theme),
...getSelectedStyle('false', isMilitaryTime.toString(), theme, isDark),
}}
value="false"
onClick={handleTimeFormatChange}
Expand All @@ -123,7 +125,7 @@ function TimeMenu() {
borderRadius: '0px 12px 12px 0px',
width: '100%',
fontSize: '12px',
...getSelectedStyle('true', isMilitaryTime.toString(), theme),
...getSelectedStyle('true', isMilitaryTime.toString(), theme, isDark),
}}
value="true"
onClick={handleTimeFormatChange}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const flattenSOCObject = (SOCObject: WebsocAPIResponse): (WebsocSchool | WebsocD
const RecruitmentBanner = () => {
const [bannerVisibility, setBannerVisibility] = useState(true);

const appTheme = useThemeStore((store) => store.appTheme);
const isDark = useThemeStore((store) => store.isDark);

// Display recruitment banner if more than 11 weeks (in ms) has passed since last dismissal
const recruitmentDismissalTime = window.localStorage.getItem('recruitmentDismissalTime');
Expand All @@ -69,8 +69,8 @@ const RecruitmentBanner = () => {
icon={false}
severity="info"
style={{
color: appTheme == 'dark' ? '#ece6e6' : '#2e2e2e',
backgroundColor: appTheme == 'dark' ? '#2e2e2e' : '#ece6e6',
color: isDark ? '#ece6e6' : '#2e2e2e',
backgroundColor: isDark ? '#2e2e2e' : '#ece6e6',
}}
action={
<IconButton
Expand Down Expand Up @@ -146,20 +146,20 @@ const SectionTableWrapped = (
};

const LoadingMessage = () => {
const appTheme = useThemeStore((store) => store.appTheme);
const isDark = useThemeStore((store) => store.isDark);
return (
<Box sx={{ height: '100%', display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
<img src={appTheme == 'dark' ? darkModeLoadingGif : loadingGif} alt="Loading courses" />
<img src={isDark ? darkModeLoadingGif : loadingGif} alt="Loading courses" />
</Box>
);
};

const ErrorMessage = () => {
const appTheme = useThemeStore((store) => store.appTheme);
const isDark = useThemeStore((store) => store.isDark);
return (
<Box sx={{ height: '100%', display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
<img
src={appTheme == 'dark' ? darkNoNothing : noNothing}
src={isDark ? darkNoNothing : noNothing}
alt="No Results Found"
style={{ objectFit: 'contain', width: '80%', height: '80%' }}
/>
Expand Down
4 changes: 2 additions & 2 deletions apps/antalmanac/src/components/RightPane/RightPaneRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const tabs = [
export default function Desktop({ style }: DesktopTabsProps) {
const { activeTab, setActiveTab } = useTabStore();

const appTheme = useThemeStore((store) => store.appTheme);
const isDark = useThemeStore((store) => store.isDark);

return (
<Box style={{ ...style, margin: '0 4px' }}>
Expand Down Expand Up @@ -83,7 +83,7 @@ export default function Desktop({ style }: DesktopTabsProps) {
<Suspense
fallback={
<div style={styles.fallback}>
<img src={appTheme == 'dark' ? darkModeLoadingGif : loadingGif} alt="Loading map" />
<img src={isDark ? darkModeLoadingGif : loadingGif} alt="Loading map" />
</div>
}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function GradesPopup(props: GradesPopupProps) {
}

const encodedDept = encodeURIComponent(deptCode);
const axisColor = appTheme == 'dark' ? '#fff' : '#111';
const axisColor = isDark ? '#fff' : '#111';

return (
<Box sx={{ padding: '4px' }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const Node: FC<NodeProps> = (props) => {
<div
className={'course'}
style={{
backgroundColor: appTheme == 'dark' ? '#303030' : '#e0e0e0',
color: appTheme == 'dark' ? '#bfbfbf' : 'black',
backgroundColor: isDark ? '#303030' : '#e0e0e0',
color: isDark ? '#bfbfbf' : 'black',
}}
>
{props.label}
Expand Down
Loading