import React from 'react'; import lbry from '../lbry.js'; import lbryio from '../lbryio.js'; import lbryuri from '../lbryuri.js'; import lighthouse from '../lighthouse.js'; import {FileTile, FileTileStream} from '../component/file-tile.js'; import {Link} from '../component/link.js'; import {ToolTip} from '../component/tooltip.js'; import {BusyMessage} from '../component/common.js'; var SearchNoResults = React.createClass({ render: function() { return
No one has checked anything in for {this.props.query} yet.
; } }); var SearchResultList = React.createClass({ render: function() { var rows = [], seenNames = {}; //fix this when the search API returns claim IDs for (let {name, claim, claim_id, channel_name, channel_id, txid, nout} of this.props.results) { const uri = lbryuri.build({ channelName: channel_name, contentName: name, claimId: channel_id || claim_id, }); rows.push( ); } return (
{rows}
); } }); let SearchResults = React.createClass({ propTypes: { query: React.PropTypes.string.isRequired }, _isMounted: false, search: function(term) { lighthouse.search(term).then(this.searchCallback); if (!this.state.searching) { this.setState({ searching: true }) } }, componentWillMount: function () { this._isMounted = true; this.search(this.props.query); }, componentWillReceiveProps: function (nextProps) { if (nextProps.query != this.props.query) { this.search(nextProps.query); } }, componentWillUnmount: function () { this._isMounted = false; }, getInitialState: function () { return { results: [], searching: true }; }, searchCallback: function (results) { if (this._isMounted) //could have canceled while results were pending, in which case nothing to do { this.setState({ results: results, searching: false //multiple searches can be out, we're only done if we receive one we actually care about }); } }, render: function () { return this.state.searching ? : (this.state.results && this.state.results.length ? : ); } }); let SearchPage = React.createClass({ _isMounted: false, propTypes: { query: React.PropTypes.string.isRequired }, isValidUri: function(query) { try { lbryuri.parse(query); return true; } catch (e) { return false; } }, componentWillMount: function() { this._isMounted = true; lighthouse.search(this.props.query).then(this.searchCallback); }, componentWillUnmount: function() { this._isMounted = false; }, getInitialState: function() { return { results: [], searching: true }; }, searchCallback: function(results) { if (this._isMounted) //could have canceled while results were pending, in which case nothing to do { this.setState({ results: results, searching: false //multiple searches can be out, we're only done if we receive one we actually care about }); } }, render: function() { return (
{ this.isValidUri(this.props.query) ?

Exact URL

: '' }

Search Results for {this.props.query}

); } }); export default SearchPage;