lbry-desktop/ui/redux/selectors/user.js
Rafael Saes 83dbe8ec7c
Playlists v2: Refactors, touch ups + Queue Mode (#1604)
* Playlists v2

* Style pass

* Change playlist items arrange icon

* Playlist card body open by default

* Refactor collectionEdit components

* Paginate & Refactor bid field

* Collection page changes

* Add Thumbnail optional

* Replace extra info for description on collection page

* Playlist card right below video on medium screen

* Allow editing private collections

* Add edit option to menus

* Allow deleting a public playlist but keeping a private version

* Add queue to Save menu, remove edit option from Builtin pages, show queue on playlists page

* Fix scroll to recent persisting on medium screen

* Fix adding to queue from menu

* Fixes for delete

* PublishList: delay mounting Items tab to prevent lock-up (#1783)

For a large list, the playlist publish form is unusable (super-slow typing) due to the entire list being mounted despite the tab is not active.
The full solution is still to paginate it, but for now, don't mount the tab until it is selected. Add a spinner to indicate something is loading. It's not prefect, but it's throwaway code anyway. At least we can fill in the fields properly now.

* Batch-resolve private collections (#1782)

* makeSelectClaimForClaimId --> selectClaimForClaimId

Move away from the problematic `makeSelect*`, especially in large loops.

* Batch-resolve private collections
1758

This alleviates the lock-up that is caused by large number of invidual resolves. There will still be some minor stutter due to the large DOM that React needs to handle -- that is logged in 1758 and will be handled separately.

At least the stutter is short (1-2s) and the app is still usable.
Private list items are being resolve individually, super slow if the list is large (>100). Published lists doesn't have this issue.
doFetchItemsInCollections contains most of the useful logic, but it isn't called for private/built-in lists because it's not an actual claim.
Tweaked doFetchItemsInCollections to handle private (UUID-based) collections.

* Use persisted state for floating player playlist card body
- I find it annoying being open everytime

* Fix removing edits from published playlist

* Fix scroll on mobile

* Allow going editing items from toast

* Fix ClaimShareButton

* Prevent edit/publish of builtin

* Fix async inside forEach

* Fix sync on queue edit

* Fix autoplayCountdown replay

* Fix deleting an item scrolling the playlist

* CreatedAt fixes

* Remove repost for now

* Anon publish fixes

* Fix mature case on floating

Co-authored-by: infinite-persistence <64950861+infinite-persistence@users.noreply.github.com>
2022-07-13 10:59:59 -03:00

153 lines
6.8 KiB
JavaScript

import { createSelector } from 'reselect';
import { LocalStorage } from 'util/storage';
export const selectState = (state) => state.user || {};
export const selectAuthenticationIsPending = (state) => selectState(state).authenticationIsPending;
export const selectUserIsPending = (state) => selectState(state).userIsPending;
export const selectUser = (state) => selectState(state).user;
export const selectEmailAlreadyExists = (state) => selectState(state).emailAlreadyExists;
export const selectEmailDoesNotExist = (state) => selectState(state).emailDoesNotExist;
export const selectResendingVerificationEmail = (state) => selectState(state).resendingVerificationEmail;
export const selectHomepageFetched = (state) => selectState(state).homepageFetched;
export const selectUserEmail = createSelector(selectUser, (user) =>
user ? user.primary_email || user.latest_claimed_email : null
);
export const selectUserPhone = createSelector(selectUser, (user) => (user ? user.phone_number : null));
export const selectUserCreationDate = (state) => selectUser(state)?.created_at || null;
export const selectUserCountryCode = createSelector(selectUser, (user) => (user ? user.country_code : null));
export const selectEmailToVerify = createSelector(
selectState,
selectUserEmail,
(state, userEmail) => state.emailToVerify || userEmail
);
export const selectPhoneToVerify = createSelector(
selectState,
selectUserPhone,
(state, userPhone) => state.phoneToVerify || userPhone
);
export const selectYoutubeChannels = createSelector(selectUser, (user) => (user ? user.youtube_channels : null));
export const selectUserIsRewardApproved = createSelector(selectUser, (user) => user && user.is_reward_approved);
export const selectEmailNewIsPending = (state) => selectState(state).emailNewIsPending;
export const selectEmailNewErrorMessage = createSelector(selectState, (state) => {
const error = state.emailNewErrorMessage;
return typeof error === 'object' && error !== null ? error.message : error;
});
export const selectPasswordExists = (state) => selectState(state).passwordExistsForUser;
export const selectPasswordResetIsPending = (state) => selectState(state).passwordResetPending;
export const selectPasswordResetSuccess = (state) => selectState(state).passwordResetSuccess;
export const selectPasswordResetError = createSelector(selectState, (state) => {
const error = state.passwordResetError;
return typeof error === 'object' && error !== null ? error.message : error;
});
export const selectPasswordSetIsPending = (state) => selectState(state).passwordSetPending;
export const selectPasswordSetSuccess = (state) => selectState(state).passwordSetSuccess;
export const selectPasswordSetError = createSelector(selectState, (state) => {
const error = state.passwordSetError;
return typeof error === 'object' && error !== null ? error.message : error;
});
export const selectPhoneNewErrorMessage = (state) => selectState(state).phoneNewErrorMessage;
export const selectEmailVerifyIsPending = (state) => selectState(state).emailVerifyIsPending;
export const selectEmailVerifyErrorMessage = (state) => selectState(state).emailVerifyErrorMessage;
export const selectPhoneNewIsPending = (state) => selectState(state).phoneNewIsPending;
export const selectPhoneVerifyIsPending = (state) => selectState(state).phoneVerifyIsPending;
export const selectPhoneVerifyErrorMessage = (state) => selectState(state).phoneVerifyErrorMessage;
export const selectIdentityVerifyIsPending = (state) => selectState(state).identityVerifyIsPending;
export const selectIdentityVerifyErrorMessage = (state) => selectState(state).identityVerifyErrorMessage;
export const selectUserVerifiedEmail = createSelector(selectUser, (user) => user && user.has_verified_email);
export const selectUserIsVerificationCandidate = createSelector(
selectUser,
(user) => user && (!user.has_verified_email || !user.is_identity_verified)
);
export const selectUserInviteStatusIsPending = (state) => selectState(state).inviteStatusIsPending;
export const selectUserInvitesRemaining = (state) => selectState(state).invitesRemaining;
export const selectUserInvitees = (state) => selectState(state).invitees;
export const selectUserInviteStatusFailed = createSelector(
selectUserInvitesRemaining,
() => selectUserInvitesRemaining === null
);
export const selectUserInviteStatusFetched = (state) => {
// A successful fetch produces something; a failed fetch sets it to 'null'.
return selectUserInvitees(state) !== undefined;
};
export const selectUserInviteNewIsPending = (state) => selectState(state).inviteNewIsPending;
export const selectUserInviteNewErrorMessage = (state) => selectState(state).inviteNewErrorMessage;
export const selectUserInviteReferralLink = (state) => selectState(state).referralLink;
/**
* Returns the invitation referral code.
* Clients should use selectUserInviteStatusFetched to check if the info has been fetched.
*/
export const selectUserInviteReferralCode = createSelector(selectState, (state) =>
state.referralCode ? state.referralCode[0] : ''
);
export const selectYouTubeImportPending = (state) => selectState(state).youtubeChannelImportPending;
export const selectYouTubeImportError = (state) => selectState(state).youtubeChannelImportErrorMessage;
export const selectSetReferrerPending = (state) => selectState(state).referrerSetIsPending;
export const selectSetReferrerError = (state) => selectState(state).referrerSetError;
// undefined = not fetched
// '' = no membership
// '<name>' = membership name
export const selectOdyseeMembershipName = (state) => selectState(state).odyseeMembershipName;
/**
* @param state
* @returns {undefined|boolean} 'undefined' if not yet fetched; boolean otherwise.
*/
export const selectOdyseeMembershipIsPremiumPlus = (state) => {
const name = selectOdyseeMembershipName(state);
return name === undefined ? undefined : name === 'Premium+';
};
/**
* @param state
* @returns {undefined|boolean} 'undefined' if not yet fetched; boolean otherwise.
*/
export const selectHasOdyseeMembership = (state) => {
// @if process.env.NODE_ENV!='production'
const override = LocalStorage.getItem('hasMembershipOverride');
if (override) return override === 'true';
// @endif
const name = selectOdyseeMembershipName(state);
return name === undefined ? undefined : Boolean(name);
};
export const selectYouTubeImportVideosComplete = createSelector(selectState, (state) => {
const total = state.youtubeChannelImportTotal;
const complete = state.youtubeChannelImportComplete || 0;
if (total) {
return [complete, total];
}
});
export const makeSelectUserPropForProp = (prop) => createSelector(selectUser, (user) => (user ? user[prop] : null));
export const selectUserLocale = (state) => selectState(state).locale;
export const selectUserCountry = createSelector(selectUserLocale, (locale) => locale?.country);