Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate util functions #78

Merged
merged 5 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 42 additions & 38 deletions src/shapes/enum.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export const enum AdditionalTrackType {
DOUBLE,
MINOR,
ADVANCED,
INTERDISCIPLINARY,
DOUBLE = 'DOUBLE', // 복수전공
MINOR = 'MINOR', // 부전공
ADVANCED = 'ADVANCED', // 심화전공
INTERDISCIPLINARY = 'INTERDISCIPLINARY', // 융합전공
}

export const enum SemesterType {
Expand All @@ -13,32 +13,31 @@ export const enum SemesterType {
}

export const enum ItemFocusFrom {
NONE,
LIST,
ADDING,
TABLE_TAKEN,
TABLE_FUTURE,
TABLE_ARBITRARY,
CATEGORY,
NONE = 'NONE',
LIST = 'LIST',
ADDING = 'ADDING',
TABLE_TAKEN = 'TABLE_TAKEN',
TABLE_FUTURE = 'TABLE_FUTURE',
TABLE_ARBITRARY = 'TABLE_ARBITRARY',
CATEGORY = 'CATEGORY',
}

export const enum LectureFocusFrom {
NONE,
LIST,
TABLE,
MULTIPLE,
NONE = 'NONE',
LIST = 'LIST',
TABLE = 'TABLE',
MULTIPLE = 'MULTIPLE',
}

export const enum ReviewsFocusFrom {
NONE,
LECTURE,
REVIEWS_LATEST,
REVIEWS_MY,
REVIEWS_LIKED,
REVIEWS_RANKED,
NONE = 'NONE',
LECTURE = 'LECTURE',
REVIEWS_LATEST = 'REVIEWS_LATEST',
REVIEWS_MY = 'REVIEWS_MY',
REVIEWS_LIKED = 'REVIEWS_LIKED',
REVIEWS_RANKED = 'REVIEWS_RANKED',
}

// string enum for PlannerSubSection.jsx
export const enum PlannerItemType {
TAKEN = 'TAKEN',
FUTURE = 'FUTURE',
Expand All @@ -55,32 +54,32 @@ export const enum CategoryFirstIndex {
}

export const enum CourseListCode {
SEARCH,
BASIC,
HUMANITY,
TAKEN,
SEARCH = 'SEARCH',
BASIC = 'BASIC',
HUMANITY = 'HUMANITY',
TAKEN = 'TAKEN',
}

export const enum LectureListCode {
SEARCH,
BASIC,
HUMANITY,
CART,
SEARCH = 'SEARCH',
BASIC = 'BASIC',
HUMANITY = 'HUMANITY',
CART = 'CART',
}

export const enum Day {
MON,
TUE,
WED,
THU,
FRI,
SAT,
SUN,
MON = 'MON',
TUE = 'TUE',
WED = 'WED',
THU = 'THU',
FRI = 'FRI',
SAT = 'SAT',
SUN = 'SUN',
}

/** Redux state 중에서 서버에서 course 또는 lecture를 fetch 해서 저장하는
* planner.list , timetable.list , dictionary.list 에서
아래 enum 을 optional key 로 사용합니다.*/
아래 enum 을 optional key 로 사용합니다.*/
export const enum DepartmentCode {
ALL = 'ALL',
HSS = 'HSS',
Expand All @@ -105,3 +104,8 @@ export const enum DepartmentCode {
BCS = 'BCS',
ETC = 'ETC',
}

export const enum Orientation {
HORIZONTAL = 'HORIZONTAL',
VERTICAL = 'VERTICAL',
}
Comment on lines +108 to +111
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) Orientation 대신.. direction을 쓰자고 이제 와서 말하면 이후 PR까지 고쳐야 해서 공사가 너무 커지겠군.... 수정하자는 말은 아니고 아쉬워서 말해봅니다 흑흑 😂

13 changes: 8 additions & 5 deletions src/shapes/state/planner/ItemFocus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ export interface NoneItem {
export interface ListItem {
from: ItemFocusFrom.LIST;
clicked: boolean;
item?: null;
item: null;
course?: Course | ArbitraryPseudoCourse;
category?: null;
category: null;
reviews?: Review[];
lectures?: Lecture[];
}

export interface AddingItem {
from: ItemFocusFrom.ADDING;
clicked: true;
item?: null;
item: null;
course?: Course | ArbitraryPseudoCourse;
category?: null;
reviews?: Review[];
Expand All @@ -53,7 +53,7 @@ export interface AddingItem {
export interface TableItem {
from: ItemFocusFrom.TABLE_TAKEN | ItemFocusFrom.TABLE_FUTURE | ItemFocusFrom.TABLE_ARBITRARY;
clicked: boolean;
item?: TakenPlannerItem | FuturePlannerItem | ArbitraryPlannerItem;
item: TakenPlannerItem | FuturePlannerItem | ArbitraryPlannerItem;
course?: Course | ArbitraryPseudoCourse;
category?: null;
reviews?: Review[];
Expand All @@ -63,13 +63,16 @@ export interface TableItem {
export interface CategoryItem {
from: ItemFocusFrom.CATEGORY;
clicked: boolean;
item?: null;
item: null;
course?: null;
category: number[];
reviews?: null;
lectures?: null;
}

export type PlannerItem = TakenPlannerItem | FuturePlannerItem | ArbitraryPlannerItem;
export type PlannerCourse = Course | ArbitraryPseudoCourse;

type ItemFocus = NoneItem | ListItem | AddingItem | TableItem | CategoryItem;

export default ItemFocus;
12 changes: 6 additions & 6 deletions src/shapes/state/timetable/LectureFocus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ export interface Detail {
interface FromNone {
from: LectureFocusFrom.NONE;
clicked: false;
lecture?: null;
reviews?: null;
lecture: null;
reviews: null;
multipleTitle: '';
multipleDetails: EmtpyArray;
}

interface FromListOrTable {
from: LectureFocusFrom.LIST | LectureFocusFrom.TABLE;
clicked: boolean;
lecture?: Lecture;
reviews?: Review[];
lecture: Lecture;
reviews: Review[];
multipleTitle: '';
multipleDetails: EmtpyArray;
}

interface FromMutliple {
from: LectureFocusFrom.MULTIPLE;
clicked: false;
lecture?: null;
reviews?: null;
lecture: null;
reviews: null;
multipleTitle: '';
multipleDetails: Detail[];
}
Expand Down
19 changes: 7 additions & 12 deletions src/shapes/state/timetable/LectureLists.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import type Lecture from '@/shapes/model/subject/Lecture';

interface LectureGroups {
lectureGroups: Lecture[][];
}
export default interface LectureLists {
search: {
lectureGroups: Lecture[][];
};
basic: {
lectureGroups: Lecture[][];
};
humanity: {
lectureGroups: Lecture[][];
};
cart: {
lectureGroups: Lecture[][];
};
search: LectureGroups;
basic: LectureGroups;
humanity: LectureGroups;
cart: LectureGroups;
}
6 changes: 4 additions & 2 deletions src/utils/commonUtils.jsx → src/utils/commonUtils.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import React from 'react';

export const unique = (array, compareFunction = undefined) => {
type ComapreFunc = <T>(v1: T, v2: T) => number;

export const unique = <T,>(array: T[], compareFunction: ComapreFunc) => {

Check warning on line 5 in src/utils/commonUtils.tsx

View check run for this annotation

Codecov / codecov/patch

src/utils/commonUtils.tsx#L5

Added line #L5 was not covered by tests
if (!compareFunction) {
return Array.from(new Set(array));
}
return array.filter((v, i) => array.findIndex((v2) => compareFunction(v, v2)) === i);
};

export const formatNewlineToBr = (content) => {
export const formatNewlineToBr = (content: string) => {

Check warning on line 12 in src/utils/commonUtils.tsx

View check run for this annotation

Codecov / codecov/patch

src/utils/commonUtils.tsx#L12

Added line #L12 was not covered by tests
const contentLines = content.split('\n');
return contentLines
.map((l, i) => ({
Expand Down
21 changes: 0 additions & 21 deletions src/utils/courseUtils.js

This file was deleted.

31 changes: 31 additions & 0 deletions src/utils/courseUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import Course from '@/shapes/model/subject/Course';
import User from '@/shapes/model/session/User';
import CourseFocus from '@/shapes/state/dictionary/CourseFocus';
import { getTranslatedString } from '@/utils/translationUtils';

Check warning on line 4 in src/utils/courseUtils.ts

View check run for this annotation

Codecov / codecov/patch

src/utils/courseUtils.ts#L4

Added line #L4 was not covered by tests

//Dictionary Page 에서 사용되는 유틸들입니다.

// Dictionary Page 의 Course List Section 에서 포커싱된 Course가 현재 Course이면 True를 반환합니다.
export const isFocused = (course: Course, courseFocus: CourseFocus) =>

Check warning on line 9 in src/utils/courseUtils.ts

View check run for this annotation

Codecov / codecov/patch

src/utils/courseUtils.ts#L9

Added line #L9 was not covered by tests
Boolean(courseFocus.course) && courseFocus.course?.id === course.id;

// Dictionary Page 의 Course List Section 에서 포커싱된 Course가 있고, 포커싱된 Course가 현재 Course가 아니면 True를 반환합니다.
export const isDimmedCourse = (course: Course, courseFocus: CourseFocus) =>

Check warning on line 13 in src/utils/courseUtils.ts

View check run for this annotation

Codecov / codecov/patch

src/utils/courseUtils.ts#L13

Added line #L13 was not covered by tests
Boolean(courseFocus.course) && courseFocus.course?.id !== course.id;

// Dictionary Page의 Course List Section에서 이미 수강한 Course 이면 True를 반환합니다.
// isTaken 이 True 이면 리뷰 작성하기 블록이 보여집니다.
export const isTaken = (courseId: number, user: User) =>
user.review_writable_lectures.some((l) => l.course === courseId);

Check warning on line 19 in src/utils/courseUtils.ts

View check run for this annotation

Codecov / codecov/patch

src/utils/courseUtils.ts#L18-L19

Added lines #L18 - L19 were not covered by tests

// Dictionary Page의 Course Block 에서 교수님들의 이름 리스트를 가져오기 위해 사용합니다.
export const getProfessorsFullStr = (course: Course) => {

Check warning on line 22 in src/utils/courseUtils.ts

View check run for this annotation

Codecov / codecov/patch

src/utils/courseUtils.ts#L22

Added line #L22 was not covered by tests
const professors = course.professors.slice().sort((a, b) => (a.name < b.name ? -1 : 1));
const professorNames = professors.map((p) => getTranslatedString(p, 'name'));
return professorNames.join(', ');

Check warning on line 25 in src/utils/courseUtils.ts

View check run for this annotation

Codecov / codecov/patch

src/utils/courseUtils.ts#L24-L25

Added lines #L24 - L25 were not covered by tests
};

export const isSpecialLectureCourse = (course: Course) =>

Check warning on line 28 in src/utils/courseUtils.ts

View check run for this annotation

Codecov / codecov/patch

src/utils/courseUtils.ts#L28

Added line #L28 was not covered by tests
course.title.includes('특강') ||
course.title_en.includes('Special Lectures') ||
course.title_en.includes('Special Topics');

Check warning on line 31 in src/utils/courseUtils.ts

View check run for this annotation

Codecov / codecov/patch

src/utils/courseUtils.ts#L30-L31

Added lines #L30 - L31 were not covered by tests
8 changes: 0 additions & 8 deletions src/utils/examtimeUtils.js

This file was deleted.

9 changes: 9 additions & 0 deletions src/utils/examtimeUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Examtime from '@/shapes/model/subject/Examtime';
import { getTranslatedString } from '@/utils/translationUtils';

export const getStr = (examtime: Examtime) => getTranslatedString(examtime, 'str');

export const getTimeStr = (examtime: Examtime) => {
const fullStr = getStr(examtime);

Check warning on line 7 in src/utils/examtimeUtils.ts

View check run for this annotation

Codecov / codecov/patch

src/utils/examtimeUtils.ts#L7

Added line #L7 was not covered by tests
return fullStr?.slice(fullStr.indexOf(' '));
};
Loading
Loading