Skip to content

Commit

Permalink
Merge branch 'migration@reducers/common' into migration
Browse files Browse the repository at this point in the history
  • Loading branch information
sboh1214 committed May 16, 2024
2 parents d0db360 + 80a6d31 commit dd16e38
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 70 deletions.
4 changes: 2 additions & 2 deletions src/actions/common/track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ const CombinedReducer = combineReducers({
media: media,
});

export type CommonState = ReturnType<typeof CombinedReducer>;
export default CombinedReducer;
18 changes: 0 additions & 18 deletions src/reducers/common/media.js

This file was deleted.

20 changes: 20 additions & 0 deletions src/reducers/common/media.ts
Original file line number Diff line number Diff line change
@@ -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;
18 changes: 0 additions & 18 deletions src/reducers/common/semester.js

This file was deleted.

21 changes: 21 additions & 0 deletions src/reducers/common/semester.ts
Original file line number Diff line number Diff line change
@@ -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;
18 changes: 0 additions & 18 deletions src/reducers/common/track.js

This file was deleted.

20 changes: 20 additions & 0 deletions src/reducers/common/track.ts
Original file line number Diff line number Diff line change
@@ -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;
29 changes: 15 additions & 14 deletions src/reducers/common/user.js → src/reducers/common/user.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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;

0 comments on commit dd16e38

Please sign in to comment.