Commit c78b805e authored by David Haynes's avatar David Haynes 🙆
Browse files

entry -> CourseSection

parent 5b727f45
export const ADD_ENTRY: string = '[Schedule] ADD_ENTRY'; export const ADD_COURSE_SECTION: string = '[Schedule] ADD_COURSE_SECTION';
export const REMOVE_ENTRY: string = '[Schedule] REMOVE_ENTRY'; export const REMOVE_COURSE_SECTION: string = '[Schedule] REMOVE_COURSE_SECTION';
import { CourseSection } from '../../util/CourseSection'; import { CourseSection } from '../../util/CourseSection';
import { ADD_ENTRY, REMOVE_ENTRY } from './schedule.action-types'; import { ADD_COURSE_SECTION, REMOVE_COURSE_SECTION } from './schedule.action-types';
export interface ScheduleAction { export interface ScheduleAction {
type: string; // What action is to be performed type: string; // What action is to be performed
entry: CourseSection; // The section that is being added/removed courseSection: CourseSection; // The section that is being added/removed
} }
/** /**
* Add a section to the Schedule * Add a section to the Schedule
* @param section The section that is to be added * @param section The section that is to be added
*/ */
export const addEntry = (entry: CourseSection): ScheduleAction => ({ export const addCourseSection = (courseSectionToAdd: CourseSection): ScheduleAction => ({
type: ADD_ENTRY, type: ADD_COURSE_SECTION,
entry: entry, courseSection: courseSectionToAdd,
}); });
/** /**
* Remove a section from the Schedule * Remove a section from the Schedule
* @param section The section that is to be removed * @param section The section that is to be removed
*/ */
export const removeEntry = (entry: CourseSection): ScheduleAction => ({ export const removeCourseSection = (courseSectionToRemove: CourseSection): ScheduleAction => ({
type: REMOVE_ENTRY, type: REMOVE_COURSE_SECTION,
entry: entry, courseSection: courseSectionToRemove,
}); });
...@@ -6,7 +6,7 @@ export interface SearchAction { ...@@ -6,7 +6,7 @@ export interface SearchAction {
searchResults: CourseSection[]; searchResults: CourseSection[];
} }
export const searchCourses = (crn: string) => async (dispatch: any) => { export const searchCourseSections = (crn: string) => async (dispatch: any) => {
const response = await fetch(`http://localhost:3000/api/search?crn=${crn}`); const response = await fetch(`http://localhost:3000/api/search?crn=${crn}`);
const object = await response.json(); const object = await response.json();
......
...@@ -3,7 +3,7 @@ import { CourseSection } from '../util/CourseSection'; ...@@ -3,7 +3,7 @@ import { CourseSection } from '../util/CourseSection';
interface Props { interface Props {
courses: CourseSection[]; courses: CourseSection[];
selectCourseCallback?: (entry: CourseSection) => void; selectCourseCallback?: (courseSection: CourseSection) => void;
} }
export default class ScheduleList extends React.Component<Props, any> { export default class ScheduleList extends React.Component<Props, any> {
......
...@@ -4,7 +4,7 @@ import ScheduleList from './ScheduleList'; ...@@ -4,7 +4,7 @@ import ScheduleList from './ScheduleList';
interface SearchRootProps { interface SearchRootProps {
schedule: CourseSection[]; schedule: CourseSection[];
removeEntry: (CourseEntry: CourseSection) => any; removeCourseSection: (courseSection: CourseSection) => any;
} }
// const generateSchedule = (schedule: CourseEntry[]): void => { // const generateSchedule = (schedule: CourseEntry[]): void => {
...@@ -15,9 +15,9 @@ interface SearchRootProps { ...@@ -15,9 +15,9 @@ interface SearchRootProps {
// .then(icalText => downloadCalendar(icalText)); // .then(icalText => downloadCalendar(icalText));
// }; // };
const ScheduleRoot = ({ schedule, removeEntry }: SearchRootProps) => ( const ScheduleRoot = ({ schedule, removeCourseSection }: SearchRootProps) => (
<div> <div>
<ScheduleList courses={schedule} selectCourseCallback={removeEntry} /> <ScheduleList courses={schedule} selectCourseCallback={removeCourseSection} />
{/* <button onClick={generateSchedule}>Generate Schedule</button> */} {/* <button onClick={generateSchedule}>Generate Schedule</button> */}
</div> </div>
); );
......
...@@ -5,14 +5,14 @@ import { CourseSection } from '../util/CourseSection'; ...@@ -5,14 +5,14 @@ import { CourseSection } from '../util/CourseSection';
interface SearchRootProps { interface SearchRootProps {
searchResults: CourseSection[]; searchResults: CourseSection[];
searchCourses: (crn: string) => void; searchCourseSections: (crn: string) => void;
addEntry: (entry: CourseSection) => void; addCourseSection: (courseSectionToAdd: CourseSection) => void;
} }
const SearchRoot = ({ searchResults, searchCourses, addEntry }: SearchRootProps) => ( const SearchRoot = ({ searchResults, searchCourseSections, addCourseSection }: SearchRootProps) => (
<div> <div>
<SearchBar onSearch={searchCourses} /> <SearchBar onSearch={searchCourseSections} />
<SectionList courses={searchResults} selectCourseCallback={addEntry} /> <SectionList courses={searchResults} selectCourseCallback={addCourseSection} />
</div> </div>
); );
......
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { addEntry, removeEntry } from '../actions/schedule/schedule.actions'; import { removeCourseSection } from '../actions/schedule/schedule.actions';
import ScheduleRoot from '../components/ScheduleRoot'; import ScheduleRoot from '../components/ScheduleRoot';
import { State } from '../reducers'; import { State } from '../reducers';
...@@ -9,5 +9,5 @@ const mapStateToProps = (state: State) => ({ ...@@ -9,5 +9,5 @@ const mapStateToProps = (state: State) => ({
export default connect( export default connect(
mapStateToProps, mapStateToProps,
{ addEntry, removeEntry } { removeCourseSection }
)(ScheduleRoot); )(ScheduleRoot);
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { addEntry } from '../actions/schedule/schedule.actions'; import { addCourseSection } from '../actions/schedule/schedule.actions';
import { searchCourses } from '../actions/search/search.actions'; import { searchCourseSections } from '../actions/search/search.actions';
import SearchRoot from '../components/SearchRoot'; import SearchRoot from '../components/SearchRoot';
import { State } from '../reducers'; import { State } from '../reducers';
...@@ -10,5 +10,5 @@ const mapStateToProps = (state: State) => ({ ...@@ -10,5 +10,5 @@ const mapStateToProps = (state: State) => ({
export default connect( export default connect(
mapStateToProps, mapStateToProps,
{ searchCourses, addEntry } { searchCourseSections, addCourseSection }
)(SearchRoot); )(SearchRoot);
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* Perform operations on the current state of the "Schedule" list in the store * Perform operations on the current state of the "Schedule" list in the store
* and return a new definition of the state. * and return a new definition of the state.
*/ */
import { ADD_ENTRY, REMOVE_ENTRY } from '../actions/schedule/schedule.action-types'; import { ADD_COURSE_SECTION, REMOVE_COURSE_SECTION } from '../actions/schedule/schedule.action-types';
import { ScheduleAction } from '../actions/schedule/schedule.actions'; import { ScheduleAction } from '../actions/schedule/schedule.actions';
import { CourseSection } from '../util/CourseSection'; import { CourseSection } from '../util/CourseSection';
...@@ -12,10 +12,12 @@ export type ScheduleState = CourseSection[]; ...@@ -12,10 +12,12 @@ export type ScheduleState = CourseSection[];
export const schedule = (state: ScheduleState = [], action: ScheduleAction) => { export const schedule = (state: ScheduleState = [], action: ScheduleAction) => {
switch (action.type) { switch (action.type) {
case ADD_ENTRY: case ADD_COURSE_SECTION:
return state.findIndex(s => s.crn === action.entry.crn) === -1 ? [...state, action.entry] : state; return state.findIndex(s => s.crn === action.courseSection.crn) === -1
case REMOVE_ENTRY: ? [...state, action.courseSection]
return state.filter(s => s.crn !== action.entry.crn); : state;
case REMOVE_COURSE_SECTION:
return state.filter(s => s.crn !== action.courseSection.crn);
default: default:
return state; return state;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment