Skip to content

Commit

Permalink
Merge pull request #564 from asuc-octo/jaden-refactor-lodash
Browse files Browse the repository at this point in the history
Remove dependency on lodash
  • Loading branch information
mathhulk authored Mar 16, 2023
2 parents 47bf3e8 + 807761d commit 1d743c8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
2 changes: 0 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"date-fns": "^2.21.1",
"graphql": "^15.4.0",
"js-yaml": "^3.13.1",
"lodash-es": "^4.17.21",
"object-hash": "^3.0.0",
"react": "^18.0.0",
"react-bootstrap": "^1.3.0",
Expand Down Expand Up @@ -58,7 +57,6 @@
"@graphql-typed-document-node/core": "^3.1.1",
"@types/color": "^3.0.1",
"@types/js-yaml": "^3.12.5",
"@types/lodash-es": "^4.17.6",
"@types/node": "^14.6.1",
"@types/react": "^18.0.27",
"@types/react-dom": "^18.0.10",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useCallback, useEffect, useRef, useState, Dispatch, SetStateAction } fr
import { deserializeSchedule, Schedule, serializeSchedule } from 'utils/scheduler/scheduler';
import ScheduleEditor from '../ScheduleEditor';
import { Semester } from 'utils/playlists/semesters';
import { debounce } from 'lodash-es';
import debounce from 'utils/debounce';
import Callout from '../Callout';

// This is NOT a loop. Rather it combines all
Expand Down
13 changes: 13 additions & 0 deletions frontend/src/utils/debounce.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

export default function debounce<T extends (...args: any[]) => any>(
func: T,
wait: number
) {
let timeout: number | undefined;
return (...args: any[]) => {
if (!timeout) func(...args);
clearTimeout(timeout);
timeout = setTimeout(() => func(...args), wait);
};
}
7 changes: 5 additions & 2 deletions frontend/src/utils/sections/sort.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { SectionFragment } from 'graphql';
import { groupBy } from 'lodash-es';
import { stringToDate } from 'utils/date';
import { isEnrollmentSection } from './section';

Expand Down Expand Up @@ -60,7 +59,11 @@ export function sortSections(sections: SectionFragment[]): SectionFragment[] {
* Sorts a list of sections into ([type, [sections]])
*/
export function groupSections(sections: SectionFragment[]) {
return Object.entries(groupBy(sections, (s) => s.kind))
const groups = sections.reduce(
(r, v) => ({ ...r, [v.kind]: [...(r[v.kind] ?? []), v] }),
{} as { [key: string]: SectionFragment[] }
);
return Object.entries(groups)
.sort((a, b) => (SECTION_TYPE_ORDER[a[0]] ?? Infinity) - SECTION_TYPE_ORDER[b[0]])
.map(([category, sections]) => ({
category,
Expand Down

0 comments on commit 1d743c8

Please sign in to comment.