lbry-desktop/ui/redux/selectors/publish.js

82 lines
2.6 KiB
JavaScript
Raw Normal View History

2018-03-26 23:32:43 +02:00
import { createSelector } from 'reselect';
2019-08-28 02:01:51 +02:00
import { parseURI, selectClaimsById, selectMyClaimsWithoutChannels, selectResolvingUris, buildURI } from 'lbry-redux';
2018-03-26 23:32:43 +02:00
const selectState = state => state.publish || {};
2019-03-05 05:46:57 +01:00
export const selectPublishFormValues = createSelector(
selectState,
state => {
const { pendingPublish, ...formValues } = state;
return formValues;
}
);
2018-03-26 23:32:43 +02:00
export const makeSelectPublishFormValue = item =>
createSelector(
selectState,
state => state[item]
);
2018-06-12 07:11:17 +02:00
// Is the current uri the same as the uri they clicked "edit" on
2019-03-05 05:46:57 +01:00
export const selectIsStillEditing = createSelector(
selectPublishFormValues,
publishState => {
const { editingURI, uri } = publishState;
2018-06-12 07:11:17 +02:00
2019-03-05 05:46:57 +01:00
if (!editingURI || !uri) {
return false;
}
2019-05-07 23:38:29 +02:00
const { isChannel: currentIsChannel, claimName: currentClaimName, contentName: currentContentName } = parseURI(uri);
const { isChannel: editIsChannel, claimName: editClaimName, contentName: editContentName } = parseURI(editingURI);
2018-06-12 09:12:22 +02:00
2019-03-05 05:46:57 +01:00
// 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
const currentName = currentIsChannel ? currentContentName : currentClaimName;
const editName = editIsChannel ? editContentName : editClaimName;
return currentName === editName;
}
);
2018-06-12 07:11:17 +02:00
export const selectMyClaimForUri = createSelector(
selectPublishFormValues,
selectIsStillEditing,
selectClaimsById,
selectMyClaimsWithoutChannels,
2018-06-12 07:11:17 +02:00
({ editingURI, uri }, isStillEditing, claimsById, myClaims) => {
const { contentName, claimName } = parseURI(uri);
2018-06-12 07:11:17 +02:00
const { claimId: editClaimId } = parseURI(editingURI);
// If isStillEditing
// They clicked "edit" from the file page
// They haven't changed the channel/name after clicking edit
// Get the claim so they can edit without re-uploading a new file
return isStillEditing
? claimsById[editClaimId]
2019-03-05 05:46:57 +01:00
: myClaims.find(claim =>
2019-05-07 23:38:29 +02:00
!contentName ? claim.name === claimName : claim.name === contentName || claim.name === claimName
);
2018-06-12 07:11:17 +02:00
}
);
2018-09-25 02:17:08 +02:00
export const selectIsResolvingPublishUris = createSelector(
selectState,
selectResolvingUris,
({ uri, name }, resolvingUris) => {
if (uri) {
const isResolvingUri = resolvingUris.includes(uri);
const { isChannel } = parseURI(uri);
let isResolvingShortUri;
if (isChannel) {
const shortUri = buildURI({ contentName: name });
isResolvingShortUri = resolvingUris.includes(shortUri);
}
return isResolvingUri || isResolvingShortUri;
}
return false;
}
);