lbry-desktop/ui/page/collection/internal/collectionPrivateEdit/view.jsx

151 lines
4.5 KiB
React
Raw Normal View History

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
import React from 'react';
import Button from 'component/button';
import CollectionItemsList from 'component/collectionItemsList';
import Card from 'component/common/card';
import * as MODALS from 'constants/modal_types';
import * as ICONS from 'constants/icons';
import * as COLLECTIONS_CONSTS from 'constants/collections';
import Tooltip from 'component/common/tooltip';
import { Tabs, TabList, Tab, TabPanels, TabPanel } from 'component/common/tabs';
import { useHistory } from 'react-router-dom';
import CollectionGeneralTab from 'component/collectionGeneralTab';
import ErrorText from 'component/common/error-text';
type Props = {
collectionId: string,
// -- redux -
collection: Collection,
collectionUrls: Array<string>,
collectionHasEdits: boolean,
doCollectionEdit: (id: string, params: CollectionEditParams) => void,
doClearEditsForCollectionid: (id: string) => void,
doOpenModal: (id: string, params: {}) => void,
};
function CollectionForm(props: Props) {
const {
collectionId,
// -- redux -
collection,
collectionUrls,
collectionHasEdits,
doCollectionEdit,
doClearEditsForCollectionid,
doOpenModal,
} = props;
const { goBack } = useHistory();
const collectionResetPending = React.useRef(false);
const isBuiltin = COLLECTIONS_CONSTS.BUILTIN_PLAYLISTS.includes(collectionId);
const { name, description, thumbnail } = collection || {};
const initialParams = React.useRef({
uris: collectionUrls,
name,
description,
thumbnail,
});
const [thumbailError, setThumbnailError] = React.useState('');
const [params, setParams] = React.useState(initialParams.current);
function updateParams(newParams) {
// $FlowFixMe
setParams({ ...params, ...newParams });
}
function handleSubmit() {
doCollectionEdit(collectionId, params);
goBack();
}
React.useEffect(() => {
if (collection && collectionResetPending.current) {
setParams({
uris: collectionUrls,
name,
description,
thumbnail,
});
collectionResetPending.current = false;
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [collection]);
return (
<div className="main--contained publishList-wrapper">
<Tabs>
<TabList className="tabs__list--collection-edit-page">
<Tab>{__('General')}</Tab>
<Tab>{__('Items')}</Tab>
</TabList>
<TabPanels>
<TabPanel>
<CollectionGeneralTab
params={params}
setThumbnailError={setThumbnailError}
updateParams={updateParams}
isPrivateEdit
/>
</TabPanel>
<TabPanel>
<CollectionItemsList collectionId={collectionId} empty={__('This playlist has no items.')} showEdit />
</TabPanel>
</TabPanels>
</Tabs>
<Card
className="card--after-tabs"
actions={
<>
<div className="section__actions">
<Button
button="primary"
label={__('Submit')}
disabled={isBuiltin || thumbailError || params === initialParams.current}
onClick={handleSubmit}
/>
<Button button="link" label={__('Cancel')} onClick={goBack} />
</div>
{collectionHasEdits && (
<Tooltip title={__('Delete all edits from this published playlist')}>
<Button
button="close"
icon={ICONS.REFRESH}
label={__('Clear Updates')}
onClick={() =>
doOpenModal(MODALS.CONFIRM, {
title: __('Clear Updates'),
subtitle: __(
"Are you sure you want to delete all edits from this published playlist? (You won't be able to undo this action later)"
),
onConfirm: (closeModal) => {
doClearEditsForCollectionid(collectionId);
collectionResetPending.current = true;
closeModal();
},
})
}
/>
</Tooltip>
)}
{(thumbailError || isBuiltin) && (
<ErrorText>{thumbailError || (isBuiltin && __("Can't edit default playlists."))}</ErrorText>
)}
<p className="help">{__('After submitting, all changes will remain private.')}</p>
</>
}
/>
</div>
);
}
export default CollectionForm;