-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from sparcs-kaist/migration@reducers/dictionary
Migrate redux reducer about dictionary
- Loading branch information
Showing
7 changed files
with
161 additions
and
138 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
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,86 @@ | ||
import { | ||
RESET, | ||
SET_SELECTED_LIST_CODE, | ||
SET_LIST_COURSES, | ||
CLEAR_SEARCH_LIST_COURSES, | ||
ADD_COURSE_READ, | ||
DictionaryAction, | ||
} from '@/actions/dictionary/list'; | ||
|
||
import { CourseListCode } from '@/shapes/enum'; | ||
import Course from '@/shapes/model/subject/Course'; | ||
|
||
interface ListState { | ||
selectedListCode: CourseListCode; | ||
lists: { | ||
[key in CourseListCode]: { | ||
courses: Course[] | null; | ||
}; | ||
}; | ||
readCourses: Course[]; | ||
} | ||
|
||
const initialState: ListState = { | ||
selectedListCode: CourseListCode.SEARCH, | ||
lists: { | ||
[CourseListCode.SEARCH]: { | ||
courses: [], | ||
}, | ||
[CourseListCode.BASIC]: { | ||
courses: null, | ||
}, | ||
[CourseListCode.HUMANITY]: { | ||
courses: null, | ||
}, | ||
[CourseListCode.TAKEN]: { | ||
courses: null, | ||
}, | ||
}, | ||
readCourses: [], | ||
}; | ||
|
||
const list = (state = initialState, action: DictionaryAction) => { | ||
switch (action.type) { | ||
case RESET: { | ||
return initialState; | ||
} | ||
case SET_SELECTED_LIST_CODE: { | ||
return { ...state, selectedListCode: action.listCode }; | ||
} | ||
case SET_LIST_COURSES: { | ||
return { | ||
...state, | ||
lists: { | ||
...state.lists, | ||
[action.code]: { | ||
...state.lists[action.code], | ||
courses: action.courses, | ||
}, | ||
}, | ||
}; | ||
} | ||
case CLEAR_SEARCH_LIST_COURSES: { | ||
return { | ||
...state, | ||
lists: { | ||
...state.lists, | ||
[CourseListCode.SEARCH]: { | ||
...state.lists[CourseListCode.SEARCH], | ||
courses: null, | ||
}, | ||
}, | ||
}; | ||
} | ||
case ADD_COURSE_READ: { | ||
return { | ||
...state, | ||
readCourses: [...state.readCourses, action.course], | ||
}; | ||
} | ||
default: { | ||
return state; | ||
} | ||
} | ||
}; | ||
|
||
export default list; |
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,40 @@ | ||
import { | ||
RESET, | ||
OPEN_SEARCH, | ||
CLOSE_SEARCH, | ||
SET_LAST_SEARCH_OPTION, | ||
CourseAction, | ||
} from '@/actions/dictionary/search'; | ||
import CourseLastSearchOption from '@/shapes/state/dictionary/CourseLastSearchOption'; | ||
|
||
interface SearchState { | ||
open: boolean; | ||
lastSearchOption: CourseLastSearchOption; | ||
} | ||
|
||
const initialState: SearchState = { | ||
open: true, | ||
lastSearchOption: {}, | ||
}; | ||
|
||
const search = (state = initialState, action: CourseAction) => { | ||
switch (action.type) { | ||
case RESET: { | ||
return initialState; | ||
} | ||
case OPEN_SEARCH: { | ||
return { ...state, open: true }; | ||
} | ||
case CLOSE_SEARCH: { | ||
return { ...state, open: false }; | ||
} | ||
case SET_LAST_SEARCH_OPTION: { | ||
return { ...state, lastSearchOption: action.lastSearchOption }; | ||
} | ||
default: { | ||
return state; | ||
} | ||
} | ||
}; | ||
|
||
export default search; |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
export default interface CourseLastSearchOption { | ||
keyword: string; | ||
type: string[]; | ||
department: string[]; | ||
grade: string[]; | ||
term: string[]; | ||
keyword?: string; | ||
type?: string[]; | ||
department?: string[]; | ||
grade?: string[]; | ||
term?: string[]; | ||
} |