2018-03-26 23:32:43 +02:00
|
|
|
import { createSelector } from 'reselect';
|
2022-04-18 04:52:40 +02:00
|
|
|
import { createCachedSelector } from 're-reselect';
|
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 15:59:59 +02:00
|
|
|
import { parseURI, buildURI, parseName } from 'util/lbryURI';
|
|
|
|
import { dedupeLanguages } from 'util/publish';
|
2021-10-17 10:36:14 +02:00
|
|
|
import {
|
|
|
|
selectClaimsById,
|
|
|
|
selectMyClaimsWithoutChannels,
|
|
|
|
selectResolvingUris,
|
|
|
|
selectClaimsByUri,
|
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 15:59:59 +02:00
|
|
|
selectClaimForUri,
|
|
|
|
makeSelectMetadataItemForUri,
|
2021-10-17 10:36:14 +02:00
|
|
|
} from 'redux/selectors/claims';
|
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 15:59:59 +02:00
|
|
|
import { getChannelIdFromClaim, getClaimTitle, getThumbnailFromClaim } from 'util/claim';
|
2022-01-05 15:59:26 +01:00
|
|
|
import { SCHEDULED_LIVESTREAM_TAG } from 'constants/tags';
|
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 15:59:59 +02:00
|
|
|
import { selectCollectionForId, selectClaimIdsForCollectionId } from 'redux/selectors/collections';
|
|
|
|
import { selectActiveChannelClaimId } from 'redux/selectors/app';
|
2018-03-26 23:32:43 +02:00
|
|
|
|
2021-10-17 10:36:14 +02:00
|
|
|
const selectState = (state) => state.publish || {};
|
2018-03-26 23:32:43 +02:00
|
|
|
|
2021-10-17 10:36:14 +02:00
|
|
|
export const selectIsStillEditing = createSelector(selectState, (publishState) => {
|
|
|
|
const { editingURI, uri } = publishState;
|
|
|
|
|
|
|
|
if (!editingURI || !uri) {
|
|
|
|
return false;
|
2019-03-05 05:46:57 +01:00
|
|
|
}
|
2018-03-26 23:32:43 +02:00
|
|
|
|
2021-10-17 10:36:14 +02:00
|
|
|
const { isChannel: currentIsChannel, streamName: currentClaimName, channelName: currentContentName } = parseURI(uri);
|
|
|
|
const { isChannel: editIsChannel, streamName: editClaimName, channelName: editContentName } = parseURI(editingURI);
|
2019-06-28 09:27:55 +02:00
|
|
|
|
2021-10-17 10:36:14 +02: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
|
|
|
|
2021-10-17 10:36:14 +02:00
|
|
|
export const selectPublishFormValues = createSelector(
|
|
|
|
selectState,
|
|
|
|
(state) => state.settings,
|
|
|
|
selectIsStillEditing,
|
|
|
|
(publishState, settingsState, isStillEditing) => {
|
|
|
|
const { languages, ...formValues } = publishState;
|
|
|
|
const language = languages && languages.length && languages[0];
|
|
|
|
const { clientSettings } = settingsState;
|
|
|
|
const { language: languageSet } = clientSettings;
|
2018-08-08 17:33:43 +02:00
|
|
|
|
2021-10-17 10:36:14 +02:00
|
|
|
let actualLanguage;
|
|
|
|
// Sets default if editing a claim with a set language
|
|
|
|
if (!language && isStillEditing && languageSet) {
|
|
|
|
actualLanguage = languageSet;
|
|
|
|
} else {
|
|
|
|
actualLanguage = language || languageSet || 'en';
|
|
|
|
}
|
2018-06-12 09:12:22 +02:00
|
|
|
|
2021-10-17 10:36:14 +02:00
|
|
|
return { ...formValues, language: actualLanguage };
|
2019-03-05 05:46:57 +01:00
|
|
|
}
|
|
|
|
);
|
2018-06-12 07:11:17 +02:00
|
|
|
|
2021-10-17 10:36:14 +02:00
|
|
|
export const makeSelectPublishFormValue = (item) => createSelector(selectState, (state) => state[item]);
|
|
|
|
|
2022-04-18 04:52:40 +02:00
|
|
|
export const selectMyClaimForUri = createCachedSelector(
|
2018-06-12 07:11:17 +02:00
|
|
|
selectPublishFormValues,
|
|
|
|
selectIsStillEditing,
|
|
|
|
selectClaimsById,
|
2018-06-13 05:28:06 +02:00
|
|
|
selectMyClaimsWithoutChannels,
|
2022-04-18 04:52:40 +02:00
|
|
|
(state, caseSensitive) => caseSensitive,
|
|
|
|
({ editingURI, uri }, isStillEditing, claimsById, myClaims, caseSensitive = true) => {
|
|
|
|
let { channelName: contentName, streamName: claimName } = parseURI(uri);
|
2021-10-17 10:36:14 +02:00
|
|
|
const { streamClaimId: editClaimId } = parseURI(editingURI);
|
2018-06-12 07:11:17 +02:00
|
|
|
|
2018-06-13 05:28:06 +02:00
|
|
|
// 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
|
2022-04-18 04:52:40 +02:00
|
|
|
if (isStillEditing) {
|
|
|
|
return claimsById[editClaimId];
|
|
|
|
} else {
|
|
|
|
if (caseSensitive) {
|
|
|
|
return myClaims.find((claim) =>
|
2019-05-07 23:38:29 +02:00
|
|
|
!contentName ? claim.name === claimName : claim.name === contentName || claim.name === claimName
|
2018-06-13 05:28:06 +02:00
|
|
|
);
|
2022-04-18 04:52:40 +02:00
|
|
|
} else {
|
|
|
|
contentName = contentName ? contentName.toLowerCase() : contentName;
|
|
|
|
claimName = claimName ? claimName.toLowerCase() : claimName;
|
|
|
|
|
|
|
|
return myClaims.find((claim) => {
|
|
|
|
const n = claim && claim.name ? claim.name.toLowerCase() : null;
|
|
|
|
return !contentName ? n === claimName : n === contentName || n === claimName;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2018-06-12 07:11:17 +02:00
|
|
|
}
|
2022-04-18 04:52:40 +02:00
|
|
|
)((state, caseSensitive = true) => `selectMyClaimForUri-${caseSensitive ? '1' : '0'}`);
|
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;
|
2021-10-17 10:36:14 +02:00
|
|
|
if (isChannel && name) {
|
|
|
|
const shortUri = buildURI({ streamName: name });
|
2018-09-25 02:17:08 +02:00
|
|
|
isResolvingShortUri = resolvingUris.includes(shortUri);
|
|
|
|
}
|
|
|
|
|
|
|
|
return isResolvingUri || isResolvingShortUri;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
);
|
2021-10-17 10:36:14 +02:00
|
|
|
|
|
|
|
export const selectTakeOverAmount = createSelector(
|
|
|
|
selectState,
|
|
|
|
selectMyClaimForUri,
|
|
|
|
selectClaimsByUri,
|
|
|
|
({ name }, myClaimForUri, claimsByUri) => {
|
|
|
|
if (!name) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We only care about the winning claim for the short uri
|
|
|
|
const shortUri = buildURI({ streamName: name });
|
|
|
|
const claimForShortUri = claimsByUri[shortUri];
|
|
|
|
|
|
|
|
if (!myClaimForUri && claimForShortUri) {
|
|
|
|
return claimForShortUri.meta.effective_amount;
|
|
|
|
} else if (myClaimForUri && claimForShortUri) {
|
|
|
|
// https://github.com/lbryio/lbry/issues/1476
|
|
|
|
// We should check the current effective_amount on my claim to see how much additional lbc
|
|
|
|
// is needed to win the claim. Currently this is not possible during a takeover.
|
|
|
|
// With this, we could say something like, "You have x lbc in support, if you bid y additional LBC you will control the claim"
|
|
|
|
// For now just ignore supports. We will just show the winning claim's bid amount
|
|
|
|
return claimForShortUri.meta.effective_amount || claimForShortUri.amount;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
);
|
Support resume-able upload via tus (#186)
* Publish button: use spinner instead of "Publishing..."
Looks better, plus the preview could take a while sometimes.
* Refactor `doPublish`. No functional change
This is to allow `doPublish` to accept a custom payload as an input (for resuming uploads), instead of always resolving it from the redux data.
* Add doPublishResume
* Support resume-able upload via tus
## Issue
38 Handle resumable file upload
## Notes
Since we can't serialize a File object, we'll need to the user to re-select the file to resume.
* Exclude "modified date" for Firefox/Android
## Issue
It appears that the modification date of the Android file changes when selected, so that file was deemed "different" when trying to resume upload.
## Change
Exclude modification date for now. Let's assume a smart user.
* Move 'currentUploads' to 'publish' reducer
`publish` is currently rehydrated, so we can ride on that and don't need to store the `currentUploads` in `localStorage` for persistence. This would allow us to store Markdown Post data too, as `localStorage` has a 5MB limit per app.
We could have also made `webReducer` rehydrate, but in this repo, there is no need to split it to another reducer. It also makes more sense to be part of publish anyway (at least to me).
This change is mostly moving items between files, with the exception of
1. An additional REHYDRATE in the publish reducer to clean up the tusUploader.
2. Not clearing `currentUploads` in CLEAR_PUBLISH.
* Restore v1 code for livestream replay, etc.
v2 (tus) does not handle `remote_url`, so the app still needs v1 for that. Since we'll still have v1 code, use v1 for previews as well.
2021-11-10 19:16:16 +01:00
|
|
|
|
|
|
|
export const selectCurrentUploads = (state) => selectState(state).currentUploads;
|
|
|
|
|
|
|
|
export const selectUploadCount = createSelector(
|
|
|
|
selectCurrentUploads,
|
|
|
|
(currentUploads) => currentUploads && Object.keys(currentUploads).length
|
|
|
|
);
|
2022-01-05 15:59:26 +01:00
|
|
|
|
|
|
|
export const selectIsScheduled = (state) => selectState(state).tags.some((t) => t.name === SCHEDULED_LIVESTREAM_TAG);
|
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 15:59:59 +02:00
|
|
|
|
|
|
|
// @flow
|
|
|
|
export const selectCollectionClaimParamsForUri = (state: State, uri: string, collectionId: string) => {
|
|
|
|
const claim = selectClaimForUri(state, uri);
|
|
|
|
const collection = selectCollectionForId(state, collectionId);
|
|
|
|
const activeChannelId = selectActiveChannelClaimId(state);
|
|
|
|
|
|
|
|
const { claim_id: claimId, name: collectionName, amount } = claim || collection || {};
|
|
|
|
|
|
|
|
const title = getClaimTitle(claim);
|
|
|
|
const collectionChannelId = getChannelIdFromClaim(claim);
|
|
|
|
const tags = makeSelectMetadataItemForUri(uri, 'tags')(state);
|
|
|
|
const languages = makeSelectMetadataItemForUri(uri, 'languages')(state);
|
|
|
|
const collectionClaimIds = selectClaimIdsForCollectionId(state, collectionId);
|
|
|
|
|
|
|
|
const collectionParams: CollectionPublishParams = {
|
|
|
|
thumbnail_url: getThumbnailFromClaim(claim),
|
|
|
|
name: collectionName ? parseName(collectionName) : undefined,
|
|
|
|
description: makeSelectMetadataItemForUri(uri, 'description')(state),
|
|
|
|
title: claim ? title : collectionName,
|
|
|
|
bid: String(amount || 0.001),
|
|
|
|
languages: languages ? dedupeLanguages(languages) : [],
|
|
|
|
locations: makeSelectMetadataItemForUri(uri, 'locations')(state) || [],
|
|
|
|
tags: tags ? tags.map((tag) => ({ name: tag })) : [],
|
|
|
|
claim_id: claimId,
|
|
|
|
channel_id: claim ? collectionChannelId : activeChannelId || undefined,
|
|
|
|
claims: collectionClaimIds,
|
|
|
|
};
|
|
|
|
|
|
|
|
return collectionParams;
|
|
|
|
};
|