Search working

This commit is contained in:
6ea86b96 2017-04-25 12:47:21 +07:00 committed by Jeremy Kauffman
parent 894ba3d38f
commit 3a050b3b71
9 changed files with 83 additions and 105 deletions

View file

@ -1,21 +1,40 @@
import * as types from 'constants/action_types' import * as types from 'constants/action_types'
import lbry from 'lbry' import lbry from 'lbry'
import lbryio from 'lbryio' import lbryio from 'lbryio'
import lbryuri from 'lbryuri'
import lighthouse from 'lighthouse' import lighthouse from 'lighthouse'
import { import {
selectSearchQuery, selectSearchQuery,
} from 'selectors/search' } from 'selectors/search'
import {
doResolveUri,
} from 'actions/content'
export function doSearchContent(query) { export function doSearchContent(query) {
return function(dispatch, getState) { return function(dispatch, getState) {
const state = getState() const state = getState()
if (!query) {
return dispatch({
type: types.SEARCH_CANCELLED,
})
}
dispatch({ dispatch({
type: types.SEARCH_STARTED, type: types.SEARCH_STARTED,
data: { query } data: { query }
}) })
lighthouse.search(query).then(results => { lighthouse.search(query).then(results => {
results.forEach(result => {
const uri = lbryuri.build({
channelName: result.channel_name,
contentName: result.name,
claimId: result.channel_id || result.claim_id,
})
doResolveUri(dispatch, uri.split('://')[1])
})
dispatch({ dispatch({
type: types.SEARCH_COMPLETED, type: types.SEARCH_COMPLETED,
data: { data: {

View file

@ -2,12 +2,16 @@ import React from 'react'
import { import {
connect connect
} from 'react-redux' } from 'react-redux'
import {
doNavigate,
} from 'actions/app'
import FileTileStream from './view' import FileTileStream from './view'
const select = (state) => ({ const select = (state) => ({
}) })
const perform = (dispatch) => ({ const perform = (dispatch) => ({
navigate: (path) => dispatch(doNavigate(path))
}) })
export default connect(select, perform)(FileTileStream) export default connect(select, perform)(FileTileStream)

View file

@ -79,11 +79,12 @@ const FileTileStream = React.createClass({
const isConfirmed = !!metadata; const isConfirmed = !!metadata;
const title = isConfirmed ? metadata.title : uri; const title = isConfirmed ? metadata.title : uri;
const obscureNsfw = this.props.obscureNsfw && isConfirmed && metadata.nsfw; const obscureNsfw = this.props.obscureNsfw && isConfirmed && metadata.nsfw;
const { navigate } = this.props
return ( return (
<section className={ 'file-tile card ' + (obscureNsfw ? 'card--obscured ' : '') } onMouseEnter={this.handleMouseOver} onMouseLeave={this.handleMouseOut}> <section className={ 'file-tile card ' + (obscureNsfw ? 'card--obscured ' : '') } onMouseEnter={this.handleMouseOver} onMouseLeave={this.handleMouseOut}>
<div className={"row-fluid card__inner file-tile__row"}> <div className={"row-fluid card__inner file-tile__row"}>
<div className="span3 file-tile__thumbnail-container"> <div className="span3 file-tile__thumbnail-container">
<a href={'?show=' + uri}><Thumbnail className="file-tile__thumbnail" {... metadata && metadata.thumbnail ? {src: metadata.thumbnail} : {}} alt={'Photo for ' + this.props.uri} /></a> <a href="#" onClick={() => navigate(`show=${uri}`)}><Thumbnail className="file-tile__thumbnail" {... metadata && metadata.thumbnail ? {src: metadata.thumbnail} : {}} alt={'Photo for ' + this.props.uri} /></a>
</div> </div>
<div className="span9"> <div className="span9">
<div className="card__title-primary"> <div className="card__title-primary">

View file

@ -51,3 +51,4 @@ export const FETCH_COST_INFO_COMPLETED = 'FETCH_COST_INFO_COMPLETED'
// Search // Search
export const SEARCH_STARTED = 'SEARCH_STARTED' export const SEARCH_STARTED = 'SEARCH_STARTED'
export const SEARCH_COMPLETED = 'SEARCH_COMPLETED' export const SEARCH_COMPLETED = 'SEARCH_COMPLETED'
export const SEARCH_CANCELLED = 'SEARCH_CANCELLED'

View file

@ -3,12 +3,14 @@ import {
connect connect
} from 'react-redux' } from 'react-redux'
import { import {
selectDownloadedContent, selectDownloadedContentFileInfos,
selectFetchingDownloadedContent,
} from 'selectors/content' } from 'selectors/content'
import FileListDownloaded from './view' import FileListDownloaded from './view'
const select = (state) => ({ const select = (state) => ({
downloadedContent: selectDownloadedContent(state), downloadedContent: selectDownloadedContentFileInfos(state),
fetching: selectFetchingDownloadedContent(state),
}) })
const perform = (dispatch) => ({ const perform = (dispatch) => ({

View file

@ -9,11 +9,33 @@ import lbryio from 'lbryio.js';
import {BusyMessage, Thumbnail} from 'component/common.js'; import {BusyMessage, Thumbnail} from 'component/common.js';
import FileList from 'component/fileList' import FileList from 'component/fileList'
const FileListDownloaded = (props) => { class FileListDownloaded extends React.Component {
// <FileListNav viewingPage="published" /> render() {
const {
downloadedContent,
fetching,
} = this.props
if (fetching) {
return ( return (
<div>item</div> <main className="page">
) <BusyMessage message="Loading" />
</main>
);
} else if (!downloadedContent.length) {
return (
<main className="page">
<span>You haven't downloaded anything from LBRY yet. Go <Link href="?discover" label="search for your first download" />!</span>
</main>
);
} else {
return (
<main className="page">
<FileList fileInfos={downloadedContent} hidePrices={true} />
</main>
);
}
}
} }
// const FileListDownloaded = React.createClass({ // const FileListDownloaded = React.createClass({
// _isMounted: false, // _isMounted: false,

View file

@ -17,19 +17,19 @@ const FormatItem = (props) => {
const { const {
contentType, contentType,
metadata, metadata,
cost, metadata: {
uri,
outpoint,
costIncludesData,
} = props
const {
thumbnail, thumbnail,
author, author,
title, title,
description, description,
language, language,
license license,
} = metadata; },
cost,
uri,
outpoint,
costIncludesData,
} = props
const mediaType = lbry.getMediaType(contentType); const mediaType = lbry.getMediaType(contentType);
return ( return (
@ -289,89 +289,3 @@ let ShowPage = React.createClass({
return <main className="main--single-column">{innerContent}</main>; return <main className="main--single-column">{innerContent}</main>;
} }
}); });
export default ShowPage;
//
// const ShowPage = (props) => {
// const {
// claim,
// uri,
// isDownloaded,
// fileInfo,
// costInfo,
// } = props
// const {
// txid,
// nout,
// has_signature,
// signature_is_valid,
// value,
// } = claim
// const {
// stream,
// } = value
// const {
// metadata,
// source,
// } = stream
// const {
// title,
// } = metadata
// const {
// contentType,
// } = source
// const {
// cost,
// includesData,
// } = costInfo
// const costIncludesData = includesData
//
// const outpoint = txid + ':' + nout;
// const uriLookupComplete = !!claim
// const hasSignature = has_signature
// const signatureIsValid = signature_is_valid
//
// return (
// <main className="main--single-column">
// <section className="show-page-media">
// { contentType && contentType.startsWith('video/') ?
// <Video className="video-embedded" uri={uri} metadata={metadata} outpoint={outpoint} /> :
// (metadata ? <Thumbnail src={metadata.thumbnail} /> : <Thumbnail />) }
// </section>
// <section className="card">
// <div className="card__inner">
// <div className="card__title-identity">
// {isDownloaded === false
// ? <span style={{float: "right"}}><FilePrice uri={uri} metadata={metadata} /></span>
// : null}
// <h1>{title}</h1>
// { uriLookupComplete ?
// <div>
// <div className="card__subtitle">
// <UriIndicator uri={uri} hasSignature={hasSignature} signatureIsValid={signatureIsValid} />
// </div>
// <div className="card__actions">
// <FileActions uri={uri} outpoint={outpoint} metadata={metadata} contentType={contentType} />
// </div>
// </div> : '' }
// </div>
// { uriLookupComplete ?
// <div>
// <div className="card__content card__subtext card__subtext card__subtext--allow-newlines">
// {metadata.description}
// </div>
// </div>
// : <div className="card__content"><BusyMessage message="Loading magic decentralized data..." /></div> }
// </div>
// { metadata ?
// <div className="card__content">
// <FormatItem metadata={metadata} contentType={contentType} cost={cost} uri={uri} outpoint={outpoint} costIncludesData={costIncludesData} />
// </div> : '' }
// <div className="card__content">
// <Link href="https://lbry.io/dmca" label="report" className="button-text-help" />
// </div>
// </section>
// </main>
// )
// }

View file

@ -19,9 +19,12 @@ reducers[types.SEARCH_COMPLETED] = function(state, action) {
const { const {
query, query,
} = action.data } = action.data
const newResults = Object.assign({}, state.results) const oldResults = Object.assign({}, state.results)
const newByQuery = Object.assign({}, newResults.byQuery) const newByQuery = Object.assign({}, oldResults.byQuery)
newByQuery[query] = action.data.results newByQuery[query] = action.data.results
const newResults = Object.assign({}, oldResults, {
byQuery: newByQuery
})
return Object.assign({}, state, { return Object.assign({}, state, {
searching: false, searching: false,
@ -29,6 +32,13 @@ reducers[types.SEARCH_COMPLETED] = function(state, action) {
}) })
} }
reducers[types.SEARCH_CANCELLED] = function(state, action) {
return Object.assign({}, state, {
searching: false,
query: undefined,
})
}
export default function reducer(state = defaultState, action) { export default function reducer(state = defaultState, action) {
const handler = reducers[action.type]; const handler = reducers[action.type];
if (handler) return handler(state, action); if (handler) return handler(state, action);

View file

@ -155,6 +155,11 @@ export const selectDownloadedContent = createSelector(
(state) => state.downloadedContent || {} (state) => state.downloadedContent || {}
) )
export const selectDownloadedContentFileInfos = createSelector(
selectDownloadedContent,
(downloadedContent) => downloadedContent.fileInfos || []
)
export const shouldFetchDownloadedContent = createSelector( export const shouldFetchDownloadedContent = createSelector(
selectDaemonReady, selectDaemonReady,
selectCurrentPage, selectCurrentPage,