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 redux reducer about planner #63

Merged
merged 10 commits into from
May 13, 2024
11 changes: 1 addition & 10 deletions src/actions/planner/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export const RESET = `${BASE_STRING}RESET` as const;
export const SET_SELECTED_LIST_CODE = `${BASE_STRING}SER_SELECTED_LIST_CODE` as const;
export const SET_LIST_COURSES = `${BASE_STRING}SET_LIST_COURSES` as const;
export const CLEAR_SEARCH_LIST_COURSES = `${BASE_STRING}CLEAR_SEARCH_LIST_COURSES` as const;
export const ADD_COURSE_READ = `${BASE_STRING}ADD_COURSE_READ` as const;

import { CourseListCode } from '@/shapes/enum';
import Course from '@/shapes/model/subject/Course';
Expand Down Expand Up @@ -36,16 +35,8 @@ export function clearSearchListCourses() {
};
}

export function addCourseRead(course: Course) {
return {
type: ADD_COURSE_READ,
course: course,
};
}

export type ListAction =
| ReturnType<typeof reset>
| ReturnType<typeof setSelectedListCode>
| ReturnType<typeof setListCourses>
| ReturnType<typeof clearSearchListCourses>
| ReturnType<typeof addCourseRead>;
| ReturnType<typeof clearSearchListCourses>;
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ const CombinedReducer = combineReducers({
search: search,
});

export type PlannerState = ReturnType<typeof CombinedReducer>;
export default CombinedReducer;
80 changes: 0 additions & 80 deletions src/reducers/planner/itemFocus.js

This file was deleted.

112 changes: 112 additions & 0 deletions src/reducers/planner/itemFocus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import {

Check warning on line 1 in src/reducers/planner/itemFocus.ts

View check run for this annotation

Codecov / codecov/patch

src/reducers/planner/itemFocus.ts#L1

Added line #L1 was not covered by tests
RESET,
SET_ITEM_FOCUS,
CLEAR_ITEM_FOCUS,
SET_CATEGORY_FOCUS,
CLEAR_CATEGORY_FOCUS,
SET_REVIEWS,
SET_LECTURES,
ItemFocusAction,
} from '@/actions/planner/itemFocus';
import { ItemFocusFrom } from '@/shapes/enum';

Check warning on line 11 in src/reducers/planner/itemFocus.ts

View check run for this annotation

Codecov / codecov/patch

src/reducers/planner/itemFocus.ts#L11

Added line #L11 was not covered by tests
import ItemFocus from '@/shapes/state/planner/ItemFocus';

const initialState: ItemFocus = {

Check warning on line 14 in src/reducers/planner/itemFocus.ts

View check run for this annotation

Codecov / codecov/patch

src/reducers/planner/itemFocus.ts#L14

Added line #L14 was not covered by tests
from: ItemFocusFrom.NONE,
clicked: false,
item: null,
course: null,
category: null,
reviews: null,
lectures: null,
};

