fix: double pending issue
This commit is contained in:
parent
a69a4e2852
commit
a8d693d890
5 changed files with 71 additions and 56 deletions
|
@ -1,12 +1,11 @@
|
|||
import { connect } from 'react-redux';
|
||||
import { selectMyClaimsWithoutChannels } from 'lbry-redux';
|
||||
import { selectPendingPublishes } from 'redux/selectors/publish';
|
||||
import { selectPendingPublishes, selectClaimsWithPendingPublishes } from 'redux/selectors/publish';
|
||||
import { doNavigate } from 'redux/actions/navigation';
|
||||
import { doCheckPendingPublishes } from 'redux/actions/publish';
|
||||
import FileListPublished from './view';
|
||||
|
||||
const select = state => ({
|
||||
claims: selectMyClaimsWithoutChannels(state),
|
||||
claims: selectClaimsWithPendingPublishes(state),
|
||||
pendingPublishes: selectPendingPublishes(state),
|
||||
});
|
||||
|
||||
|
@ -15,4 +14,7 @@ const perform = dispatch => ({
|
|||
checkIfPublishesConfirmed: publishes => dispatch(doCheckPendingPublishes(publishes)),
|
||||
});
|
||||
|
||||
export default connect(select, perform)(FileListPublished);
|
||||
export default connect(
|
||||
select,
|
||||
perform
|
||||
)(FileListPublished);
|
||||
|
|
|
@ -20,13 +20,12 @@ class FileListPublished extends React.PureComponent<Props> {
|
|||
}
|
||||
|
||||
render() {
|
||||
const { claims, pendingPublishes, navigate } = this.props;
|
||||
const fileInfos = [...pendingPublishes, ...claims];
|
||||
const { claims, navigate } = this.props;
|
||||
|
||||
return (
|
||||
<Page notContained>
|
||||
{fileInfos.length ? (
|
||||
<FileList checkPending fileInfos={fileInfos} sortByHeight />
|
||||
{claims.length ? (
|
||||
<FileList checkPending fileInfos={claims} sortByHeight />
|
||||
) : (
|
||||
<div className="page__empty">
|
||||
{__("It looks like you haven't published anything to LBRY yet.")}
|
||||
|
|
|
@ -25,7 +25,6 @@ class HelpPage extends React.PureComponent {
|
|||
|
||||
componentDidMount() {
|
||||
Native.getAppVersionInfo().then(({ remoteVersion, localVersion, upgradeAvailable }) => {
|
||||
console.log('localVersion: ', localVersion);
|
||||
this.setState({
|
||||
uiVersion: localVersion,
|
||||
upgradeAvailable,
|
||||
|
|
|
@ -187,24 +187,12 @@ export const doPublish = (params: PublishParams) => (dispatch: Dispatch, getStat
|
|||
price,
|
||||
uri,
|
||||
sources,
|
||||
isStillEditing
|
||||
isStillEditing,
|
||||
} = params;
|
||||
|
||||
// get the claim id from the channel name, we will use that instead
|
||||
const namedChannelClaim = myChannels.find(myChannel => myChannel.name === channel);
|
||||
const channelId = namedChannelClaim ? namedChannelClaim.claim_id : '';
|
||||
|
||||
// let isEdit;
|
||||
// const newPublishName = channel ? `${channel}/${name}` : name;
|
||||
// for (let i = 0; i < myClaims.length; i += 1) {
|
||||
// const { channel_name: claimChannelName, name: claimName } = myClaims[i];
|
||||
// const contentName = claimChannelName ? `${claimChannelName}/${claimName}` : claimName;
|
||||
// if (contentName === newPublishName) {
|
||||
// isEdit = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
const fee = contentIsFree || !price.amount ? undefined : { ...price };
|
||||
|
||||
const metadata = {
|
||||
|
@ -245,6 +233,7 @@ export const doPublish = (params: PublishParams) => (dispatch: Dispatch, getStat
|
|||
data: { pendingPublish: { ...publishPayload, isEdit: isStillEditing } },
|
||||
});
|
||||
dispatch(doNotify({ id: MODALS.PUBLISH }, { uri }));
|
||||
dispatch(doCheckPendingPublishes());
|
||||
};
|
||||
|
||||
const failure = error => {
|
||||
|
@ -259,38 +248,36 @@ export const doPublish = (params: PublishParams) => (dispatch: Dispatch, getStat
|
|||
export const doCheckPendingPublishes = () => (dispatch: Dispatch, getState: GetState) => {
|
||||
const state = getState();
|
||||
const pendingPublishes = selectPendingPublishes(state);
|
||||
const myClaims = selectMyClaimsWithoutChannels(state);
|
||||
|
||||
let publishCheckInterval;
|
||||
|
||||
const checkFileList = () => {
|
||||
Lbry.claim_list_mine().then(claims => {
|
||||
const claimsWithoutChannels = claims.filter(claim => !claim.name.match(/^@/));
|
||||
if (myClaims.length !== claimsWithoutChannels.length) {
|
||||
const pendingPublishMap = {};
|
||||
pendingPublishes.forEach(({ name }) => {
|
||||
pendingPublishMap[name] = name;
|
||||
});
|
||||
const pendingPublishMap = {};
|
||||
pendingPublishes.forEach(({ name }) => {
|
||||
pendingPublishMap[name] = name;
|
||||
});
|
||||
|
||||
claims.forEach(claim => {
|
||||
if (pendingPublishMap[claim.name]) {
|
||||
dispatch({
|
||||
type: ACTIONS.REMOVE_PENDING_PUBLISH,
|
||||
data: {
|
||||
name: claim.name,
|
||||
},
|
||||
});
|
||||
dispatch({
|
||||
type: ACTIONS.FETCH_CLAIM_LIST_MINE_COMPLETED,
|
||||
data: {
|
||||
claims,
|
||||
},
|
||||
});
|
||||
claims.forEach(claim => {
|
||||
if (pendingPublishMap[claim.name]) {
|
||||
dispatch({
|
||||
type: ACTIONS.REMOVE_PENDING_PUBLISH,
|
||||
data: {
|
||||
name: claim.name,
|
||||
},
|
||||
});
|
||||
dispatch({
|
||||
type: ACTIONS.FETCH_CLAIM_LIST_MINE_COMPLETED,
|
||||
data: {
|
||||
claims,
|
||||
},
|
||||
});
|
||||
|
||||
delete pendingPublishMap[claim.name];
|
||||
}
|
||||
});
|
||||
delete pendingPublishMap[claim.name];
|
||||
}
|
||||
});
|
||||
|
||||
if (!pendingPublishes.length) {
|
||||
clearInterval(publishCheckInterval);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
import { createSelector } from 'reselect';
|
||||
import { parseURI, selectClaimsById, selectMyClaims } from 'lbry-redux';
|
||||
import {
|
||||
parseURI,
|
||||
selectClaimsById,
|
||||
selectMyClaims,
|
||||
selectMyClaimsWithoutChannels,
|
||||
} from 'lbry-redux';
|
||||
|
||||
const selectState = state => state.publish || {};
|
||||
|
||||
|
@ -8,6 +13,24 @@ export const selectPendingPublishes = createSelector(
|
|||
state => state.pendingPublishes.map(pendingClaim => ({ ...pendingClaim, pending: true })) || []
|
||||
);
|
||||
|
||||
export const selectClaimsWithPendingPublishes = createSelector(
|
||||
selectMyClaimsWithoutChannels,
|
||||
selectPendingPublishes,
|
||||
(claims, pendingPublishes) => {
|
||||
// ensure there are no duplicates, they are being checked for in a setInterval
|
||||
// no need to wait for it to complete though
|
||||
// loop through myclaims
|
||||
// if a claim has the same name as one in pendingPublish, remove it from pending
|
||||
const claimMap = {};
|
||||
claims.forEach(claim => {
|
||||
claimMap[claim.name] = true;
|
||||
});
|
||||
|
||||
const filteredPendingPublishes = pendingPublishes.filter(claim => !claimMap[claim.name]);
|
||||
return [...claims, ...filteredPendingPublishes];
|
||||
}
|
||||
);
|
||||
|
||||
export const selectPublishFormValues = createSelector(selectState, state => {
|
||||
const { pendingPublish, ...formValues } = state;
|
||||
return formValues;
|
||||
|
@ -30,9 +53,17 @@ export const selectPendingPublish = uri =>
|
|||
export const selectIsStillEditing = createSelector(selectPublishFormValues, publishState => {
|
||||
const { editingURI, uri } = publishState;
|
||||
|
||||
const { isChannel: currentIsChannel, claimName: currentClaimName, contentName: currentContentName } = parseURI(uri);
|
||||
const { isChannel: editIsChannel, claimName: editClaimName, contentName: editContentName } = parseURI(editingURI);
|
||||
|
||||
const {
|
||||
isChannel: currentIsChannel,
|
||||
claimName: currentClaimName,
|
||||
contentName: currentContentName,
|
||||
} = parseURI(uri);
|
||||
const {
|
||||
isChannel: editIsChannel,
|
||||
claimName: editClaimName,
|
||||
contentName: editContentName,
|
||||
} = parseURI(editingURI);
|
||||
|
||||
// Depending on the previous/current use of a channel, we need to compare different things
|
||||
// ex: going from a channel to anonymous, the new uri won't return contentName, so we need to use claimName
|
||||
if (!currentIsChannel && editIsChannel) {
|
||||
|
@ -41,9 +72,8 @@ export const selectIsStillEditing = createSelector(selectPublishFormValues, publ
|
|||
return currentContentName === editClaimName;
|
||||
} else if (!currentIsChannel && !editIsChannel) {
|
||||
return currentClaimName === editClaimName;
|
||||
} else {
|
||||
return currentContentName === editContentName;
|
||||
}
|
||||
return currentContentName === editContentName;
|
||||
});
|
||||
|
||||
export const selectMyClaimForUri = createSelector(
|
||||
|
@ -52,7 +82,7 @@ export const selectMyClaimForUri = createSelector(
|
|||
selectClaimsById,
|
||||
selectMyClaims,
|
||||
({ editingURI, uri }, isStillEditing, claimsById, myClaims) => {
|
||||
const { contentName: currentContentName } = parseURI(uri);
|
||||
const { contentName: currentContentName } = parseURI(uri);
|
||||
const { claimId: editClaimId } = parseURI(editingURI);
|
||||
let myClaimForUri;
|
||||
|
||||
|
@ -63,9 +93,7 @@ export const selectMyClaimForUri = createSelector(
|
|||
myClaimForUri = claimsById[editClaimId];
|
||||
} else {
|
||||
// Check if they have a previous claim based on the channel/name
|
||||
myClaimForUri = myClaims.find(
|
||||
claim => claim.name === currentContentName
|
||||
);
|
||||
myClaimForUri = myClaims.find(claim => claim.name === currentContentName);
|
||||
}
|
||||
|
||||
return myClaimForUri;
|
||||
|
|
Loading…
Add table
Reference in a new issue