Home Reference Source

application/components/common/content-search/content-results.js

import React from 'react';
import {connect} from 'react-redux';

import LoadingIndicator from './../loading-indicator';
import ContentSearchResult from './content-result';

import BaseView from './../../base-view';
import {Row, Col} from './../../flexbox';

/**
 * Render search results for the content search modal
 */
class ContentSearchResults extends BaseView {
    constructor(props) {
        super(props);
        this.displayName = 'ContentSearchResults';

        this.state = {};
    }

    componentDidMount() {
        if (window && window.jQuery) {
            // const parent = jQuery('.RichEditor-content');

            // this.setState({'height': parent.height() - 150});
        }
    }

    render() {
        if (this.props.contentSearch.isFetching) {
            return <LoadingIndicator size="small" />
        }

        return (
            <Row middle='xs'>
                {
                    this.props.view == 'list'
                    ? (
                        // This is the 'table' header for the list view
                        <Col offsetXs={8} xs={4} center='xs'>
                            Created
                        </Col>
                    )
                    : ''
                }
                {this.props.contentSearch.items.map((item, i) => {
                    return (
                        <ContentSearchResult onSelectContent={this.props.onSelectContent} key={i} content={item} view={this.props.view} />
                    );
                })}
            </Row>
        );
    }
}

export default connect((state) => {
    return {
        contentSearch: state.contentSearch
    };
})(ContentSearchResults);