more refactors, fixes

This commit is contained in:
Jeremy Kauffman 2017-05-15 12:34:33 -04:00
parent 6783bcdfeb
commit aa935c1c07
19 changed files with 113 additions and 64 deletions

View file

@ -10,6 +10,9 @@ import {
selectFileInfoForUri, selectFileInfoForUri,
selectDownloadingByUri, selectDownloadingByUri,
} from 'selectors/file_info' } from 'selectors/file_info'
import {
selectResolvingUris
} from 'selectors/content'
import { import {
selectCostInfoForUri, selectCostInfoForUri,
} from 'selectors/cost_info' } from 'selectors/cost_info'
@ -22,26 +25,38 @@ import {
export function doResolveUri(uri) { export function doResolveUri(uri) {
return function(dispatch, getState) { return function(dispatch, getState) {
dispatch({
type: types.RESOLVE_URI_STARTED,
data: { uri }
})
lbry.resolve({ uri }).then((resolutionInfo) => { const state = getState()
const { const alreadyResolving = selectResolvingUris(state).indexOf(uri) !== -1
claim,
certificate,
} = resolutionInfo ? resolutionInfo : { claim : null, certificate: null }
if (!alreadyResolving) {
dispatch({ dispatch({
type: types.RESOLVE_URI_COMPLETED, type: types.RESOLVE_URI_STARTED,
data: { data: { uri }
uri, })
lbry.resolve({ uri }).then((resolutionInfo) => {
const {
claim, claim,
certificate, certificate,
} } = resolutionInfo ? resolutionInfo : { claim : null, certificate: null }
dispatch({
type: types.RESOLVE_URI_COMPLETED,
data: {
uri,
claim,
certificate,
}
})
}) })
}) }
}
}
export function doCancelResolveUri(uri) {
return function(dispatch, getState) {
lbry.cancelResolve({ uri })
} }
} }

View file

@ -21,13 +21,6 @@ export function doFetchFileInfo(uri) {
const outpoint = claim ? `${claim.txid}:${claim.nout}` : null const outpoint = claim ? `${claim.txid}:${claim.nout}` : null
const alreadyFetching = !!selectLoadingByUri(state)[uri] const alreadyFetching = !!selectLoadingByUri(state)[uri]
if (!outpoint) {
console.log(claim);
console.log(outpoint);
console.log(selectClaimsByUri(state))
throw new Error("Unable to get outpoint from claim for URI " + uri);
}
if (!alreadyFetching) { if (!alreadyFetching) {
dispatch({ dispatch({
type: types.FETCH_FILE_INFO_STARTED, type: types.FETCH_FILE_INFO_STARTED,

View file

@ -7,6 +7,9 @@ import {
import { import {
doCheckUpgradeAvailable, doCheckUpgradeAvailable,
} from 'actions/app' } from 'actions/app'
import {
doUpdateBalance,
} from 'actions/wallet'
import App from './view' import App from './view'
const select = (state) => ({ const select = (state) => ({
@ -15,6 +18,7 @@ const select = (state) => ({
const perform = (dispatch) => ({ const perform = (dispatch) => ({
checkUpgradeAvailable: () => dispatch(doCheckUpgradeAvailable()), checkUpgradeAvailable: () => dispatch(doCheckUpgradeAvailable()),
updateBalance: (balance) => dispatch(doUpdateBalance(balance))
}) })
export default connect(select, perform)(App) export default connect(select, perform)(App)

View file

@ -4,7 +4,8 @@ import Header from 'component/header';
import ErrorModal from 'component/errorModal' import ErrorModal from 'component/errorModal'
import DownloadingModal from 'component/downloadingModal' import DownloadingModal from 'component/downloadingModal'
import UpgradeModal from 'component/upgradeModal' import UpgradeModal from 'component/upgradeModal'
import {Line} from 'rc-progress'; import lbry from 'lbry'
import {Line} from 'rc-progress'
class App extends React.Component { class App extends React.Component {
componentWillMount() { componentWillMount() {
@ -15,6 +16,10 @@ class App extends React.Component {
if (!this.props.upgradeSkipped) { if (!this.props.upgradeSkipped) {
this.props.checkUpgradeAvailable() this.props.checkUpgradeAvailable()
} }
lbry.balanceSubscribe((balance) => {
this.props.updateBalance(balance)
})
} }
render() { render() {

View file

@ -3,7 +3,6 @@ import {
connect, connect,
} from 'react-redux' } from 'react-redux'
import { import {
selectHasSignature,
selectPlatform, selectPlatform,
} from 'selectors/app' } from 'selectors/app'
import { import {

View file

@ -72,11 +72,14 @@ class FileActions extends React.Component {
let content let content
if (fileInfo === undefined || isAvailable === undefined) { console.log('file actions render')
console.log(this.props)
if (!fileInfo && isAvailable === undefined) {
content = <BusyMessage message="Checking availability" /> content = <BusyMessage message="Checking availability" />
} else if (!isAvailable && !this.state.forceShowActions) { } else if (!fileInfo && !isAvailable && !this.state.forceShowActions) {
content = <div> content = <div>
<div className="button-set-item empty">Content unavailable.</div> <div className="button-set-item empty">Content unavailable.</div>
@ -119,7 +122,7 @@ class FileActions extends React.Component {
</DropDownMenu> : '' } </DropDownMenu> : '' }
<Modal type="confirm" isOpen={modal == 'affirmPurchase'} <Modal type="confirm" isOpen={modal == 'affirmPurchase'}
contentLabel="Confirm Purchase" onConfirmed={this.onAffirmPurchase.bind(this)} onAborted={closeModal}> contentLabel="Confirm Purchase" onConfirmed={this.onAffirmPurchase.bind(this)} onAborted={closeModal}>
Are you sure you'd like to buy <strong>{title}</strong> for <strong><FilePrice uri={uri} look="plain" /></strong> credits? This will purchase <strong>{title}</strong> for <strong><FilePrice uri={uri} look="plain" /></strong> credits.
</Modal> </Modal>
<Modal isOpen={modal == 'notEnoughCredits'} contentLabel="Not enough credits" <Modal isOpen={modal == 'notEnoughCredits'} contentLabel="Not enough credits"
onConfirmed={closeModal}> onConfirmed={closeModal}>

View file

@ -7,6 +7,7 @@ import {
} from 'actions/app' } from 'actions/app'
import { import {
doResolveUri, doResolveUri,
doCancelResolveUri,
} from 'actions/content' } from 'actions/content'
import { import {
selectObscureNsfw, selectObscureNsfw,
@ -44,6 +45,7 @@ const makeSelect = () => {
const perform = (dispatch) => ({ const perform = (dispatch) => ({
navigate: (path, params) => dispatch(doNavigate(path, params)), navigate: (path, params) => dispatch(doNavigate(path, params)),
resolveUri: (uri) => dispatch(doResolveUri(uri)), resolveUri: (uri) => dispatch(doResolveUri(uri)),
cancelResolveUri: (uri) => dispatch(doCancelResolveUri(uri))
}) })
export default connect(makeSelect, perform)(FileCard) export default connect(makeSelect, perform)(FileCard)

View file

@ -8,18 +8,30 @@ import UriIndicator from 'component/uriIndicator';
class FileCard extends React.Component { class FileCard extends React.Component {
componentDidMount() { componentDidMount() {
this.resolve(this.props)
}
componentWillReceiveProps(nextProps) {
this.resolve(nextProps)
}
resolve(props) {
const { const {
isResolvingUri, isResolvingUri,
resolveUri, resolveUri,
claim, claim,
uri, uri,
} = this.props } = props
if(!isResolvingUri && !claim && uri) { if(!isResolvingUri && claim === undefined && uri) {
resolveUri(uri) resolveUri(uri)
} }
} }
componentWillUnmount() {
this.props.cancelResolveUri(this.props.uri)
}
handleMouseOver() { handleMouseOver() {
this.setState({ this.setState({
hovered: true, hovered: true,

View file

@ -58,6 +58,7 @@ class FileList extends React.Component {
render() { render() {
const { const {
handleSortChanged, handleSortChanged,
fetching,
fileInfos, fileInfos,
hidePrices, hidePrices,
} = this.props } = this.props
@ -74,7 +75,8 @@ class FileList extends React.Component {
content.push(<FileTile key={uri} uri={uri} hidePrice={hidePrices} hideOnRemove={true} showEmpty={""} />) content.push(<FileTile key={uri} uri={uri} hidePrice={hidePrices} hideOnRemove={true} showEmpty={""} />)
}) })
return ( return (
<section> <section className="file-list__header">
{ fetching && <span className="busy-indicator"/> }
<span className='sort-section'> <span className='sort-section'>
Sort by { ' ' } Sort by { ' ' }
<FormField type="select" onChange={this.handleSortChanged.bind(this)}> <FormField type="select" onChange={this.handleSortChanged.bind(this)}>

View file

@ -20,7 +20,8 @@ const makeSelect = () => {
} }
const perform = (dispatch) => ({ const perform = (dispatch) => ({
fetchCostInfo: (uri) => dispatch(doFetchCostInfoForUri(uri)) fetchCostInfo: (uri) => dispatch(doFetchCostInfoForUri(uri)),
cancelFetchCostInfo: (uri) => dispatch(doCancelFetchCostInfoForUri(uri))
}) })
export default connect(makeSelect, perform)(FilePrice) export default connect(makeSelect, perform)(FilePrice)

View file

@ -38,7 +38,7 @@ class VideoPlayButton extends React.Component {
return (<div> return (<div>
<Link button={ button ? button : null } <Link button={ button ? button : null }
disabled={isLoading || !costInfo || costInfo.cost === undefined || fileInfo === undefined} disabled={isLoading || fileInfo === undefined || (fileInfo === null && (!costInfo || costInfo.cost === undefined))}
label={label ? label : ""} label={label ? label : ""}
className="video__play-button" className="video__play-button"
icon="icon-play" icon="icon-play"
@ -53,7 +53,7 @@ class VideoPlayButton extends React.Component {
contentLabel="Confirm Purchase" contentLabel="Confirm Purchase"
onConfirmed={this.confirmPurchaseClick.bind(this)} onConfirmed={this.confirmPurchaseClick.bind(this)}
onAborted={closeModal}> onAborted={closeModal}>
Are you sure you'd like to buy <strong>{this.props.metadata.title}</strong> for <strong><FilePrice uri={uri} look="plain" /></strong> credits? This will purchase <strong>{title}</strong> for <strong><FilePrice uri={uri} look="plain" /></strong> credits.
</Modal> </Modal>
<Modal <Modal
isOpen={modal == 'timedOut'} onConfirmed={closeModal} contentLabel="Timed Out"> isOpen={modal == 'timedOut'} onConfirmed={closeModal} contentLabel="Timed Out">
@ -98,6 +98,11 @@ class Video extends React.Component {
isPlaying = false, isPlaying = false,
} = this.state } = this.state
const isReadyToPlay = fileInfo && fileInfo.written_bytes > 0
console.log('video render')
console.log(this.props)
let loadStatusMessage = '' let loadStatusMessage = ''
if (isLoading) { if (isLoading) {
@ -107,9 +112,9 @@ class Video extends React.Component {
} }
return ( return (
<div className={"video " + this.props.className + (isPlaying && fileInfo.isReadyToPlay ? " video--active" : " video--hidden")}>{ <div className={"video " + this.props.className + (isPlaying && isReadyToPlay ? " video--active" : " video--hidden")}>{
isPlaying ? isPlaying ?
(!fileInfo.isReadyToPlay ? (!isReadyToPlay ?
<span>this is the world's worst loading screen and we shipped our software with it anyway... <br /><br />{loadStatusMessage}</span> : <span>this is the world's worst loading screen and we shipped our software with it anyway... <br /><br />{loadStatusMessage}</span> :
<VideoPlayer downloadPath={fileInfo.download_path} />) : <VideoPlayer downloadPath={fileInfo.download_path} />) :
<div className="video__cover" style={{backgroundImage: 'url("' + metadata.thumbnail + '")'}}> <div className="video__cover" style={{backgroundImage: 'url("' + metadata.thumbnail + '")'}}>

View file

@ -68,6 +68,8 @@ jsonrpc.call = function (connectionString, method, params, callback, errorCallba
})); }));
sessionStorage.setItem('JSONRPCCounter', counter + 1); sessionStorage.setItem('JSONRPCCounter', counter + 1);
return xhr
}; };
export default jsonrpc; export default jsonrpc;

View file

@ -95,7 +95,7 @@ let lbry = {
}; };
lbry.call = function (method, params, callback, errorCallback, connectFailedCallback) { lbry.call = function (method, params, callback, errorCallback, connectFailedCallback) {
jsonrpc.call(lbry.daemonConnectionString, method, params, callback, errorCallback, connectFailedCallback); return jsonrpc.call(lbry.daemonConnectionString, method, params, callback, errorCallback, connectFailedCallback);
} }
//core //core
@ -177,11 +177,6 @@ lbry.setDaemonSetting = function(setting, value, callback) {
lbry.call('set_settings', setSettingsArgs, callback) lbry.call('set_settings', setSettingsArgs, callback)
} }
lbry.getBalance = function(callback) {
lbry.call("wallet_balance", {}, callback);
}
lbry.sendToAddress = function(amount, address, callback, errorCallback) { lbry.sendToAddress = function(amount, address, callback, errorCallback) {
lbry.call("send_amount_to_address", { "amount" : amount, "address": address }, callback, errorCallback); lbry.call("send_amount_to_address", { "amount" : amount, "address": address }, callback, errorCallback);
} }
@ -641,6 +636,7 @@ lbry.claim_list_mine = function(params={}) {
const claimCacheKey = 'resolve_claim_cache'; const claimCacheKey = 'resolve_claim_cache';
lbry._claimCache = getSession(claimCacheKey, {}); lbry._claimCache = getSession(claimCacheKey, {});
lbry._resolveXhrs = {}
lbry.resolve = function(params={}) { lbry.resolve = function(params={}) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (!params.uri) { if (!params.uri) {
@ -649,7 +645,7 @@ lbry.resolve = function(params={}) {
if (params.uri && lbry._claimCache[params.uri] !== undefined) { if (params.uri && lbry._claimCache[params.uri] !== undefined) {
resolve(lbry._claimCache[params.uri]); resolve(lbry._claimCache[params.uri]);
} else { } else {
lbry.call('resolve', params, function(data) { lbry._resolveXhrs[params.uri] = lbry.call('resolve', params, function(data) {
if (data !== undefined) { if (data !== undefined) {
lbry._claimCache[params.uri] = data; lbry._claimCache[params.uri] = data;
} }
@ -660,6 +656,13 @@ lbry.resolve = function(params={}) {
}); });
} }
lbry.cancelResolve = function(params={}) {
const xhr = lbry._resolveXhrs[params.uri]
if (xhr && xhr.readyState > 0 && xhr.readyState < 4) {
xhr.abort()
}
}
// Adds caching. // Adds caching.
lbry._settingsPromise = null; lbry._settingsPromise = null;
lbry.settings_get = function(params={}) { lbry.settings_get = function(params={}) {

View file

@ -23,12 +23,14 @@ class FileListDownloaded extends React.Component {
} = this.props } = this.props
let content let content
if (fetching) { if (downloadedContent && downloadedContent.length > 0) {
content = <BusyMessage message="Loading" /> content = <FileList fileInfos={downloadedContent} fetching={fetching} hidePrices={true} />
} else if (!downloadedContent.length) {
content = <span>You haven't downloaded anything from LBRY yet. Go <Link onClick={() => navigate('/discover')} label="search for your first download" />!</span>
} else { } else {
content = <FileList fileInfos={downloadedContent} hidePrices={true} /> if (fetching) {
content = <BusyMessage message="Loading" />
} else {
content = <span>You haven't downloaded anything from LBRY yet. Go <Link onClick={() => navigate('/discover')} label="search for your first download" />!</span>
}
} }
return ( return (

View file

@ -44,12 +44,15 @@ class FileListPublished extends React.Component {
} = this.props } = this.props
let content let content
if (fetching) {
content = <BusyMessage message="Loading" /> if (publishedContent && publishedContent.length > 0) {
} else if (!publishedContent.length) { content = <FileList fileInfos={publishedContent} fetching={fetching} hidePrices={true} />
content = <span>You haven't downloaded anything from LBRY yet. Go <Link onClick={() => navigate('/discover')} label="search for your first download" />!</span>
} else { } else {
content = <FileList fileInfos={publishedContent} hidePrices={true} /> if (fetching) {
content = <BusyMessage message="Loading" />
} else {
content = <span>You haven't downloaded anything from LBRY yet. Go <Link onClick={() => navigate('/discover')} label="search for your first download" />!</span>
}
} }
return ( return (

View file

@ -27,11 +27,6 @@ reducers[types.FETCH_FILE_INFO_COMPLETED] = function(state, action) {
const newByUri = Object.assign({}, state.byUri) const newByUri = Object.assign({}, state.byUri)
const newFetching = Object.assign({}, state.fetching) const newFetching = Object.assign({}, state.fetching)
if (fileInfo) {
fileInfo.isReadyToPlay = fileInfo.written_bytes > 0
fileInfo.isDownloaded = fileInfo.completed && fileInfo.written_bytes > 0;
}
newByUri[uri] = fileInfo || null newByUri[uri] = fileInfo || null
delete newFetching[uri] delete newFetching[uri]

View file

@ -191,9 +191,4 @@ export const selectDaemonReady = createSelector(
export const selectObscureNsfw = createSelector( export const selectObscureNsfw = createSelector(
_selectState, _selectState,
(state) => !!state.obscureNsfw (state) => !!state.obscureNsfw
) )
export const selectHasSignature = createSelector(
_selectState,
(state) => !!state.hasSignature
)

View file

@ -42,7 +42,7 @@ export const selectPublishedContent = createSelector(
(state) => state.publishedContent || {} (state) => state.publishedContent || {}
) )
const selectResolvingUris = createSelector( export const selectResolvingUris = createSelector(
_selectState, _selectState,
(state) => state.resolvingUris || [] (state) => state.resolvingUris || []
) )
@ -56,4 +56,4 @@ export const makeSelectIsResolvingForUri = () => {
selectResolvingUri, selectResolvingUri,
(resolving) => resolving (resolving) => resolving
) )
} }

View file

@ -143,6 +143,14 @@ p
font-style: italic; font-style: italic;
} }
/*should be redone/moved*/
.file-list__header {
.busy-indicator {
float: left;
margin-top: 12px;
}
}
.sort-section { .sort-section {
display: block; display: block;
margin-bottom: $spacing-vertical * 2/3; margin-bottom: $spacing-vertical * 2/3;