Skip to content

Commit

Permalink
feat: add reducer return types
Browse files Browse the repository at this point in the history
  • Loading branch information
yumincho committed May 18, 2024
1 parent 4b013a8 commit e2b8a4e
Show file tree
Hide file tree
Showing 16 changed files with 34 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/reducers/dictionary/courseFocus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const initialState: CourseFocusState = {
lectures: null,
};

const courseFocus = (state = initialState, action: DictionaryAction) => {
const courseFocus = (state = initialState, action: DictionaryAction): CourseFocusState => {
switch (action.type) {
case RESET: {
return initialState;
Expand Down
2 changes: 1 addition & 1 deletion src/reducers/dictionary/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const initialState: ListState = {
readCourses: [],
};

const list = (state = initialState, action: DictionaryAction) => {
const list = (state = initialState, action: DictionaryAction): ListState => {
switch (action.type) {
case RESET: {
return initialState;
Expand Down
2 changes: 1 addition & 1 deletion src/reducers/dictionary/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const initialState: SearchState = {
lastSearchOption: {},
};

const search = (state = initialState, action: CourseAction) => {
const search = (state = initialState, action: CourseAction): SearchState => {
switch (action.type) {
case RESET: {
return initialState;
Expand Down
28 changes: 17 additions & 11 deletions src/reducers/planner/itemFocus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,23 @@ import {
ItemFocusAction,
} from '@/actions/planner/itemFocus';
import { ItemFocusFrom } from '@/shapes/enum';
import ItemFocus from '@/shapes/state/planner/ItemFocus';
import ItemFocus, {
AddingItem,
CategoryItem,
ListItem,
NoneItem,
TableItem,
} from '@/shapes/state/planner/ItemFocus';

const initialState: ItemFocus = {
const initialState = {

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

View check run for this annotation

Codecov / codecov/patch

src/reducers/planner/itemFocus.ts#L20

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

/*
모든 ItemFocus 는 아래 5가지 중 하나의 타입을 가짐
Expand Down Expand Up @@ -49,7 +55,7 @@ const initialState: ItemFocus = {
0, 1 중 하나. 0이면 필수 과목, 1이면 선택 과목.
(ex. [0, 1, 0] => 기초 1번째 필수 과목)
*/
const itemFocus = (state: ItemFocus = initialState, action: ItemFocusAction) => {
const itemFocus = (state = initialState, action: ItemFocusAction): ItemFocus => {
switch (action.type) {
case RESET: {
return initialState;
Expand All @@ -63,8 +69,8 @@ const itemFocus = (state: ItemFocus = initialState, action: ItemFocusAction) =>
clicked: action.clicked,
item: action.item,
course: action.course,
changedItem,
};
...changedItem,
} as ListItem | AddingItem | TableItem;
}
case CLEAR_ITEM_FOCUS: {
return {
Expand All @@ -75,33 +81,33 @@ const itemFocus = (state: ItemFocus = initialState, action: ItemFocusAction) =>
course: null,
reviews: null,
lectures: null,
};
} as NoneItem;
}
case SET_CATEGORY_FOCUS: {
return {
...state,
from: ItemFocusFrom.CATEGORY,
category: action.category,
};
} as CategoryItem;
}
case CLEAR_CATEGORY_FOCUS: {
return {
...state,
from: ItemFocusFrom.NONE,
category: null,
};
} as NoneItem;
}
case SET_REVIEWS: {
return {
...state,
reviews: action.reviews,
};
} as ListItem | AddingItem | TableItem;
}
case SET_LECTURES: {
return {
...state,
lectures: action.lectures,
};
} as ListItem | AddingItem | TableItem;
}
default: {
return state;
Expand Down
2 changes: 1 addition & 1 deletion src/reducers/planner/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const initialState: ListState = {
},
};

const list = (state = initialState, action: ListAction) => {
const list = (state = initialState, action: ListAction): ListState => {
switch (action.type) {
case RESET: {
return initialState;
Expand Down
4 changes: 2 additions & 2 deletions src/reducers/planner/planner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const getListNameOfType = (type: PlannerItemType) => {
SET_IS_TRACK_SETTINGS_SECTION_OPEN
planner 관련 정보를 수정하는 팝업창이 열려있는지 여부를 변경하는 action
*/
const planner = (state = initialState, action: PlannerAction) => {
const planner = (state = initialState, action: PlannerAction): PlannerState => {
switch (action.type) {
case RESET: {
return initialState;
Expand Down Expand Up @@ -218,7 +218,7 @@ const planner = (state = initialState, action: PlannerAction) => {
return t;
});
newPlanners.sort((t1, t2) => t1.arrange_order - t2.arrange_order);
const updatedPlanner = newPlanners.find((t) => t.id === state.selectedPlanner?.id);
const updatedPlanner = newPlanners.find((t) => t.id === state.selectedPlanner?.id) || null;
return {
...state,
planners: newPlanners,
Expand Down
2 changes: 1 addition & 1 deletion src/reducers/planner/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const initialState: SearchState = {
lastSearchOption: {},
};

const search = (state = initialState, action: SearchAction) => {
const search = (state = initialState, action: SearchAction): SearchState => {
switch (action.type) {
case RESET: {
return initialState;
Expand Down
2 changes: 1 addition & 1 deletion src/reducers/timetable/lectureFocus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const initialState: LectureFocusState = {
multipleDetails: [],
};

const lectureFocus = (state = initialState, action: LectureFocusAction) => {
const lectureFocus = (state = initialState, action: LectureFocusAction): LectureFocusState => {
switch (action.type) {
case RESET: {
return initialState;
Expand Down
2 changes: 1 addition & 1 deletion src/reducers/timetable/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const initialState: ListState = {
isLectureListOpenOnMobile: false,
};

const list = (state = initialState, action: LectureListAction) => {
const list = (state = initialState, action: LectureListAction): ListState => {
const groupLectures = (lectures: Lecture[]) => {
const sortedLectures = lectures.sort((a, b) => {
if (a.old_code !== b.old_code) {
Expand Down
3 changes: 1 addition & 2 deletions src/reducers/timetable/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
} from '@/actions/timetable/search';
import { Day } from '@/shapes/enum';
import LectureLastSearchOption from '@/shapes/state/timetable/LectureLastSearchOption';
import { stat } from 'fs';

interface SearchState {
open: boolean;
Expand All @@ -27,7 +26,7 @@ const initialState: SearchState = {
classtimeDay: null,
};

const search = (state = initialState, action: SearchAction) => {
const search = (state = initialState, action: SearchAction): SearchState => {
switch (action.type) {
case RESET: {
return initialState;
Expand Down
2 changes: 1 addition & 1 deletion src/reducers/timetable/semester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const initialState: SemesterState = {
semester: null,
};

const semester = (state = initialState, action: SemesterAction) => {
const semester = (state = initialState, action: SemesterAction): SemesterState => {
switch (action.type) {
case RESET: {
return initialState;
Expand Down
4 changes: 2 additions & 2 deletions src/reducers/timetable/timetable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const initialState: TimetableState = {
isTimetableTabsOpenOnMobile: false,
};

const timetable = (state = initialState, action: TimetableAction) => {
const timetable = (state = initialState, action: TimetableAction): TimetableState => {
switch (action.type) {
case RESET: {
return initialState;
Expand Down Expand Up @@ -186,7 +186,7 @@ const timetable = (state = initialState, action: TimetableAction) => {
return t;
});
newTables.sort((t1, t2) => t1.arrange_order - t2.arrange_order);
const updatedTable = newTables.find((t) => t.id === state.selectedTimetable?.id);
const updatedTable = newTables.find((t) => t.id === state.selectedTimetable?.id) || null;
return { ...state, timetables: newTables, selectedTimetable: updatedTable };
}
case UPDATE_CELL_SIZE: {
Expand Down
2 changes: 1 addition & 1 deletion src/reducers/write-reviews/latestReviews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const initialState: LatestReviewsState = {
reviews: null,
};

const latestReviews = (state = initialState, action: LatestReviewsAction) => {
const latestReviews = (state = initialState, action: LatestReviewsAction): LatestReviewsState => {
switch (action.type) {
case RESET: {
return initialState;
Expand Down
2 changes: 1 addition & 1 deletion src/reducers/write-reviews/likedReviews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const initialState: LikedReviewsState = {
reviews: null,
};

const likedReviews = (state = initialState, action: LikedReviewsAction) => {
const likedReviews = (state = initialState, action: LikedReviewsAction): LikedReviewsState => {
switch (action.type) {
case RESET: {
return initialState;
Expand Down
2 changes: 1 addition & 1 deletion src/reducers/write-reviews/rankedReviews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const initialState: RankedReviewState = {
reviewCountBySemester: {},
};

const latestReviews = (state = initialState, action: RankedReviewsAction) => {
const latestReviews = (state = initialState, action: RankedReviewsAction): RankedReviewState => {
switch (action.type) {
case RESET: {
return initialState;
Expand Down
2 changes: 1 addition & 1 deletion src/reducers/write-reviews/reviewsFocus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const initialState: ReviewsFocusState = {
reviews: null,
};

const reviewsFocus = (state = initialState, action: ReviewsFocusAction) => {
const reviewsFocus = (state = initialState, action: ReviewsFocusAction): ReviewsFocusState => {
switch (action.type) {
case RESET: {
return initialState;
Expand Down

0 comments on commit e2b8a4e

Please sign in to comment.