search.reducer.ts 658 Bytes
Newer Older
1
2
3
4
5
6
/**
 * reducers/search.reducer.ts
 *
 * Perform operations on the current state of the "search.searchedSections"
 * list in the store and return a new definition of the state.
 */
David Haynes's avatar
David Haynes committed
7
import { SET_SEARCH_RESULTS } from '../actions/search/search.action-types';
8
import { SearchAction } from '../actions/search/search.actions';
9
import CourseSection from '../util/CourseSection';
Andrew Hrdy's avatar
Andrew Hrdy committed
10

David Haynes's avatar
David Haynes committed
11
export type SearchState = CourseSection[];
Andrew Hrdy's avatar
Andrew Hrdy committed
12

David Haynes's avatar
David Haynes committed
13
export const search = (state: SearchState = [], action: SearchAction): SearchState => {
Andrew Hrdy's avatar
Andrew Hrdy committed
14
    switch (action.type) {
David Haynes's avatar
David Haynes committed
15
16
        case SET_SEARCH_RESULTS:
            return action.searchResults;
Andrew Hrdy's avatar
Andrew Hrdy committed
17
18
19
        default:
            return state;
    }
David Haynes's avatar
David Haynes committed
20
};