SearchRoot.tsx 1.31 KB
Newer Older
David Haynes's avatar
David Haynes committed
1
import * as React from 'react';
David Haynes's avatar
David Haynes committed
2
import SearchBar from '../components/SearchBar';
3
import CourseSection from '../util/CourseSection';
David Haynes's avatar
David Haynes committed
4
import CourseSectionList from './CourseSectionList';
5
6
import { Row, Col, Alert } from 'reactstrap';
import { SearchState } from '../reducers/search.reducer';
David Haynes's avatar
David Haynes committed
7
8

interface SearchRootProps {
9
    search: SearchState;
David Haynes's avatar
David Haynes committed
10
11
    searchCourseSections: (crn: string) => void;
    addCourseSection: (courseSectionToAdd: CourseSection) => void;
David Haynes's avatar
David Haynes committed
12
13
}

14
15
16
17
/**
 * Renders the SearchBar and a list of CourseSections returned from the Search.
 * Also renders an error if there is one.
 */
18
const SearchRoot = ({ search, searchCourseSections, addCourseSection }: SearchRootProps) => (
David Haynes's avatar
David Haynes committed
19
    <div>
David Haynes's avatar
David Haynes committed
20
        <SearchBar onSearch={searchCourseSections} />
21
22
23
24
25
26
27
28
29
        {search.error !== '' ? (
            <Error />
        ) : (
            <CourseSectionList
                courseSectionActionButtonText="Add to schedule"
                courseSections={search.courseSections}
                courseSectionAction={addCourseSection}
            />
        )}
David Haynes's avatar
David Haynes committed
30
31
32
    </div>
);

33
34
35
/**
 * Renders a basic error message.
 */
36
37
38
39
40
41
42
43
const Error = () => (
    <Row className="justify-content-center">
        <Col md="8">
            <Alert color="danger">Could not find course section with the given CRN.</Alert>
        </Col>
    </Row>
);

David Haynes's avatar
David Haynes committed
44
export default SearchRoot;