-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move code around and optimize
- Loading branch information
1 parent
5b4736a
commit b8dd5f6
Showing
7 changed files
with
269 additions
and
254 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...mponents/Calendar/Toolbar/schedule-select/schedule-select-buttons/add-schedule-button.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Add as AddIcon } from '@mui/icons-material'; | ||
import { Box, Button, Typography } from '@mui/material'; | ||
import { useCallback, useState } from 'react'; | ||
|
||
import AddScheduleDialog from '$components/dialogs/AddSchedule'; | ||
|
||
interface AddScheduleButtonProps { | ||
disabled: boolean; | ||
} | ||
|
||
/** | ||
* MenuItem nested in the select menu to add a new schedule through a dialog. | ||
*/ | ||
export function AddScheduleButton({ disabled }: AddScheduleButtonProps) { | ||
const [open, setOpen] = useState(false); | ||
|
||
const handleOpen = useCallback(() => { | ||
setOpen(true); | ||
}, []); | ||
|
||
const handleClose = useCallback(() => { | ||
setOpen(false); | ||
}, []); | ||
|
||
return ( | ||
<Box> | ||
<Button color="inherit" onClick={handleOpen} sx={{ display: 'flex', gap: 1 }} disabled={disabled}> | ||
<AddIcon /> | ||
<Typography whiteSpace="nowrap" textOverflow="ellipsis" overflow="hidden" textTransform="none"> | ||
Add Schedule | ||
</Typography> | ||
</Button> | ||
<AddScheduleDialog fullWidth open={open} onClose={handleClose} /> | ||
</Box> | ||
); | ||
} |
40 changes: 40 additions & 0 deletions
40
...nents/Calendar/Toolbar/schedule-select/schedule-select-buttons/delete-schedule-button.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Clear as ClearIcon } from '@mui/icons-material'; | ||
import { Box, IconButton, Tooltip } from '@mui/material'; | ||
import { useCallback, useState } from 'react'; | ||
|
||
import DeleteScheduleDialog from '$components/dialogs/DeleteSchedule'; | ||
import AppStore from '$stores/AppStore'; | ||
|
||
interface DeleteScheduleButtonProps { | ||
index: number; | ||
disabled?: boolean; | ||
} | ||
|
||
export function DeleteScheduleButton({ index, disabled }: DeleteScheduleButtonProps) { | ||
const [open, setOpen] = useState(false); | ||
|
||
const handleOpen = useCallback(() => { | ||
setOpen(true); | ||
}, []); | ||
|
||
const handleClose = useCallback(() => { | ||
setOpen(false); | ||
}, []); | ||
|
||
return ( | ||
<Box> | ||
<Tooltip title="Delete Schedule"> | ||
<span> | ||
<IconButton | ||
onClick={handleOpen} | ||
size="small" | ||
disabled={AppStore.schedule.getNumberOfSchedules() === 1 || disabled} | ||
> | ||
<ClearIcon /> | ||
</IconButton> | ||
</span> | ||
</Tooltip> | ||
<DeleteScheduleDialog fullWidth open={open} index={index} onClose={handleClose} /> | ||
</Box> | ||
); | ||
} |
Oops, something went wrong.