/*
모든 ItemFocus 는 아래 5가지 중 하나의 타입을 가짐
type ItemFocus = NoneItem | ListItem | AddingItem | TableItem | CategoryItem;

CategoryItem 에 focusing 할 경우에는 SET_CATEGORY_FOCUS 액션을,
ListItem | AddingItem | TableItem 에 focusing 할 경우에는 SET_ITEM_FOCUS 액션을 사용함.

(구체적인 사진은 notion과 PR 에 첨부된 사진을 참고.)
1. NoneItem
포커싱된 아이템이 없을 때.
2. ListItem
Planner 테이블 아래의 course list 중 하나의 항목을 클릭했을 때 포커싱되는 상태를 나타냄.
3. AddingItem
Planner 테이블에 아이템을 추가할 때
4. TableItem
Planner 테이블에서 각 항목을 클릭했을 때 포커싱되는 상태를 나타냄.
Future, Taken, Arbitrary 중하나임.
5. CategoryItem
플래너 우측의 기초/전공/교양 과목의 이수 상황을 보여주는 바에서 특정 카테고리를 호버하면 Focus, 언호버하면 Focus 해제됨.
[CategoryIndex, N, M]
CategoryIndex: 0, 1, 2, 3, 4 중 하나.
순서대로 기초, 전공, 연구, 교양, 기타.
N:
세부 전공을 의미. 전공/부전/복수/심화/자유 등을 가르킴.
M:
0, 1 중 하나. 0이면 필수 과목, 1이면 선택 과목.
(ex. [0, 1, 0] => 기초 1번째 필수 과목)
*/
const itemFocus = (state: ItemFocus = initialState, action: ItemFocusAction) => {
switch (action.type) {
case RESET: {
return initialState;

Check warning on line 55 in src/reducers/planner/itemFocus.ts

View check run for this annotation

Codecov / codecov/patch

src/reducers/planner/itemFocus.ts#L54-L55

Added lines #L54 - L55 were not covered by tests
}
case SET_ITEM_FOCUS: {

Check warning on line 57 in src/reducers/planner/itemFocus.ts

View check run for this annotation

Codecov / codecov/patch

src/reducers/planner/itemFocus.ts#L57

Added line #L57 was not covered by tests
const courseChanged = !state.course || state.course.id !== action.course.id;
const changedItem = courseChanged ? { reviews: null, lectures: null } : {};
return {

Check warning on line 60 in src/reducers/planner/itemFocus.ts

View check run for this annotation

Codecov / codecov/patch

src/reducers/planner/itemFocus.ts#L60

Added line #L60 was not covered by tests
...state,
from: action.from,
clicked: action.clicked,
item: action.item,
course: action.course,
changedItem,
};
}
case CLEAR_ITEM_FOCUS: {
return {

Check warning on line 70 in src/reducers/planner/itemFocus.ts

View check run for this annotation

Codecov / codecov/patch

src/reducers/planner/itemFocus.ts#L69-L70

Added lines #L69 - L70 were not covered by tests
...state,
from: ItemFocusFrom.NONE,
clicked: false,
item: null,
course: null,
reviews: null,
lectures: null,
};
}
case SET_CATEGORY_FOCUS: {
return {

Check warning on line 81 in src/reducers/planner/itemFocus.ts

View check run for this annotation

Codecov / codecov/patch

src/reducers/planner/itemFocus.ts#L80-L81

Added lines #L80 - L81 were not covered by tests
...state,
from: ItemFocusFrom.CATEGORY,
category: action.category,
};
}
case CLEAR_CATEGORY_FOCUS: {
return {

Check warning on line 88 in src/reducers/planner/itemFocus.ts

View check run for this annotation

Codecov / codecov/patch

src/reducers/planner/itemFocus.ts#L87-L88

Added lines #L87 - L88 were not covered by tests
...state,
from: ItemFocusFrom.NONE,
category: null,
};
}
case SET_REVIEWS: {
return {

Check warning on line 95 in src/reducers/planner/itemFocus.ts

View check run for this annotation

Codecov / codecov/patch

src/reducers/planner/itemFocus.ts#L94-L95

Added lines #L94 - L95 were not covered by tests
...state,
reviews: action.reviews,
};
}
case SET_LECTURES: {
return {

Check warning on line 101 in src/reducers/planner/itemFocus.ts

View check run for this annotation

Codecov / codecov/patch

src/reducers/planner/itemFocus.ts#L100-L101

Added lines #L100 - L101 were not covered by tests
...state,
lectures: action.lectures,
};
}
default: {
return state;

Check warning on line 107 in src/reducers/planner/itemFocus.ts

View check run for this annotation

Codecov / codecov/patch

src/reducers/planner/itemFocus.ts#L106-L107

Added lines #L106 - L107 were not covered by tests
}
}
};

export default itemFocus;

Check warning on line 112 in src/reducers/planner/itemFocus.ts

View check run for this annotation

Codecov / codecov/patch

