Skip to content

Commit

Permalink
Update entity and store files, and components for better code organiz…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
gihoekveld committed Apr 13, 2024
1 parent d412eab commit 997d419
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 126 deletions.
6 changes: 3 additions & 3 deletions src/components/ScheduleCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ interface ScheduleCardProps {
id: string
title: string
priority: 'high' | 'medium' | 'low' | 'routine' | 'event'
done: boolean
status: 'pending' | 'in-progress' | 'done'
startTime: string
endTime: string
}

export const ScheduleCard = ({
id,
title,
done,
status,
priority,
startTime,
endTime,
}: ScheduleCardProps) => {
const [openEditRoutineDialog, setOpenEditRoutineDialog] = useState(false)
const [openEditTaskDialog, setOpenEditTaskDialog] = useState(false)
const [openDeleteDialog, setOpenDeleteDialog] = useState(false)
const [completed, setCompleted] = useState(done)
const [completed, setCompleted] = useState(status === 'done')
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null)
const open = Boolean(anchorEl)
const { deleteSchedule } = useSchedulesStates()
Expand Down
2 changes: 1 addition & 1 deletion src/components/WeekSchedulesCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const WeekSchedulesCard = ({
key={schedule.id}
id={schedule.id}
title={schedule.title}
done={schedule.done}
status={schedule.status}
priority={schedule.priority}
startTime={`${schedule.startAt.getUTCHours().toString().padStart(2, '0')}:${schedule.startAt.getUTCMinutes().toString().padStart(2, '0')}`}
endTime={`${schedule.endAt.getUTCHours().toString().padStart(2, '0')}:${schedule.endAt.getUTCMinutes().toString().padStart(2, '0')}`}
Expand Down
10 changes: 0 additions & 10 deletions src/entities/Routine.ts

This file was deleted.

4 changes: 3 additions & 1 deletion src/entities/Schedule.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
export interface Schedule {
id: string
title: string
done: boolean
status: 'pending' | 'in-progress' | 'done'
priority: 'high' | 'medium' | 'low' | 'routine' | 'event'
startAt: Date
endAt: Date
deadline: Date
notes?: string
tags?: string[]
}
5 changes: 0 additions & 5 deletions src/entities/Tag.ts

This file was deleted.

14 changes: 0 additions & 14 deletions src/entities/Task.ts

This file was deleted.

38 changes: 14 additions & 24 deletions src/helpers/schedule/utils/allocateTask.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
import { beforeAll, describe, expect, it } from '@jest/globals'
import { advanceTo } from 'jest-date-mock'
import { allocateTask } from './allocateTask'

type UnallocatedTask = {
id: string
title: string
notes?: string
priority: 'low' | 'medium' | 'high'
duration: string
deadline: Date
}

type Schedule = {
id: string
title: string
done: boolean
priority: 'high' | 'medium' | 'low' | 'routine' | 'event'
startAt: Date
endAt: Date
}
import { Schedule } from '@/entities/Schedule'
import { UnallocatedTask } from '@/entities/UnallocatedTask'

describe('allocateTask', () => {
beforeAll(() => {
Expand All @@ -31,17 +15,19 @@ describe('allocateTask', () => {
id: '1',
title: 'Test Schedule',
priority: 'low',
done: false,
status: 'pending',
startAt: new Date('2022-01-01T08:00:00'),
endAt: new Date('2022-01-01T09:00:00'),
deadline: new Date('2022-01-14T12:00:00'),
},
{
id: '2',
title: 'Test Schedule',
priority: 'low',
done: false,
status: 'pending',
startAt: new Date('2022-01-01T10:00:00'),
endAt: new Date('2022-01-01T11:00:00'),
deadline: new Date('2022-01-14T12:00:00'),
},
]
const taskToAllocate: UnallocatedTask = {
Expand Down Expand Up @@ -73,17 +59,19 @@ describe('allocateTask', () => {
id: '1',
title: 'Test Schedule 1',
priority: 'low',
done: false,
status: 'pending',
startAt: new Date('2022-01-01T08:00:00'),
endAt: new Date('2022-01-01T09:00:00'),
deadline: new Date('2022-01-14T12:00:00'),
},
{
id: '2',
title: 'Test Schedule 2',
priority: 'low',
done: false,
status: 'pending',
startAt: new Date('2022-01-01T09:00:00'),
endAt: new Date('2022-01-01T10:00:00'),
deadline: new Date('2022-01-14T12:00:00'),
},
]

Expand Down Expand Up @@ -114,17 +102,19 @@ describe('allocateTask', () => {
id: '1',
title: 'Test Schedule',
priority: 'low',
done: false,
status: 'pending',
endAt: new Date('2022-01-01T09:00:00'),
startAt: new Date('2022-01-01T08:00:00'),
deadline: new Date('2022-01-14T12:00:00'),
},
{
id: '2',
title: 'Test Schedule',
priority: 'low',
done: false,
status: 'pending',
startAt: new Date('2022-01-01T09:00:00'),
endAt: new Date('2022-01-01T10:00:00'),
deadline: new Date('2022-01-14T12:00:00'),
},
]

Expand Down
4 changes: 2 additions & 2 deletions src/helpers/schedule/utils/allocateTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const allocateTask = (
newSchedule = {
id: taskToAllocate.id,
title: taskToAllocate.title,
done: false,
status: 'pending',
priority: taskToAllocate.priority,
startAt: new Date(previousSchedule.endAt),
endAt: new Date(newScheduleEndAt),
Expand Down Expand Up @@ -73,7 +73,7 @@ export const allocateTask = (
newSchedule = {
id: taskToAllocate.id,
title: taskToAllocate.title,
done: false,
status: 'pending',
priority: taskToAllocate.priority,
startAt: new Date(previousSchedule.endAt),
endAt: new Date(newScheduleEndAt),
Expand Down
20 changes: 13 additions & 7 deletions src/helpers/schedule/utils/isThereGapBetweenSchedules.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import { describe, expect, it } from '@jest/globals'
import { Schedule } from '../entities/Schedule'
import { isThereGapBetweenSchedules } from './isThereGapBetweenSchedules'
import { Schedule } from '@/entities/Schedule'

describe('isThereGapBetweenSchedules', () => {
it('should return true if there is a gap between schedules', () => {
const previousSchedule: Schedule = {
id: '1',
title: 'Test Schedule',
priority: 'low',
done: false,
status: 'pending',
startAt: new Date('2022-01-01T08:00:00'),
endAt: new Date('2022-01-01T09:00:00'),
deadline: new Date('2022-01-10T09:00:00'),
}
const nextSchedule: Schedule = {
id: '2',
title: 'Test Schedule',
priority: 'low',
done: false,
status: 'pending',
startAt: new Date('2022-01-01T10:00:00'),
endAt: new Date('2022-01-01T11:00:00'),
deadline: new Date('2022-01-10T09:00:00'),
}
const newScheduleDuration = 30 // 30 minutes

Expand All @@ -36,17 +38,19 @@ describe('isThereGapBetweenSchedules', () => {
id: '1',
title: 'Test Schedule',
priority: 'low',
done: false,
status: 'pending',
startAt: new Date('2022-01-01T08:00:00'),
endAt: new Date('2022-01-01T09:00:00'),
deadline: new Date('2022-01-10T09:00:00'),
}
const nextSchedule: Schedule = {
id: '2',
title: 'Test Schedule',
priority: 'low',
done: false,
status: 'pending',
startAt: new Date('2022-01-01T09:30:00'),
endAt: new Date('2022-01-01T11:00:00'),
deadline: new Date('2022-01-10T09:00:00'),
}
const newScheduleDuration = 30 // 30 minutes

Expand All @@ -64,17 +68,19 @@ describe('isThereGapBetweenSchedules', () => {
id: '1',
title: 'Test Schedule',
priority: 'low',
done: false,
status: 'pending',
startAt: new Date('2022-01-01T08:00:00'),
endAt: new Date('2022-01-01T09:00:00'),
deadline: new Date('2022-01-10T09:00:00'),
}
const nextSchedule: Schedule = {
id: '2',
title: 'Test Schedule',
priority: 'low',
done: false,
status: 'pending',
startAt: new Date('2022-01-01T09:30:00'),
endAt: new Date('2022-01-01T11:00:00'),
deadline: new Date('2022-01-10T09:00:00'),
}
const newScheduleDuration = 45 // 45 minutes

Expand Down
Loading

0 comments on commit 997d419

Please sign in to comment.