Search.tsx 807 Bytes
Newer Older
Zac Wood's avatar
Zac Wood committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
import * as React from 'react';
import Section, { fetchSectionsWithCRN } from '../section';
import SearchBar from './SearchBar';
import SectionList from './SectionList';

interface Props {
    addSearchResultCallback?: (section: Section) => void;
}

interface State {
    sections: Section[];
}

export default class Search extends React.Component<Props, State> {
    constructor(props: Props) {
        super(props);

        this.setState({ sections: [] });
    }

    searchForSections(crn: string) {
        fetchSectionsWithCRN(crn).then(sections => this.setState({ sections }));
    }

    render() {
        return (
            <div>
                <SearchBar onSearch={this.searchForSections} />
                <SectionList sections={this.state.sections} />
            </div>
        );
    }
}