src/reducers/planner/itemFocus.ts#L112

Added line #L112 was not covered by tests
66 changes: 0 additions & 66 deletions src/reducers/planner/list.js

This file was deleted.

82 changes: 82 additions & 0 deletions src/reducers/planner/list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import {

Check warning on line 1 in src/reducers/planner/list.ts

View check run for this annotation

Codecov / codecov/patch

src/reducers/planner/list.ts#L1

Added line #L1 was not covered by tests
RESET,
SET_SELECTED_LIST_CODE,
SET_LIST_COURSES,
CLEAR_SEARCH_LIST_COURSES,
ListAction,
} from '../../actions/planner/list';

import { CourseListCode, DepartmentCode } from '@/shapes/enum';

Check warning on line 9 in src/reducers/planner/list.ts

View check run for this annotation

Codecov / codecov/patch

src/reducers/planner/list.ts#L9

Added line #L9 was not covered by tests
import Course from '@/shapes/model/subject/Course';

type CourseDepartmentLists = {
[K in CourseListCode]: {
courses: Course[] | null;
};
} & {
[K in DepartmentCode]?: {
courses: Course[] | null;
};
};
yumincho marked this conversation as resolved.
Show resolved Hide resolved

interface ListState {
selectedListCode: CourseListCode | DepartmentCode;
lists: CourseDepartmentLists;
}

const initialState: ListState = {

Check warning on line 27 in src/reducers/planner/list.ts

View check run for this annotation

Codecov / codecov/patch

src/reducers/planner/list.ts#L27

Added line #L27 was not covered by tests
selectedListCode: CourseListCode.SEARCH,
lists: {
[CourseListCode.SEARCH]: {
courses: [],
},
[CourseListCode.BASIC]: {
courses: null,
},
[CourseListCode.HUMANITY]: {
courses: null,
},
[CourseListCode.TAKEN]: {
courses: null,
},
},
};

const list = (state = initialState, action: ListAction) => {
switch (action.type) {
case RESET: {
return initialState;

Check warning on line 48 in src/reducers/planner/list.ts

View check run for this annotation

Codecov / codecov/patch

src/reducers/planner/list.ts#L47-L48

Added lines #L47 - L48 were not covered by tests
}
case SET_SELECTED_LIST_CODE: {
return { ...state, selectedListCode: action.listCode };

Check warning on line 51 in src/reducers/planner/list.ts

View check run for this annotation

Codecov / codecov/patch

src/reducers/planner/list.ts#L50-L51

Added lines #L50 - L51 were not covered by tests
}
case SET_LIST_COURSES: {
return {

Check warning on line 54 in src/reducers/planner/list.ts

View check run for this annotation

Codecov / codecov/patch

src/reducers/planner/list.ts#L53-L54

Added lines #L53 - L54 were not covered by tests
...state,
lists: {
...state.lists,
[action.code]: {
...state.lists[action.code],
courses: action.courses,
},
},
};
yumincho marked this conversation as resolved.
Show resolved Hide resolved
}
case CLEAR_SEARCH_LIST_COURSES:
return {

Check warning on line 66 in src/reducers/planner/list.ts

View check run for this annotation

Codecov / codecov/patch

src/reducers/planner/list.ts#L65-L66

Added lines #L65 - L66 were not covered by tests
...state,
lists: {
...state.lists,
[CourseListCode.SEARCH]: {
...state.lists[CourseListCode.SEARCH],
courses: null,
},
},
};
default: {
return state;

Check warning on line 77 in src/reducers/planner/list.ts

View check run for this annotation

Codecov / codecov/patch

src/reducers/planner/list.ts#L76-L77

Added lines #L76 - L77 were not covered by tests
}
}
};

export default list;

Check warning on line 82 in src/reducers/planner/list.ts

View check run for this annotation

Codecov / codecov/patch

src/reducers/planner/list.ts#L82

Added line #L82 was not covered by tests
Loading
Loading