updated channel display to use redux store
This commit is contained in:
parent
ff86b0aa81
commit
a00ff9203c
9 changed files with 141 additions and 135 deletions
|
@ -16,10 +16,22 @@ export function updateChannelRequest (channel) {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export function updateChannelData (channelData) {
|
export function updateChannelData (name, longId, shortId) {
|
||||||
return {
|
return {
|
||||||
type: actions.CHANNEL_DATA_UPDATE,
|
type: actions.CHANNEL_DATA_UPDATE,
|
||||||
channelData,
|
name,
|
||||||
|
longId,
|
||||||
|
shortId,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export function updateChannelClaimsData (claims, currentPage, totalPages, totalClaims) {
|
||||||
|
return {
|
||||||
|
type: actions.CHANNEL_CLAIMS_UPDATE,
|
||||||
|
claims,
|
||||||
|
currentPage,
|
||||||
|
totalPages,
|
||||||
|
totalClaims,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
export const CLAIM_REQUEST_UPDATE = 'CLAIM_REQUEST_UPDATE';
|
export const CLAIM_REQUEST_UPDATE = 'CLAIM_REQUEST_UPDATE';
|
||||||
export const CHANNEL_REQUEST_UPDATE = 'CHANNEL_REQUEST_UPDATE';
|
export const CHANNEL_REQUEST_UPDATE = 'CHANNEL_REQUEST_UPDATE';
|
||||||
export const CHANNEL_DATA_UPDATE = 'CHANNEL_DATA_UPDATE';
|
export const CHANNEL_DATA_UPDATE = 'CHANNEL_DATA_UPDATE';
|
||||||
|
export const CHANNEL_CLAIMS_UPDATE = 'CHANNEL_CLAIMS_UPDATE';
|
||||||
export const CLAIM_DATA_UPDATE = 'CLAIM_DATA_UPDATE';
|
export const CLAIM_DATA_UPDATE = 'CLAIM_DATA_UPDATE';
|
||||||
|
|
24
react/containers/ChannelClaimsDisplay/index.js
Normal file
24
react/containers/ChannelClaimsDisplay/index.js
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
import View from './view';
|
||||||
|
import {updateChannelClaimsData} from 'actions/show';
|
||||||
|
|
||||||
|
const mapStateToProps = ({ show }) => {
|
||||||
|
return {
|
||||||
|
name : show.channel.name,
|
||||||
|
id : show.channel.id,
|
||||||
|
claims : show.channel.claimsData.claims,
|
||||||
|
currentPage: show.channel.claimsData.currentPage,
|
||||||
|
totalPages : show.channel.claimsData.totalPages,
|
||||||
|
totalClaims: show.channel.claimsData.totalClaims,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const mapDispatchToProps = dispatch => {
|
||||||
|
return {
|
||||||
|
onClaimsDataChange: (claims, currentPage, totalPages, totalClaims) => {
|
||||||
|
dispatch(updateChannelClaimsData(claims, currentPage, totalPages, totalClaims));
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default connect(mapStateToProps, mapDispatchToProps)(View);
|
|
@ -1,5 +1,5 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import AssetPreview from 'components/AssetPreview';
|
import AssetPreview from 'components/AssetPreview/index';
|
||||||
import request from 'utils/request';
|
import request from 'utils/request';
|
||||||
|
|
||||||
class ChannelClaimsDisplay extends React.Component {
|
class ChannelClaimsDisplay extends React.Component {
|
||||||
|
@ -12,13 +12,11 @@ class ChannelClaimsDisplay extends React.Component {
|
||||||
this.getAndStoreChannelClaims = this.getAndStoreChannelClaims.bind(this);
|
this.getAndStoreChannelClaims = this.getAndStoreChannelClaims.bind(this);
|
||||||
}
|
}
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
const channelName = this.props.channelName;
|
this.getAndStoreChannelClaims(this.props.name, this.props.id, this.state.page);
|
||||||
const channelClaimId = this.props.channelClaimId || 'none';
|
|
||||||
const page = this.state.page;
|
|
||||||
this.getAndStoreChannelClaims(channelName, channelClaimId, page);
|
|
||||||
}
|
}
|
||||||
getAndStoreChannelClaims (channelName, channelClaimId, page) {
|
getAndStoreChannelClaims (name, id, page) {
|
||||||
const url = `/api/channel-claims/${channelName}/${channelClaimId}/${page}`;
|
if (!id) id = 'none';
|
||||||
|
const url = `/api/channel-claims/${name}/${id}/${page}`;
|
||||||
const that = this;
|
const that = this;
|
||||||
return request(url)
|
return request(url)
|
||||||
.then(({ success, message, data }) => {
|
.then(({ success, message, data }) => {
|
||||||
|
@ -26,14 +24,7 @@ class ChannelClaimsDisplay extends React.Component {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
return that.setState({error: message});
|
return that.setState({error: message});
|
||||||
}
|
}
|
||||||
that.setState({
|
this.props.onClaimsDataChange(data.claims, data.currentPage, data.totalPages, data.totalResults);
|
||||||
claims : data.claims,
|
|
||||||
currentPage : data.currentPage,
|
|
||||||
nextPage : data.nextPage,
|
|
||||||
previousPage: data.previousPage,
|
|
||||||
totalPages : data.totalPages,
|
|
||||||
totalResults: data.totalResults,
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
that.setState({error: error.message});
|
that.setState({error: error.message});
|
||||||
|
@ -50,12 +41,19 @@ class ChannelClaimsDisplay extends React.Component {
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="row row--tall">
|
<div className="row row--tall">
|
||||||
{this.state.claims && this.state.claims.map((claim, index) => <AssetPreview
|
{this.props.claims &&
|
||||||
|
<div>
|
||||||
|
{this.props.claims.map((claim, index) => <AssetPreview
|
||||||
name={claim.name}
|
name={claim.name}
|
||||||
claimId={claim.claimId}
|
claimId={claim.claimId}
|
||||||
contentType={claim.contentType}
|
contentType={claim.contentType}
|
||||||
key={index}
|
key={index}
|
||||||
/>)}
|
/>)}
|
||||||
|
<p>current page: {this.props.currentPage}</p>
|
||||||
|
<p>total pages: {this.props.totalPages}</p>
|
||||||
|
<p>total claims: {this.props.totalClaims}</p>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
@ -63,8 +61,4 @@ class ChannelClaimsDisplay extends React.Component {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// required props
|
|
||||||
// channelName
|
|
||||||
// channelClaimId
|
|
||||||
|
|
||||||
export default ChannelClaimsDisplay;
|
export default ChannelClaimsDisplay;
|
27
react/containers/ShowChannel/index.js
Normal file
27
react/containers/ShowChannel/index.js
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
import View from './view';
|
||||||
|
import {updateChannelData} from 'actions/show';
|
||||||
|
|
||||||
|
const mapStateToProps = ({ show }) => {
|
||||||
|
return {
|
||||||
|
request: {
|
||||||
|
name: show.request.channel.name,
|
||||||
|
id : show.request.channel.id,
|
||||||
|
},
|
||||||
|
channel: {
|
||||||
|
name : show.channel.name,
|
||||||
|
shortId: show.channel.shortId,
|
||||||
|
longId : show.channel.longId,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const mapDispatchToProps = dispatch => {
|
||||||
|
return {
|
||||||
|
onChannelDataChange: (name, longId, shortId) => {
|
||||||
|
dispatch(updateChannelData(name, longId, shortId));
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default connect(mapStateToProps, mapDispatchToProps)(View);
|
|
@ -1,6 +1,6 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import NavBar from 'containers/NavBar';
|
import NavBar from 'containers/NavBar';
|
||||||
import ChannelClaimsDisplay from 'components/ChannelClaimsDisplay';
|
import ChannelClaimsDisplay from 'containers/ChannelClaimsDisplay';
|
||||||
import request from 'utils/request';
|
import request from 'utils/request';
|
||||||
|
|
||||||
class ShowChannel extends React.Component {
|
class ShowChannel extends React.Component {
|
||||||
|
@ -12,12 +12,11 @@ class ShowChannel extends React.Component {
|
||||||
this.getAndStoreChannelData = this.getAndStoreChannelData.bind(this);
|
this.getAndStoreChannelData = this.getAndStoreChannelData.bind(this);
|
||||||
}
|
}
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
const channelName = this.props.channelName;
|
this.getAndStoreChannelData(this.props.request.name, this.props.request.id);
|
||||||
const channelClaimId = this.props.channelClaimId || 'none';
|
|
||||||
this.getAndStoreChannelData(channelName, channelClaimId);
|
|
||||||
}
|
}
|
||||||
getAndStoreChannelData (channelName, channelClaimId) {
|
getAndStoreChannelData (name, id) {
|
||||||
const url = `/api/channel-data/${channelName}/${channelClaimId}`;
|
if (!id) id = 'none';
|
||||||
|
const url = `/api/channel-data/${name}/${id}`;
|
||||||
const that = this;
|
const that = this;
|
||||||
return request(url)
|
return request(url)
|
||||||
.then(({ success, message, data }) => {
|
.then(({ success, message, data }) => {
|
||||||
|
@ -25,11 +24,7 @@ class ShowChannel extends React.Component {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
return that.setState({error: message});
|
return that.setState({error: message});
|
||||||
}
|
}
|
||||||
that.setState({
|
this.props.onChannelDataChange(data.channelName, data.longChannelClaimId, data.shortChannelClaimId);
|
||||||
channelName : data.channelName,
|
|
||||||
longChannelClaimId : data.longChannelClaimId,
|
|
||||||
shortChannelClaimId: data.shortChannelClaimId,
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
that.setState({error: error.message});
|
that.setState({error: error.message});
|
||||||
|
@ -48,17 +43,12 @@ class ShowChannel extends React.Component {
|
||||||
) : (
|
) : (
|
||||||
<div className="row row--tall row--padded">
|
<div className="row row--tall row--padded">
|
||||||
<div className="column column--10">
|
<div className="column column--10">
|
||||||
<h2>channel name: {this.props.channelName}</h2>
|
<h2>channel name: {this.props.channel.name}</h2>
|
||||||
<p>full channel id: {this.state.longChannelClaimId ? this.state.longChannelClaimId : 'loading...'}</p>
|
<p>full channel id: {this.props.channel.longId ? this.props.channel.longId : 'loading...'}</p>
|
||||||
<p>short channel id: {this.state.shortChannelClaimId ? this.state.shortChannelClaimId : 'loading...'}</p>
|
<p>short channel id: {this.props.channel.shortId ? this.props.channel.shortId : 'loading...'}</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="column column--10">
|
<div className="column column--10">
|
||||||
{ (this.state.channelName && this.state.longChannelClaimId) &&
|
{this.props.channel.name && <ChannelClaimsDisplay/>}
|
||||||
<ChannelClaimsDisplay
|
|
||||||
channelName={this.state.channelName}
|
|
||||||
channelClaimId={this.state.longChannelClaimId}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
@ -67,9 +57,4 @@ class ShowChannel extends React.Component {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// required props
|
|
||||||
// channelName
|
|
||||||
// channelClaimId
|
|
||||||
|
|
||||||
|
|
||||||
export default ShowChannel;
|
export default ShowChannel;
|
|
@ -4,8 +4,7 @@ import View from './view';
|
||||||
|
|
||||||
const mapStateToProps = ({ show }) => {
|
const mapStateToProps = ({ show }) => {
|
||||||
return {
|
return {
|
||||||
channel: show.request.channel,
|
request: show.request,
|
||||||
claim : show.request.claim,
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ErrorPage from 'components/ErrorPage';
|
import ErrorPage from 'components/ErrorPage';
|
||||||
import ShowAsset from 'components/ShowAsset';
|
import ShowAsset from 'components/ShowAsset';
|
||||||
import ShowChannel from 'components/ShowChannel';
|
import ShowChannel from 'containers/ShowChannel';
|
||||||
import lbryUri from 'utils/lbryUri';
|
import lbryUri from 'utils/lbryUri';
|
||||||
|
|
||||||
class ShowPage extends React.Component {
|
class ShowPage extends React.Component {
|
||||||
|
@ -35,7 +35,6 @@ class ShowPage extends React.Component {
|
||||||
this.parseAndUpdateClaimOnly(claim);
|
this.parseAndUpdateClaimOnly(claim);
|
||||||
}
|
}
|
||||||
parseAndUpdateIdentifierAndClaim (modifier, claim) {
|
parseAndUpdateIdentifierAndClaim (modifier, claim) {
|
||||||
// handle case of identifier and claim
|
|
||||||
// this is a request for an asset
|
// this is a request for an asset
|
||||||
// claim will be an asset claim
|
// claim will be an asset claim
|
||||||
// the identifier could be a channel or a claim id
|
// the identifier could be a channel or a claim id
|
||||||
|
@ -66,7 +65,6 @@ class ShowPage extends React.Component {
|
||||||
return this.props.onClaimRequest(requestedClaim);
|
return this.props.onClaimRequest(requestedClaim);
|
||||||
}
|
}
|
||||||
parseAndUpdateClaimOnly (claim) {
|
parseAndUpdateClaimOnly (claim) {
|
||||||
// handle case of just claim
|
|
||||||
// this could be a request for an asset or a channel page
|
// this could be a request for an asset or a channel page
|
||||||
// claim could be an asset claim or a channel claim
|
// claim could be an asset claim or a channel claim
|
||||||
let isChannel, channelName, channelClaimId;
|
let isChannel, channelName, channelClaimId;
|
||||||
|
@ -104,25 +102,23 @@ class ShowPage extends React.Component {
|
||||||
<ErrorPage error={this.state.error}/>
|
<ErrorPage error={this.state.error}/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (this.state.claim) {
|
if (this.props.request) {
|
||||||
if (this.state.claim.isChannel) {
|
if (this.props.request.channel) {
|
||||||
return (
|
return (
|
||||||
<ShowChannel
|
<ShowChannel />
|
||||||
channelName={this.state.claim.channelName}
|
|
||||||
channelClaimId={this.state.claim.channelClaimId}
|
|
||||||
/>
|
|
||||||
);
|
);
|
||||||
}
|
} else if (this.props.request.claim) {
|
||||||
return (
|
return (
|
||||||
<ShowAsset
|
<ShowAsset
|
||||||
identifier={this.state.identifier} // this.state.url.identifier
|
modifier={this.props.request.claim.identifier}
|
||||||
claim={this.state.claim} // this.state.url.claim
|
claim={this.props.request.claim.name}
|
||||||
isServeRequest={this.state.isServeRequest} // this.state.url.ending
|
extension={this.props.request.claim.extension}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<p>Loading...</p>
|
<p>loading...</p>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,71 +2,24 @@ import * as actions from 'constants/show_action_types';
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
request: {
|
request: {
|
||||||
|
channel: null,
|
||||||
|
claim : null,
|
||||||
|
},
|
||||||
channel: {
|
channel: {
|
||||||
name: null,
|
name : null,
|
||||||
id : null,
|
shortId : null,
|
||||||
|
longId : null,
|
||||||
|
claimsData: {
|
||||||
|
claims : null,
|
||||||
|
currentPage: null,
|
||||||
|
totalPages : null,
|
||||||
|
totalClaims: null,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
claim: {
|
claim: {
|
||||||
name : null,
|
|
||||||
modifier: {
|
|
||||||
id : null,
|
|
||||||
channel: {
|
|
||||||
name: null,
|
name: null,
|
||||||
id : null,
|
id : null,
|
||||||
},
|
data: null,
|
||||||
},
|
|
||||||
extension: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
channelData: {
|
|
||||||
channelName : null,
|
|
||||||
claims : null,
|
|
||||||
currentPage : null,
|
|
||||||
previousPage: null,
|
|
||||||
totalPages : null,
|
|
||||||
totalResults: null,
|
|
||||||
},
|
|
||||||
claimData: {
|
|
||||||
FileId : null,
|
|
||||||
address : null,
|
|
||||||
amount : null,
|
|
||||||
author : null,
|
|
||||||
certificateId : null,
|
|
||||||
channelName : null,
|
|
||||||
claimId : null,
|
|
||||||
claimSequence : null,
|
|
||||||
claimType : null,
|
|
||||||
contentType : null,
|
|
||||||
createdAt : null,
|
|
||||||
decodedClaim : null,
|
|
||||||
depth : null,
|
|
||||||
description : null,
|
|
||||||
effectiveAmount: null,
|
|
||||||
fileExt : null,
|
|
||||||
hasSignature : null,
|
|
||||||
height : null,
|
|
||||||
hex : null,
|
|
||||||
host : null,
|
|
||||||
id : null,
|
|
||||||
language : null,
|
|
||||||
license : null,
|
|
||||||
licenseUrl : null,
|
|
||||||
metadataVersion: null,
|
|
||||||
name : null,
|
|
||||||
nout : null,
|
|
||||||
nsfw : null,
|
|
||||||
outpoint : null,
|
|
||||||
preview : null,
|
|
||||||
source : null,
|
|
||||||
sourceType : null,
|
|
||||||
sourceVersion : null,
|
|
||||||
streamVersion : null,
|
|
||||||
thumbnail : null,
|
|
||||||
title : null,
|
|
||||||
txid : null,
|
|
||||||
updatedAt : null,
|
|
||||||
validAtHeight : null,
|
|
||||||
valueVersion : null,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -92,11 +45,26 @@ export default function (state = initialState, action) {
|
||||||
});
|
});
|
||||||
case actions.CHANNEL_DATA_UPDATE:
|
case actions.CHANNEL_DATA_UPDATE:
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
channelData: action.channelData,
|
channel: Object.assign({}, state.channel, {
|
||||||
|
name : action.name,
|
||||||
|
shortId: action.shortId,
|
||||||
|
longId : action.longId,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
case actions.CHANNEL_CLAIMS_UPDATE:
|
||||||
|
return Object.assign({}, state, {
|
||||||
|
channel: Object.assign({}, state.channel, {
|
||||||
|
claimsData: {
|
||||||
|
claims : action.claims,
|
||||||
|
currentPage: action.currentPage,
|
||||||
|
totalPages : action.totalPages,
|
||||||
|
totalClaims: action.totalClaims,
|
||||||
|
},
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
case actions.CLAIM_DATA_UPDATE:
|
case actions.CLAIM_DATA_UPDATE:
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
claimData: action.claimData,
|
displayClaim: action.claimData,
|
||||||
});
|
});
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
|
|
Loading…
Reference in a new issue