Skip to content

Commit

Permalink
feat: disable calendar action buttons when meet start/end week
Browse files Browse the repository at this point in the history
  • Loading branch information
jsun969 committed Sep 24, 2024
1 parent 01027e1 commit 0ebdf29
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 12 deletions.
59 changes: 47 additions & 12 deletions src/components/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,38 @@ const CourseCard = ({ course }: { course: WeekCourse }) => {
type CalendarHeaderProps = {
currentWeek: dayjs.Dayjs;
actions: ReturnType<typeof useCalendar>['actions'];
status: ReturnType<typeof useCalendar>['status'];
};
const CalendarHeader = ({ currentWeek, actions }: CalendarHeaderProps) => {
const CalendarHeader = ({
currentWeek,
actions,
status,
}: CalendarHeaderProps) => {
const actionButtons = [
{ icon: '⏪', description: 'First week', action: actions.goToStartWeek },
{ icon: '◀️', description: 'Previous week', action: actions.prevWeek },
{ icon: '▶️', description: 'Next week', action: actions.nextWeek },
{ icon: '⏩', description: 'Last week', action: actions.goToEndWeek },
{
icon: '⏪',
description: 'First week',
action: actions.goToStartWeek,
disabled: status.isStartWeek,
},
{
icon: '◀️',
description: 'Previous week',
action: actions.prevWeek,
disabled: status.isStartWeek,
},
{
icon: '▶️',
description: 'Next week',
action: actions.nextWeek,
disabled: status.isEndWeek,
},
{
icon: '⏩',
description: 'Last week',
action: actions.goToEndWeek,
disabled: status.isEndWeek,
},
];
return (
<div className="sticky top-0 z-50 flex items-center justify-between bg-white py-1">
Expand All @@ -84,11 +109,17 @@ const CalendarHeader = ({ currentWeek, actions }: CalendarHeaderProps) => {
</span>
<span className="font-light">{YEAR}</span>
</h2>
<div className="flex *:text-3xl">
{actionButtons.map(({ icon, description, action }) => (
<Tooltip content={description} key={description}>
<Button isIconOnly variant="light" onClick={action}>
{icon}
<div className="flex">
{actionButtons.map((a) => (
<Tooltip content={a.description} key={a.description}>
<Button
isIconOnly
variant="light"
onClick={a.action}
disabled={a.disabled}
className="text-3xl disabled:opacity-50"
>
{a.icon}
</Button>
</Tooltip>
))}
Expand Down Expand Up @@ -241,12 +272,16 @@ const CalendarCourseOtherTimes = ({
};

export const Calendar = () => {
const { courses, currentWeek, actions } = useCalendar();
const { courses, currentWeek, actions, status } = useCalendar();
const isDragging = useDraggingCourse((s) => s.isDragging);

return (
<div>
<CalendarHeader currentWeek={currentWeek} actions={actions} />
<CalendarHeader
currentWeek={currentWeek}
actions={actions}
status={status}
/>
<div className="relative">
<CalendarBg currentWeek={currentWeek} />
<CalendarCourses courses={courses} />
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,14 @@ export const useCalendar = () => {

const courses = getWeekCourses(currentWeek, enrolledCourses);

const isStartWeek = currentWeek.isSame(startWeek);
const isEndWeek = currentWeek.isSame(endWeek);

return {
courses,
currentWeek,
actions: { prevWeek, nextWeek, goToStartWeek, goToEndWeek },
status: { isStartWeek, isEndWeek },
};
};

Expand Down

0 comments on commit 0ebdf29

Please sign in to comment.