diff --git a/src/actions/common/track.ts b/src/actions/common/track.ts index cb3503b..5e3909d 100644 --- a/src/actions/common/track.ts +++ b/src/actions/common/track.ts @@ -6,13 +6,13 @@ import GeneralTrack from '@/shapes/model/graduation/GeneralTrack'; import MajorTrack from '@/shapes/model/graduation/MajorTrack'; import AdditionalTrack from '@/shapes/model/graduation/AdditionalTrack'; -interface TracksProps { +export interface Tracks { general: GeneralTrack[]; major: MajorTrack[]; additional: AdditionalTrack[]; } -export function setTracks(tracks: TracksProps) { +export function setTracks(tracks: Tracks) { return { type: SET_TRACKS, tracks: tracks, diff --git a/src/reducers/common/index.js b/src/reducers/common/index.ts similarity index 83% rename from src/reducers/common/index.js rename to src/reducers/common/index.ts index a3cb827..76bf73f 100644 --- a/src/reducers/common/index.js +++ b/src/reducers/common/index.ts @@ -11,4 +11,5 @@ const CombinedReducer = combineReducers({ media: media, }); +export type CommonState = ReturnType; export default CombinedReducer; diff --git a/src/reducers/common/media.js b/src/reducers/common/media.js deleted file mode 100644 index aecca3a..0000000 --- a/src/reducers/common/media.js +++ /dev/null @@ -1,18 +0,0 @@ -import { SET_IS_PORTRAIT } from '../../actions/common/media'; - -const initialState = { - isPortrait: false, -}; - -export const reducer = (state = initialState, action) => { - switch (action.type) { - case SET_IS_PORTRAIT: - return Object.assign({}, state, { - isPortrait: action.isPortrait, - }); - default: - return state; - } -}; - -export default reducer; diff --git a/src/reducers/common/media.ts b/src/reducers/common/media.ts new file mode 100644 index 0000000..f373bfc --- /dev/null +++ b/src/reducers/common/media.ts @@ -0,0 +1,20 @@ +import { MediaAction, SET_IS_PORTRAIT } from '../../actions/common/media'; + +interface MediaState { + isPortrait: boolean; +} + +const initialState: MediaState = { + isPortrait: false, +}; + +const media = (state = initialState, action: MediaAction): MediaState => { + switch (action.type) { + case SET_IS_PORTRAIT: + return { ...state, isPortrait: action.isPortrait }; + default: + return state; + } +}; + +export default media; diff --git a/src/reducers/common/semester.js b/src/reducers/common/semester.js deleted file mode 100644 index a4829b0..0000000 --- a/src/reducers/common/semester.js +++ /dev/null @@ -1,18 +0,0 @@ -import { SET_SEMESTERS } from '../../actions/common/semester'; - -const initialState = { - semesters: null, -}; - -export const reducer = (state = initialState, action) => { - switch (action.type) { - case SET_SEMESTERS: - return Object.assign({}, state, { - semesters: action.semesters, - }); - default: - return state; - } -}; - -export default reducer; diff --git a/src/reducers/common/semester.ts b/src/reducers/common/semester.ts new file mode 100644 index 0000000..537f42f --- /dev/null +++ b/src/reducers/common/semester.ts @@ -0,0 +1,21 @@ +import { SET_SEMESTERS, SemesterAction } from '../../actions/common/semester'; +import Semester from '@/shapes/model/subject/Semester'; + +interface SemesterState { + semesters: Semester[] | null; +} + +const initialState: SemesterState = { + semesters: null, +}; + +const semester = (state = initialState, action: SemesterAction): SemesterState => { + switch (action.type) { + case SET_SEMESTERS: + return { ...state, semesters: action.semesters }; + default: + return state; + } +}; + +export default semester; diff --git a/src/reducers/common/track.js b/src/reducers/common/track.js deleted file mode 100644 index a3ecf84..0000000 --- a/src/reducers/common/track.js +++ /dev/null @@ -1,18 +0,0 @@ -import { SET_TRACKS } from '../../actions/common/track'; - -const initialState = { - tracks: null, -}; - -export const reducer = (state = initialState, action) => { - switch (action.type) { - case SET_TRACKS: - return Object.assign({}, state, { - tracks: action.tracks, - }); - default: - return state; - } -}; - -export default reducer; diff --git a/src/reducers/common/track.ts b/src/reducers/common/track.ts new file mode 100644 index 0000000..6b4b350 --- /dev/null +++ b/src/reducers/common/track.ts @@ -0,0 +1,20 @@ +import { SET_TRACKS, TrackAction, Tracks } from '../../actions/common/track'; + +interface TrackState { + tracks: Tracks | null; +} + +const initialState: TrackState = { + tracks: null, +}; + +const track = (state = initialState, action: TrackAction): TrackState => { + switch (action.type) { + case SET_TRACKS: + return { ...state, tracks: action.tracks }; + default: + return state; + } +}; + +export default track; diff --git a/src/reducers/common/user.js b/src/reducers/common/user.ts similarity index 53% rename from src/reducers/common/user.js rename to src/reducers/common/user.ts index a65f34c..b36bc94 100644 --- a/src/reducers/common/user.js +++ b/src/reducers/common/user.ts @@ -1,16 +1,22 @@ -import { SET_USER, UPDATE_USER_REVIEW } from '../../actions/common/user'; +import User from '@/shapes/model/session/User'; +import { SET_USER, UPDATE_USER_REVIEW, UserAction } from '../../actions/common/user'; -const initialState = { - user: undefined, +interface UserState { + user: User | null; +} + +const initialState: UserState = { + user: null, }; -export const reducer = (state = initialState, action) => { +const user = (state = initialState, action: UserAction): UserState => { switch (action.type) { case SET_USER: - return Object.assign({}, state, { - user: action.user, - }); + return { ...state, user: action.user }; case UPDATE_USER_REVIEW: { + if (!state.user) { + return state; + } const originalReviews = state.user.reviews; const { review } = action; const foundIndex = originalReviews.findIndex((r) => r.id === review.id); @@ -22,16 +28,11 @@ export const reducer = (state = initialState, action) => { ...originalReviews.slice(foundIndex + 1, originalReviews.length), ] : [...originalReviews.slice(), review]; - return Object.assign({}, state, { - user: { - ...state.user, - reviews: newReviews, - }, - }); + return { ...state, user: { ...state.user, reviews: newReviews } }; } default: return state; } }; -export default reducer; +export default user;