-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorganization of dashboard util functions
- Loading branch information
1 parent
0ee6e57
commit 8599236
Showing
17 changed files
with
180 additions
and
159 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
2 changes: 1 addition & 1 deletion
2
app/features/middlePanel/dashboard/components/DroppableContainer.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
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
2 changes: 1 addition & 1 deletion
2
app/features/middlePanel/dashboard/helpers/hooks/useDragHandlers.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
2 changes: 1 addition & 1 deletion
2
app/features/middlePanel/dashboard/helpers/hooks/useOverlayComponents.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
This file was deleted.
Oops, something went wrong.
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,23 @@ | ||
import { CourseID, SemesterID, Course, CoursesBySemesterID } from "@/types/models"; | ||
|
||
export function calculateSemesterCredits(courseIds: CourseID[], courses: Record<CourseID, Course>): number { | ||
return courseIds.reduce((total: number, courseId) => { | ||
const course = courses[courseId]; | ||
return total + (course ? course.credits : 0); | ||
}, 0); | ||
} | ||
|
||
export function calculateRunningCredits( | ||
semesterOrder: SemesterID[], | ||
coursesBySemesterID: CoursesBySemesterID, | ||
courses: Record<CourseID, Course>, | ||
currentSemesterId: SemesterID | ||
): number { | ||
let total = 0; | ||
for (const semesterId of semesterOrder) { | ||
const credits = calculateSemesterCredits(coursesBySemesterID[semesterId] || [], courses); | ||
total += credits; | ||
if (semesterId === currentSemesterId) break; | ||
} | ||
return total; | ||
} |
15 changes: 15 additions & 0 deletions
15
app/features/middlePanel/dashboard/utils/dnd/animations.ts
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,15 @@ | ||
import { DropAnimation, defaultDropAnimationSideEffects } from "@dnd-kit/core"; | ||
import { AnimateLayoutChanges, defaultAnimateLayoutChanges } from "@dnd-kit/sortable"; | ||
|
||
export const dropAnimation: DropAnimation = { | ||
sideEffects: defaultDropAnimationSideEffects({ | ||
styles: { | ||
active: { | ||
opacity: "0.5", | ||
}, | ||
}, | ||
}), | ||
}; | ||
|
||
export const animateLayoutChanges: AnimateLayoutChanges = (args) => | ||
defaultAnimateLayoutChanges({ ...args, wasDragging: true }); |
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
43 changes: 43 additions & 0 deletions
43
app/features/middlePanel/dashboard/utils/dnd/containers.ts
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,43 @@ | ||
import { COURSE_CREATION_CONTAINER_ID } from "@/app/features/leftPanel/courseCreation/CourseCreation"; | ||
import { CoursesBySemesterID } from "@/types/models"; | ||
import { UniqueIdentifier } from "@dnd-kit/core"; | ||
|
||
export const findContainer = ( | ||
items: CoursesBySemesterID, | ||
id: UniqueIdentifier | ||
) => { | ||
if (id in items) { | ||
return id; | ||
} | ||
|
||
const container = Object.keys(items).find((key) => items[key].includes(id)); | ||
return container; | ||
}; | ||
|
||
export const getIndex = ( | ||
items: CoursesBySemesterID, | ||
id: UniqueIdentifier | ||
) => { | ||
const container = findContainer(items, id); | ||
|
||
if (container === COURSE_CREATION_CONTAINER_ID) { | ||
return 0; | ||
} | ||
|
||
if (!container) { | ||
return -1; | ||
} | ||
|
||
const index = items[container].indexOf(id); | ||
|
||
return index; | ||
} | ||
|
||
export const getNextContainerId = ( | ||
items: CoursesBySemesterID | ||
) => { | ||
const containerIds = Object.keys(items); | ||
const lastContainerId = containerIds[containerIds.length - 1]; | ||
|
||
return String.fromCharCode(lastContainerId.charCodeAt(0) + 1); | ||
} |
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,4 @@ | ||
export * from './animations'; | ||
export * from './collisions'; | ||
export * from './containers'; | ||
export * from './styles'; |
Oops, something went wrong.