import React, {PropTypes} from "react";
import Moment from "moment";
import HistoryItem from "./HistoryItem.jsx";
import HistoryHead from "./HistoryHead.jsx";

class History extends React.Component {
    constructor(props) {
        super(props);
    }

    getItems() {
        if (parseInt(this.props.paginate.limit) === 0) {
            return this.props.items;
        }
        const cursor = this.props.paginate.page * this.props.paginate.limit;
        return this.props.items.slice(cursor, parseInt(cursor)+parseInt(this.props.paginate.limit));
    }

    render() {
        const items = this.getItems();
        const selectedDay = Moment(this.props.date);

        let formattedTitle = "";
        if (this.props.query !== "") {
            formattedTitle += "Searching: \"" + this.props.query + "\" on ";
        }
        formattedTitle += selectedDay.format("dddd, MMM Do YY'");

        return (
            <div className="history list-group">
                <HistoryHead title={formattedTitle} />
                {items.map(obj => {
                    return <HistoryItem
                            key={obj.id}
                            info={obj}
                            stale={obj.lastVisitTime > selectedDay.endOf("day").valueOf() ? true : false} />
                })}
            </div>
        );
    }
}

export default History;
import React, {PropTypes} from "react";
import Moment from "moment";
import HistoryItem from "./HistoryItem.jsx";
import HistoryHead from "./HistoryHead.jsx";

class History extends React.Component {
    constructor(props) {
        super(props);
    }

    getItems() {
        if (parseInt(this.props.paginate.limit) === 0) {
            return this.props.items;
        }
        const cursor = this.props.paginate.page * this.props.paginate.limit;
        return this.props.items.slice(cursor, parseInt(cursor)+parseInt(this.props.paginate.limit));
    }

    render() {
        const items = this.getItems();
        const selectedDay = Moment(this.props.date);

        let formattedTitle = "";
        if (this.props.query !== "") {
            formattedTitle += "Searching: \"" + this.props.query + "\"";
            if (this.props.date) {
                formattedTitle += " on ";
            }
        }
        if (this.props.date) {
            formattedTitle += selectedDay.format("dddd, MMM Do YY'");
        }

        return (
            <div className="history list-group">
                <HistoryHead title={formattedTitle || "All visits"} />
                {items.map(obj => {
                    return <HistoryItem
                            key={obj.id}
                            info={obj}
                            stale={obj.lastVisitTime > selectedDay.endOf("day").valueOf() ? true : false} />
                })}
            </div>
        );
    }
}

export default History;
Change results header title depending on search type
Change results header title depending on search type

There are currently 3 search types:
- With a query
- With a query, and date
- With neither

This commit will modify the title formatting "handler" to account for the above scenarios.
A title will be set accordingly. The changes in this commit should be optimised in the near future (WIP).
