lbry-desktop/ui/js/component/fileListSearch/view.jsx

77 lines
1.8 KiB
React
Raw Normal View History

2017-06-06 23:19:12 +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";
2017-06-06 06:21:55 +02:00
const SearchNoResults = props => {
2017-06-06 23:19:12 +02:00
const { navigate, query } = props;
2017-06-06 23:19:12 +02:00
return (
<section>
<span className="empty">
{(__("No one has checked anything in for %s yet."), query)} {" "}
<Link label={__("Be the first")} onClick={() => navigate("/publish")} />
</span>
</section>
);
2017-06-06 06:21:55 +02:00
};
2017-06-06 06:21:55 +02:00
const FileListSearchResults = props => {
2017-06-06 23:19:12 +02:00
const { results } = props;
const rows = [],
seenNames = {}; //fix this when the search API returns claim IDs
2017-06-06 23:19:12 +02:00
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,
});
2017-06-06 23:19:12 +02:00
rows.push(<FileTile key={uri} uri={uri} />);
}
2017-06-06 23:19:12 +02:00
return <div>{rows}</div>;
2017-06-06 06:21:55 +02:00
};
2017-06-06 06:21:55 +02:00
class FileListSearch extends React.Component {
componentWillMount() {
2017-06-06 23:19:12 +02:00
this.props.search(this.props.query);
}
render() {
2017-06-06 23:19:12 +02:00
const { isSearching, results } = this.props;
return (
<div>
2017-06-06 23:19:12 +02:00
{isSearching &&
!results &&
<BusyMessage message={__("Looking up the Dewey Decimals")} />}
2017-06-06 23:19:12 +02:00
{isSearching &&
results &&
<BusyMessage message={__("Refreshing the Dewey Decimals")} />}
2017-06-06 23:19:12 +02:00
{results && !!results.length
? <FileListSearchResults {...this.props} />
: <SearchNoResults {...this.props} />}
</div>
2017-06-06 23:19:12 +02:00
);
}
}
2017-06-06 06:21:55 +02:00
export default FileListSearch;