lbry-desktop/ui/js/page/search/view.jsx

90 lines
2.3 KiB
React
Raw Normal View History

2017-05-05 10:01:16 +02:00
import React from 'react';
import lbry from 'lbry';
import lbryio from 'lbryio';
import lbryuri from 'lbryuri';
import lighthouse from 'lighthouse';
import FileTile from 'component/fileTile'
import Link from 'component/link'
import {ToolTip} from 'component/tooltip.js';
import {BusyMessage} from 'component/common.js';
const SearchNoResults = (props) => {
const {
navigate,
query,
} = props
return <section>
<span className="empty">
2017-05-09 00:22:27 +02:00
No one has checked anything in for {query} yet. { ' ' }
2017-05-06 18:31:47 +02:00
<Link label="Be the first" onClick={() => navigate('/publish')} />
2017-05-05 10:01:16 +02:00
</span>
</section>;
}
const SearchResultList = (props) => {
const {
results,
} = props
const rows = [],
seenNames = {}; //fix this when the search API returns claim IDs
for (let {name, claim, claim_id, channel_name, channel_id, txid, nout} of results) {
const uri = lbryuri.build({
channelName: channel_name,
contentName: name,
claimId: channel_id || claim_id,
});
rows.push(
2017-05-09 00:22:27 +02:00
<FileTile key={uri} uri={uri} />
2017-05-05 10:01:16 +02:00
);
}
return (
<div>{rows}</div>
);
}
const SearchResults = (props) => {
const {
2017-05-09 00:22:27 +02:00
isSearching,
results
2017-05-05 10:01:16 +02:00
} = props
return (
2017-05-09 00:22:27 +02:00
isSearching ?
2017-05-05 10:01:16 +02:00
<BusyMessage message="Looking up the Dewey Decimals" /> :
(results && results.length) ?
<SearchResultList {...props} /> :
<SearchNoResults {...props} />
)
}
const SearchPage = (props) => {
const isValidUri = (query) => true
const {
query,
} = props
return (
<main className="main--single-column">
{ isValidUri(query) ?
<section className="section-spaced">
<h3 className="card-row__header">
Exact URL
<ToolTip label="?" body="This is the resolution of a LBRY URL and not controlled by LBRY Inc." className="tooltip--header" />
</h3>
2017-05-10 03:33:13 +02:00
<FileTile uri={lbryuri.normalize(query)} showEmpty={FileTile.SHOW_EMPTY_PUBLISH} />
2017-05-05 10:01:16 +02:00
</section> : '' }
<section className="section-spaced">
<h3 className="card-row__header">
Search Results for {query}
<ToolTip label="?" body="These search results are provided by LBRY, Inc." className="tooltip--header" />
</h3>
<SearchResults {...props} />
</section>
</main>
)
}
export default SearchPage;