lbry-desktop/ui/component/snackBar/view.jsx
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

131 lines
3.6 KiB
JavaScript

// @flow
import * as ICONS from 'constants/icons';
import React from 'react';
import Button from 'component/button';
import classnames from 'classnames';
import Icon from 'component/common/icon';
import LbcMessage from 'component/common/lbc-message';
import I18nMessage from 'component/i18nMessage';
type Props = {
removeSnack: (any) => void,
snack: ?ToastParams,
snackCount: number,
};
type State = {
isHovering: boolean,
};
class SnackBar extends React.PureComponent<Props, State> {
constructor(props: Props) {
super(props);
this.state = { isHovering: false };
this.intervalId = null;
(this: any).handleMouseEnter = this.handleMouseEnter.bind(this);
(this: any).handleMouseLeave = this.handleMouseLeave.bind(this);
}
intervalId: ?IntervalID;
handleMouseEnter() {
this.setState({ isHovering: true });
}
handleMouseLeave() {
this.setState({ isHovering: false });
}
render() {
const { snack, snackCount, removeSnack } = this.props;
const { isHovering } = this.state;
if (!snack) {
clearInterval(this.intervalId);
this.intervalId = null; // should be unmounting anyway, but be safe?
return null;
}
const {
message,
subMessage,
duration,
linkText,
linkTarget,
actionText,
action,
secondaryActionText,
secondaryAction,
isError,
} = snack;
if (this.intervalId) {
// TODO: render should be pure
clearInterval(this.intervalId);
}
if (!isHovering) {
this.intervalId = setInterval(
() => {
removeSnack();
},
duration === 'long' ? 10000 : 5000
);
}
function handleAction(passedAction) {
if (passedAction) passedAction();
removeSnack();
}
return (
<div
className={classnames('snack-bar', {
'snack-bar--error': isError,
'snack-bar--stacked-error': snackCount > 1 && isError,
'snack-bar--stacked-non-error': snackCount > 1 && !isError,
})}
onMouseEnter={this.handleMouseEnter}
onMouseLeave={this.handleMouseLeave}
>
<div className="snack-bar__message">
<Icon icon={isError ? ICONS.ALERT : ICONS.COMPLETED} size={18} />
<p className="snack-bar__messageText">
<LbcMessage>{message}</LbcMessage>
{subMessage && (
<p className="snack-bar__messageText snack-bar__messageText--sub">
<LbcMessage>{subMessage}</LbcMessage>
</p>
)}
</p>
<Button
className="snack-bar__close"
icon={ICONS.REMOVE}
title={__('Dismiss')}
onClick={() => removeSnack()}
/>
</div>
{linkText && linkTarget && (
// This is a little weird because of `linkTarget` code in `lbry-redux`
// Any navigation code should happen in the app, and that should be removed from lbry-redux
<Button navigate={`/$${linkTarget}`} className="snack-bar__action" label={linkText} />
)}
{actionText && action && (
<div className="snack-bar__action">
<I18nMessage
tokens={{
firstAction: <Button onClick={() => handleAction(action)} label={actionText} />,
secondAction: <Button onClick={() => handleAction(secondaryAction)} label={secondaryActionText} />,
}}
>
{secondaryAction ? '%firstAction% / %secondAction%' : '%firstAction%'}
</I18nMessage>
</div>
)}
</div>
);
}
}
export default SnackBar;