Move fetching my channels into redux
This commit is contained in:
parent
7c7bbcd064
commit
284ab8a01a
6 changed files with 99 additions and 45 deletions
|
@ -339,3 +339,20 @@ export function doFetchClaimListMine() {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function doFetchChannelListMine() {
|
||||||
|
return function(dispatch, getState) {
|
||||||
|
dispatch({
|
||||||
|
type: types.FETCH_CHANNEL_LIST_MINE_STARTED,
|
||||||
|
});
|
||||||
|
|
||||||
|
const callback = channels => {
|
||||||
|
dispatch({
|
||||||
|
type: types.FETCH_CHANNEL_LIST_MINE_COMPLETED,
|
||||||
|
data: { claims: channels },
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
lbry.channel_list_mine().then(callback);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -64,6 +64,10 @@ export const FETCH_AVAILABILITY_COMPLETED = "FETCH_AVAILABILITY_COMPLETED";
|
||||||
export const FILE_DELETE = "FILE_DELETE";
|
export const FILE_DELETE = "FILE_DELETE";
|
||||||
export const ABANDON_CLAIM_STARTED = "ABANDON_CLAIM_STARTED";
|
export const ABANDON_CLAIM_STARTED = "ABANDON_CLAIM_STARTED";
|
||||||
export const ABANDON_CLAIM_COMPLETED = "ABANDON_CLAIM_COMPLETED";
|
export const ABANDON_CLAIM_COMPLETED = "ABANDON_CLAIM_COMPLETED";
|
||||||
|
export const FETCH_CHANNEL_LIST_MINE_STARTED =
|
||||||
|
"FETCH_CHANNEL_LIST_MINE_STARTED";
|
||||||
|
export const FETCH_CHANNEL_LIST_MINE_COMPLETED =
|
||||||
|
"FETCH_CHANNEL_LIST_MINE_COMPLETED";
|
||||||
|
|
||||||
// Search
|
// Search
|
||||||
export const SEARCH_STARTED = "SEARCH_STARTED";
|
export const SEARCH_STARTED = "SEARCH_STARTED";
|
||||||
|
|
|
@ -2,13 +2,19 @@ import React from "react";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { doNavigate, doHistoryBack } from "actions/app";
|
import { doNavigate, doHistoryBack } from "actions/app";
|
||||||
import { doClaimRewardType } from "actions/rewards";
|
import { doClaimRewardType } from "actions/rewards";
|
||||||
import { selectMyClaims } from "selectors/claims";
|
import {
|
||||||
import { doFetchClaimListMine } from "actions/content";
|
selectMyClaims,
|
||||||
|
selectFetchingMyChannels,
|
||||||
|
selectMyChannelClaims,
|
||||||
|
} from "selectors/claims";
|
||||||
|
import { doFetchClaimListMine, doFetchChannelListMine } from "actions/content";
|
||||||
import rewards from "rewards";
|
import rewards from "rewards";
|
||||||
import PublishPage from "./view";
|
import PublishPage from "./view";
|
||||||
|
|
||||||
const select = state => ({
|
const select = state => ({
|
||||||
myClaims: selectMyClaims(state),
|
myClaims: selectMyClaims(state),
|
||||||
|
fetchingChannels: selectFetchingMyChannels(state),
|
||||||
|
channels: selectMyChannelClaims(state),
|
||||||
});
|
});
|
||||||
|
|
||||||
const perform = dispatch => ({
|
const perform = dispatch => ({
|
||||||
|
@ -17,6 +23,7 @@ const perform = dispatch => ({
|
||||||
fetchClaimListMine: () => dispatch(doFetchClaimListMine()),
|
fetchClaimListMine: () => dispatch(doFetchClaimListMine()),
|
||||||
claimFirstChannelReward: () =>
|
claimFirstChannelReward: () =>
|
||||||
dispatch(doClaimRewardType(rewards.TYPE_FIRST_CHANNEL)),
|
dispatch(doClaimRewardType(rewards.TYPE_FIRST_CHANNEL)),
|
||||||
|
fetchChannelListMine: () => dispatch(doFetchChannelListMine()),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(select, perform)(PublishPage);
|
export default connect(select, perform)(PublishPage);
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { FormField, FormRow } from "component/form.js";
|
||||||
import Link from "component/link";
|
import Link from "component/link";
|
||||||
import rewards from "rewards";
|
import rewards from "rewards";
|
||||||
import Modal from "component/modal";
|
import Modal from "component/modal";
|
||||||
|
import { BusyMessage } from "component/common";
|
||||||
|
|
||||||
class PublishPage extends React.PureComponent {
|
class PublishPage extends React.PureComponent {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
|
@ -13,7 +14,6 @@ class PublishPage extends React.PureComponent {
|
||||||
this._requiredFields = ["meta_title", "name", "bid", "tos_agree"];
|
this._requiredFields = ["meta_title", "name", "bid", "tos_agree"];
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
channels: null,
|
|
||||||
rawName: "",
|
rawName: "",
|
||||||
name: "",
|
name: "",
|
||||||
bid: 10,
|
bid: 10,
|
||||||
|
@ -41,15 +41,18 @@ class PublishPage extends React.PureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
_updateChannelList(channel) {
|
_updateChannelList(channel) {
|
||||||
|
const { fetchingChannels, fetchChannelListMine } = this.props;
|
||||||
|
|
||||||
|
if (!fetchingChannels) fetchChannelListMine();
|
||||||
// Calls API to update displayed list of channels. If a channel name is provided, will select
|
// Calls API to update displayed list of channels. If a channel name is provided, will select
|
||||||
// that channel at the same time (used immediately after creating a channel)
|
// that channel at the same time (used immediately after creating a channel)
|
||||||
lbry.channel_list_mine().then(channels => {
|
// lbry.channel_list_mine().then(channels => {
|
||||||
this.props.claimFirstChannelReward();
|
// this.props.claimFirstChannelReward();
|
||||||
this.setState({
|
// this.setState({
|
||||||
channels: channels,
|
// channels: channels,
|
||||||
...(channel ? { channel } : {}),
|
// ...(channel ? { channel } : {}),
|
||||||
});
|
// });
|
||||||
});
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSubmit(event) {
|
handleSubmit(event) {
|
||||||
|
@ -465,10 +468,6 @@ class PublishPage extends React.PureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
if (this.state.channels === null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const lbcInputHelp = __(
|
const lbcInputHelp = __(
|
||||||
"This LBC remains yours and the deposit can be undone at any time."
|
"This LBC remains yours and the deposit can be undone at any time."
|
||||||
);
|
);
|
||||||
|
@ -729,7 +728,9 @@ class PublishPage extends React.PureComponent {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="card__content">
|
<div className="card__content">
|
||||||
<FormRow
|
{this.props.fetchingChannels
|
||||||
|
? <BusyMessage message="Fetching identities" />
|
||||||
|
: <FormRow
|
||||||
type="select"
|
type="select"
|
||||||
tabIndex="1"
|
tabIndex="1"
|
||||||
onChange={event => {
|
onChange={event => {
|
||||||
|
@ -740,11 +741,13 @@ class PublishPage extends React.PureComponent {
|
||||||
<option key="anonymous" value="anonymous">
|
<option key="anonymous" value="anonymous">
|
||||||
{__("Anonymous")}
|
{__("Anonymous")}
|
||||||
</option>
|
</option>
|
||||||
{this.state.channels.map(({ name }) =>
|
{this.props.channels.map(({ name }) =>
|
||||||
<option key={name} value={name}>{name}</option>
|
<option key={name} value={name}>{name}</option>
|
||||||
)}
|
)}
|
||||||
<option key="new" value="new">{__("New identity...")}</option>
|
<option key="new" value="new">
|
||||||
</FormRow>
|
{__("New identity...")}
|
||||||
|
</option>
|
||||||
|
</FormRow>}
|
||||||
</div>
|
</div>
|
||||||
{this.state.channel == "new"
|
{this.state.channel == "new"
|
||||||
? <div className="card__content">
|
? <div className="card__content">
|
||||||
|
|
|
@ -50,21 +50,26 @@ reducers[types.FETCH_CLAIM_LIST_MINE_COMPLETED] = function(state, action) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// reducers[types.FETCH_CHANNEL_CLAIMS_STARTED] = function(state, action) {
|
reducers[types.FETCH_CHANNEL_LIST_MINE_STARTED] = function(state, action) {
|
||||||
// const {
|
return Object.assign({}, state, { fetchingMyChannels: true });
|
||||||
// uri,
|
};
|
||||||
// } = action.data
|
|
||||||
//
|
reducers[types.FETCH_CHANNEL_LIST_MINE_COMPLETED] = function(state, action) {
|
||||||
// const newClaims = Object.assign({}, state.claimsByChannel)
|
const { claims } = action.data;
|
||||||
//
|
const myChannelClaims = new Set(state.myChannelClaims);
|
||||||
// if (claims !== undefined) {
|
const byId = Object.assign({}, state.byId);
|
||||||
// newClaims[uri] = claims
|
|
||||||
// }
|
claims.forEach(claim => {
|
||||||
//
|
myChannelClaims.add(claim.claim_id);
|
||||||
// return Object.assign({}, state, {
|
byId[claims.claim_id] = claim;
|
||||||
// claimsByChannel: newClaims
|
});
|
||||||
// })
|
|
||||||
// }
|
return Object.assign({}, state, {
|
||||||
|
byId,
|
||||||
|
fetchingMyChannels: false,
|
||||||
|
myChannelClaims,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
reducers[types.FETCH_CHANNEL_CLAIMS_COMPLETED] = function(state, action) {
|
reducers[types.FETCH_CHANNEL_CLAIMS_COMPLETED] = function(state, action) {
|
||||||
const { uri, claims } = action.data;
|
const { uri, claims } = action.data;
|
||||||
|
|
|
@ -124,3 +124,21 @@ export const selectMyClaimsOutpoints = createSelector(
|
||||||
return outpoints;
|
return outpoints;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const selectFetchingMyChannels = createSelector(
|
||||||
|
_selectState,
|
||||||
|
state => !!state.fetchingMyChannels
|
||||||
|
);
|
||||||
|
|
||||||
|
export const selectMyChannelClaims = createSelector(
|
||||||
|
_selectState,
|
||||||
|
selectClaimsById,
|
||||||
|
(state, byId) => {
|
||||||
|
const ids = state.myChannelClaims || [];
|
||||||
|
const claims = [];
|
||||||
|
|
||||||
|
ids.forEach(id => claims.push(byId[id]));
|
||||||
|
|
||||||
|
return claims;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
Loading…
Reference in a new issue