Compare commits

...

2 commits

Author SHA1 Message Date
Akinwale Ariwodola
a1f58b2a07 fixes per review 2019-10-25 16:42:16 +01:00
Akinwale Ariwodola
ed6b527b8d improve handling of pending claims 2019-10-21 17:11:09 +01:00
5 changed files with 52 additions and 5 deletions

View file

@ -5,10 +5,11 @@ import {
doToast, doToast,
doUpdatePublishForm, doUpdatePublishForm,
selectBalance, selectBalance,
selectMyClaims,
selectPublishFormValues, selectPublishFormValues,
} from 'lbry-redux'; } from 'lbry-redux';
import { selectDrawerStack } from 'redux/selectors/drawer'; import { selectDrawerStack } from 'redux/selectors/drawer';
import { doUpdatePublishFormState, doClearPublishFormState } from 'redux/actions/form'; import { doUpdatePublishFormState, doClearPublishFormState, doPendingPublishSuccess } from 'redux/actions/form';
import { doPushDrawerStack, doPopDrawerStack, doSetPlayerVisible } from 'redux/actions/drawer'; import { doPushDrawerStack, doPopDrawerStack, doSetPlayerVisible } from 'redux/actions/drawer';
import { selectPublishFormState, selectHasPublishFormState } from 'redux/selectors/form'; import { selectPublishFormState, selectHasPublishFormState } from 'redux/selectors/form';
import Constants from 'constants'; // eslint-disable-line node/no-deprecated-api import Constants from 'constants'; // eslint-disable-line node/no-deprecated-api
@ -18,6 +19,7 @@ const select = state => ({
balance: selectBalance(state), balance: selectBalance(state),
drawerStack: selectDrawerStack(state), drawerStack: selectDrawerStack(state),
hasFormState: selectHasPublishFormState(state), hasFormState: selectHasPublishFormState(state),
myClaims: selectMyClaims(state),
publishFormState: selectPublishFormState(state), publishFormState: selectPublishFormState(state),
publishFormValues: selectPublishFormValues(state), publishFormValues: selectPublishFormValues(state),
}); });
@ -25,6 +27,7 @@ const select = state => ({
const perform = dispatch => ({ const perform = dispatch => ({
notify: data => dispatch(doToast(data)), notify: data => dispatch(doToast(data)),
clearPublishFormState: () => dispatch(doClearPublishFormState()), clearPublishFormState: () => dispatch(doClearPublishFormState()),
pendingPublishSuccess: pendingClaim => dispatch(doPendingPublishSuccess(pendingClaim)),
updatePublishForm: value => dispatch(doUpdatePublishForm(value)), updatePublishForm: value => dispatch(doUpdatePublishForm(value)),
updatePublishFormState: data => dispatch(doUpdatePublishFormState(data)), updatePublishFormState: data => dispatch(doUpdatePublishFormState(data)),
publish: (success, fail) => dispatch(doPublish(success, fail)), publish: (success, fail) => dispatch(doPublish(success, fail)),

View file

@ -17,10 +17,12 @@ import {
import { FlatGrid } from 'react-native-super-grid'; import { FlatGrid } from 'react-native-super-grid';
import { import {
isNameValid, isNameValid,
batchActions,
buildURI, buildURI,
normalizeURI, normalizeURI,
parseURI, parseURI,
regexInvalidURI, regexInvalidURI,
ACTIONS,
CLAIM_VALUES, CLAIM_VALUES,
LICENSES, LICENSES,
MATURE_TAGS, MATURE_TAGS,
@ -394,11 +396,11 @@ class PublishPage extends React.PureComponent {
}; };
handlePublishSuccess = data => { handlePublishSuccess = data => {
const { clearPublishFormState, navigation, notify } = this.props; const { clearPublishFormState, navigation, notify, pendingPublishSuccess } = this.props;
const pendingClaim = data.outputs[0]; const pendingClaim = data.outputs[0];
logPublish(pendingClaim); logPublish(pendingClaim);
// TODO: fake temp claim for claim_list_mine pendingPublishSuccess(pendingClaim);
notify({ notify({
message: `Your content was successfully published to ${this.state.uri}. It will be available in a few mintues.`, message: `Your content was successfully published to ${this.state.uri}. It will be available in a few mintues.`,

View file

@ -3,7 +3,9 @@ import {
doAbandonClaim, doAbandonClaim,
doCheckPendingPublishes, doCheckPendingPublishes,
doFetchClaimListMine, doFetchClaimListMine,
doToast,
selectMyClaimUrisWithoutChannels, selectMyClaimUrisWithoutChannels,
selectPendingClaims,
selectIsFetchingClaimListMine, selectIsFetchingClaimListMine,
} from 'lbry-redux'; } from 'lbry-redux';
import { doPushDrawerStack, doSetPlayerVisible } from 'redux/actions/drawer'; import { doPushDrawerStack, doSetPlayerVisible } from 'redux/actions/drawer';
@ -13,12 +15,14 @@ import PublishesPage from './view';
const select = state => ({ const select = state => ({
uris: selectMyClaimUrisWithoutChannels(state), uris: selectMyClaimUrisWithoutChannels(state),
fetching: selectIsFetchingClaimListMine(state), fetching: selectIsFetchingClaimListMine(state),
pendingClaims: selectPendingClaims(state),
}); });
const perform = dispatch => ({ const perform = dispatch => ({
abandonClaim: (txid, nout) => dispatch(doAbandonClaim(txid, nout)), abandonClaim: (txid, nout) => dispatch(doAbandonClaim(txid, nout)),
fetchMyClaims: () => dispatch(doFetchClaimListMine()), fetchMyClaims: () => dispatch(doFetchClaimListMine()),
checkPendingPublishes: () => dispatch(doCheckPendingPublishes()), checkPendingPublishes: () => dispatch(doCheckPendingPublishes()),
notify: data => dispatch(doToast(data)),
pushDrawerStack: () => dispatch(doPushDrawerStack(Constants.DRAWER_ROUTE_PUBLISHES)), pushDrawerStack: () => dispatch(doPushDrawerStack(Constants.DRAWER_ROUTE_PUBLISHES)),
setPlayerVisible: () => dispatch(doSetPlayerVisible(false)), setPlayerVisible: () => dispatch(doSetPlayerVisible(false)),
}); });

View file

@ -54,6 +54,8 @@ class PublishesPage extends React.PureComponent {
}; };
addOrRemoveItem = (uri, claim) => { addOrRemoveItem = (uri, claim) => {
const { pendingClaims } = this.state;
const { selectedClaimsMap } = this.state; const { selectedClaimsMap } = this.state;
let selectedUris = [...this.state.selectedUris]; let selectedUris = [...this.state.selectedUris];
@ -172,8 +174,15 @@ class PublishesPage extends React.PureComponent {
if (selectionMode) { if (selectionMode) {
this.handleSelectItem(item, claim); this.handleSelectItem(item, claim);
} else { } else {
// TODO: when shortUrl is available for my claims, navigate to that URL instead const { notify, pendingClaims } = this.props;
navigateToUri(navigation, item); if (pendingClaims.some(pendingClaim => pendingClaim.claim_id === claim.claim_id)) {
notify({
message: __('This content is currently pending. It will be available in a few minutes.'),
});
} else {
// TODO: when shortUrl is available for my claims, navigate to that URL instead
navigateToUri(navigation, item);
}
} }
}} }}
onLongPress={claim => this.handleItemLongPress(item, claim)} onLongPress={claim => this.handleItemLongPress(item, claim)}

View file

@ -1,4 +1,5 @@
import Constants from 'constants'; // eslint-disable-line node/no-deprecated-api import Constants from 'constants'; // eslint-disable-line node/no-deprecated-api
import { ACTIONS, batchActions, selectMyClaims } from 'lbry-redux';
export const doUpdatePublishFormState = publishFormValue => dispatch => export const doUpdatePublishFormState = publishFormValue => dispatch =>
dispatch({ dispatch({
@ -21,3 +22,31 @@ export const doClearChannelFormState = () => dispatch =>
dispatch({ dispatch({
type: Constants.ACTION_CLEAR_CHANNEL_FORM_STATE, type: Constants.ACTION_CLEAR_CHANNEL_FORM_STATE,
}); });
export const doPendingPublishSuccess = pendingClaim => (dispatch, getState) => {
const state = getState();
const myClaims = selectMyClaims(state);
const { permanent_url: url } = pendingClaim;
const actions = [
{
type: ACTIONS.PUBLISH_SUCCESS,
},
];
// We have to fake a temp claim until the new pending one is returned by claim_list_mine
// We can't rely on claim_list_mine because there might be some delay before the new claims are returned
// Doing this allows us to show the pending claim immediately, it will get overwritten by the real one
const isMatch = claim => claim.claim_id === pendingClaim.claim_id;
const isEdit = myClaims.some(isMatch);
const myNewClaims = isEdit
? myClaims.map(claim => (isMatch(claim) ? pendingClaim : claim))
: myClaims.concat(pendingClaim);
actions.push({
type: ACTIONS.FETCH_CLAIM_LIST_MINE_COMPLETED,
data: {
claims: myNewClaims,
},
});
dispatch(batchActions(...actions));
};