Dataset/JS/ReactBookmarks/bookmarks.js (107 lines of code) (raw):

import _ from 'lodash'; import React, { PropTypes } from 'react'; import { bindActionCreators } from 'redux'; import { connect } from 'react-redux'; import DocumentTitle from 'react-document-title'; import { Button, Input } from 'react-bootstrap'; import * as actions from '../actions'; import { podcastsSelector } from '../selectors'; import PodcastList from '../components/podcasts'; import PageHeader from '../components/header'; import Icon from '../components/icon'; import { getTitle } from './utils'; export class Bookmarks extends React.Component { constructor(props) { super(props); const { dispatch } = this.props; this.actions = bindActionCreators(actions.bookmarks, dispatch); this.handleSearch = this.handleSearch.bind(this); this.handleClearSearch = this.handleClearSearch.bind(this); this.handleSelectSearch = this.handleSelectSearch.bind(this); this.handleSelectPage = this.handleSelectPage.bind(this); } handleSearch(event) { event.preventDefault(); const query = _.trim(this.refs.query.getValue()); if (query) { this.actions.searchBookmarks(query); } else { this.actions.getBookmarks(); } } handleClearSearch(event) { event.preventDefault(); this.refs.query.getInputDOMNode().value = ''; this.actions.getBookmarks(); } handleSelectSearch(event) { event.preventDefault(); this.refs.query.getInputDOMNode().select(); } handleSelectPage(page) { window.scrollTo(0, 0); this.actions.getBookmarks(page); } render() { const { query } = this.props; return ( <DocumentTitle title={getTitle('My bookmarks')}> <div> <PageHeader header="My bookmarks" /> <form onSubmit={this.handleSearch}> <Input type="search" ref="query" onClick={this.handleSelectSearch} placeholder="Find a podcast in your bookmarks" /> <Input> <Button bsStyle="primary" type="submit" defaultValue={query} className="form-control" ><Icon icon="search" /> Search </Button> </Input> {query ? <Input> <Button bsStyle="default" onClick={this.handleClearSearch} className="form-control" ><Icon icon="refresh" /> Show all bookmarks </Button> </Input> : ''} </form> <PodcastList actions={actions} searchQuery={query} showChannel isLoggedIn ifEmpty="No bookmarks found" onSelectPage={this.handleSelectPage} {...this.props} /> </div> </DocumentTitle> ); } } Bookmarks.propTypes = { podcasts: PropTypes.array.isRequired, page: PropTypes.object.isRequired, currentlyPlaying: PropTypes.number, dispatch: PropTypes.func.isRequired, query: PropTypes.string, }; const mapStateToProps = state => { const { query } = state.bookmarks; const { page, isLoading } = state.podcasts; return { podcasts: podcastsSelector(state), page, isLoading, query, }; }; export default connect(mapStateToProps)(Bookmarks);