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 REMOVE_ENTRY: string = '[Schedule] REMOVE_ENTRY';
export const ADD_COURSE_SECTION: string = '[Schedule] ADD_COURSE_SECTION';
export const REMOVE_COURSE_SECTION: string = '[Schedule] REMOVE_COURSE_SECTION';
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 {
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
* @param section The section that is to be added
*/
export const addEntry = (entry: CourseSection): ScheduleAction => ({
type: ADD_ENTRY,
entry: entry,
export const addCourseSection = (courseSectionToAdd: CourseSection): ScheduleAction => ({
type: ADD_COURSE_SECTION,
courseSection: courseSectionToAdd,
});
/**
* Remove a section from the Schedule
* @param section The section that is to be removed
*/
export const removeEntry = (entry: CourseSection): ScheduleAction => ({
type: REMOVE_ENTRY,
entry: entry,
export const removeCourseSection = (courseSectionToRemove: CourseSection): ScheduleAction => ({
type: REMOVE_COURSE_SECTION,
courseSection: courseSectionToRemove,
});
......@@ -6,7 +6,7 @@ export interface SearchAction {
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 object = await response.json();
......
......@@ -3,7 +3,7 @@ import { CourseSection } from '../util/CourseSection';
interface Props {
courses: CourseSection[];
selectCourseCallback?: (entry: CourseSection) => void;
selectCourseCallback?: (courseSection: CourseSection) => void;
}
export default class ScheduleList extends React.Component<Props, any> {
......
......@@ -4,7 +4,7 @@ import ScheduleList from './ScheduleList';
interface SearchRootProps {
schedule: CourseSection[];
removeEntry: (CourseEntry: CourseSection) => any;
removeCourseSection: (courseSection: CourseSection) => any;
}
// const generateSchedule = (schedule: CourseEntry[]): void => {
......@@ -15,9 +15,9 @@ interface SearchRootProps {
// .then(icalText => downloadCalendar(icalText));
// };
const ScheduleRoot = ({ schedule, removeEntry }: SearchRootProps) => (
const ScheduleRoot = ({ schedule, removeCourseSection }: SearchRootProps) => (
<div>
<ScheduleList courses={schedule} selectCourseCallback={removeEntry} />
<ScheduleList courses={schedule} selectCourseCallback={removeCourseSection} />
{/* <button onClick={generateSchedule}>Generate Schedule</button> */}
</div>
);
......
......@@ -5,14 +5,14 @@ import { CourseSection } from '../util/CourseSection';
interface SearchRootProps {
searchResults: CourseSection[];
searchCourses: (crn: string) => void;
addEntry: (entry: CourseSection) => void;
searchCourseSections: (crn: string) => void;
addCourseSection: (courseSectionToAdd: CourseSection) => void;
}
const SearchRoot = ({ searchResults, searchCourses, addEntry }: SearchRootProps) => (
const SearchRoot = ({ searchResults, searchCourseSections, addCourseSection }: SearchRootProps) => (
<div>
<SearchBar onSearch={searchCourses} />
<SectionList courses={searchResults} selectCourseCallback={addEntry} />
<SearchBar onSearch={searchCourseSections} />
<SectionList courses={searchResults} selectCourseCallback={addCourseSection} />
</div>
);
......
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 { State } from '../reducers';
......@@ -9,5 +9,5 @@ const mapStateToProps = (state: State) => ({
export default connect(
mapStateToProps,
{ addEntry, removeEntry }
{ removeCourseSection }
)(ScheduleRoot);
import { connect } from 'react-redux';
import { addEntry } from '../actions/schedule/schedule.actions';
import { searchCourses } from '../actions/search/search.actions';
import { addCourseSection } from '../actions/schedule/schedule.actions';
import { searchCourseSections } from '../actions/search/search.actions';
import SearchRoot from '../components/SearchRoot';
import { State } from '../reducers';
......@@ -10,5 +10,5 @@ const mapStateToProps = (state: State) => ({
export default connect(
mapStateToProps,
{ searchCourses, addEntry }
{ searchCourseSections, addCourseSection }
)(SearchRoot);
......@@ -4,7 +4,7 @@
* Perform operations on the current state of the "Schedule" list in the store
* 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 { CourseSection } from '../util/CourseSection';
......@@ -12,10 +12,12 @@ export type ScheduleState = CourseSection[];
export const schedule = (state: ScheduleState = [], action: ScheduleAction) => {
switch (action.type) {
case ADD_ENTRY:
return state.findIndex(s => s.crn === action.entry.crn) === -1 ? [...state, action.entry] : state;
case REMOVE_ENTRY:
return state.filter(s => s.crn !== action.entry.crn);
case ADD_COURSE_SECTION:
return state.findIndex(s => s.crn === action.courseSection.crn) === -1
? [...state, action.courseSection]
: state;
case REMOVE_COURSE_SECTION:
return state.filter(s => s.crn !== action.courseSection.crn);
default:
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