mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-03-11 21:27:05 +00:00
fix: show new videos counter on library items
This commit is contained in:
parent
8674262195
commit
3551159356
6 changed files with 22 additions and 16 deletions
|
|
@ -3,17 +3,10 @@
|
||||||
const React = require('react');
|
const React = require('react');
|
||||||
const PropTypes = require('prop-types');
|
const PropTypes = require('prop-types');
|
||||||
const { useServices } = require('stremio/services');
|
const { useServices } = require('stremio/services');
|
||||||
const useNotifications = require('stremio/common/useNotifications');
|
|
||||||
const LibItem = require('stremio/common/LibItem');
|
const LibItem = require('stremio/common/LibItem');
|
||||||
|
|
||||||
const ContinueWatchingItem = ({ _id, deepLinks, ...props }) => {
|
const ContinueWatchingItem = ({ _id, notifications, deepLinks, ...props }) => {
|
||||||
const { core } = useServices();
|
const { core } = useServices();
|
||||||
const notifications = useNotifications();
|
|
||||||
|
|
||||||
const newVideos = React.useMemo(() => {
|
|
||||||
const count = notifications.items?.[_id]?.length ?? 0;
|
|
||||||
return Math.min(Math.max(count, 0), 99);
|
|
||||||
}, [_id, notifications.items]);
|
|
||||||
|
|
||||||
const onClick = React.useCallback(() => {
|
const onClick = React.useCallback(() => {
|
||||||
if (deepLinks?.metaDetailsVideos ?? deepLinks?.metaDetailsStreams) {
|
if (deepLinks?.metaDetailsVideos ?? deepLinks?.metaDetailsStreams) {
|
||||||
|
|
@ -51,8 +44,9 @@ const ContinueWatchingItem = ({ _id, deepLinks, ...props }) => {
|
||||||
return (
|
return (
|
||||||
<LibItem
|
<LibItem
|
||||||
{...props}
|
{...props}
|
||||||
|
_id={_id}
|
||||||
posterChangeCursor={true}
|
posterChangeCursor={true}
|
||||||
newVideos={newVideos}
|
notifications={notifications}
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
onPlayClick={onPlayClick}
|
onPlayClick={onPlayClick}
|
||||||
onDismissClick={onDismissClick}
|
onDismissClick={onDismissClick}
|
||||||
|
|
@ -62,6 +56,7 @@ const ContinueWatchingItem = ({ _id, deepLinks, ...props }) => {
|
||||||
|
|
||||||
ContinueWatchingItem.propTypes = {
|
ContinueWatchingItem.propTypes = {
|
||||||
_id: PropTypes.string,
|
_id: PropTypes.string,
|
||||||
|
notifications: PropTypes.object,
|
||||||
deepLinks: PropTypes.shape({
|
deepLinks: PropTypes.shape({
|
||||||
metaDetailsVideos: PropTypes.string,
|
metaDetailsVideos: PropTypes.string,
|
||||||
metaDetailsStreams: PropTypes.string,
|
metaDetailsStreams: PropTypes.string,
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,12 @@ const OPTIONS = [
|
||||||
{ label: 'LIBRARY_REMOVE', value: 'remove' },
|
{ label: 'LIBRARY_REMOVE', value: 'remove' },
|
||||||
];
|
];
|
||||||
|
|
||||||
const LibItem = ({ _id, removable, ...props }) => {
|
const LibItem = ({ _id, removable, notifications, ...props }) => {
|
||||||
const { core } = useServices();
|
const { core } = useServices();
|
||||||
|
const newVideos = React.useMemo(() => {
|
||||||
|
const count = notifications.items?.[_id]?.length ?? 0;
|
||||||
|
return Math.min(Math.max(count, 0), 99);
|
||||||
|
}, [_id, notifications]);
|
||||||
const options = React.useMemo(() => {
|
const options = React.useMemo(() => {
|
||||||
return OPTIONS
|
return OPTIONS
|
||||||
.filter(({ value }) => {
|
.filter(({ value }) => {
|
||||||
|
|
@ -98,6 +102,7 @@ const LibItem = ({ _id, removable, ...props }) => {
|
||||||
return (
|
return (
|
||||||
<MetaItem
|
<MetaItem
|
||||||
{...props}
|
{...props}
|
||||||
|
newVideos={newVideos}
|
||||||
options={options}
|
options={options}
|
||||||
optionOnSelect={optionOnSelect}
|
optionOnSelect={optionOnSelect}
|
||||||
/>
|
/>
|
||||||
|
|
@ -108,6 +113,7 @@ LibItem.propTypes = {
|
||||||
_id: PropTypes.string,
|
_id: PropTypes.string,
|
||||||
removable: PropTypes.bool,
|
removable: PropTypes.bool,
|
||||||
progress: PropTypes.number,
|
progress: PropTypes.number,
|
||||||
|
notifications: PropTypes.object,
|
||||||
deepLinks: PropTypes.shape({
|
deepLinks: PropTypes.shape({
|
||||||
metaDetailsVideos: PropTypes.string,
|
metaDetailsVideos: PropTypes.string,
|
||||||
metaDetailsStreams: PropTypes.string,
|
metaDetailsStreams: PropTypes.string,
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ const MetaItem = React.memo(({ className, type, name, poster, posterShape, poste
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
watched ?
|
!newVideos && watched ?
|
||||||
<div className={styles['watched-icon-layer']}>
|
<div className={styles['watched-icon-layer']}>
|
||||||
<Icon className={styles['watched-icon']} name={'checkmark'} />
|
<Icon className={styles['watched-icon']} name={'checkmark'} />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ const useTranslate = require('stremio/common/useTranslate');
|
||||||
const MetaRowPlaceholder = require('./MetaRowPlaceholder');
|
const MetaRowPlaceholder = require('./MetaRowPlaceholder');
|
||||||
const styles = require('./styles');
|
const styles = require('./styles');
|
||||||
|
|
||||||
const MetaRow = ({ className, title, catalog, message, itemComponent }) => {
|
const MetaRow = ({ className, title, catalog, message, itemComponent, notifications }) => {
|
||||||
const t = useTranslate();
|
const t = useTranslate();
|
||||||
|
|
||||||
const catalogTitle = React.useMemo(() => {
|
const catalogTitle = React.useMemo(() => {
|
||||||
|
|
@ -56,7 +56,8 @@ const MetaRow = ({ className, title, catalog, message, itemComponent }) => {
|
||||||
return React.createElement(itemComponent, {
|
return React.createElement(itemComponent, {
|
||||||
...item,
|
...item,
|
||||||
key: index,
|
key: index,
|
||||||
className: classnames(styles['meta-item'], styles['poster-shape-poster'], styles[`poster-shape-${item.posterShape}`])
|
className: classnames(styles['meta-item'], styles['poster-shape-poster'], styles[`poster-shape-${item.posterShape}`]),
|
||||||
|
notifications,
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
:
|
:
|
||||||
|
|
@ -104,6 +105,7 @@ MetaRow.propTypes = {
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
itemComponent: PropTypes.elementType,
|
itemComponent: PropTypes.elementType,
|
||||||
|
notifications: PropTypes.object,
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = MetaRow;
|
module.exports = MetaRow;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ const React = require('react');
|
||||||
const classnames = require('classnames');
|
const classnames = require('classnames');
|
||||||
const debounce = require('lodash.debounce');
|
const debounce = require('lodash.debounce');
|
||||||
const { useTranslation } = require('react-i18next');
|
const { useTranslation } = require('react-i18next');
|
||||||
const { MainNavBars, MetaRow, ContinueWatchingItem, MetaItem, StreamingServerWarning, useStreamingServer, withCoreSuspender, getVisibleChildrenRange, EventModal } = require('stremio/common');
|
const { MainNavBars, MetaRow, ContinueWatchingItem, MetaItem, StreamingServerWarning, useStreamingServer, useNotifications, withCoreSuspender, getVisibleChildrenRange, EventModal } = require('stremio/common');
|
||||||
const useBoard = require('./useBoard');
|
const useBoard = require('./useBoard');
|
||||||
const useContinueWatchingPreview = require('./useContinueWatchingPreview');
|
const useContinueWatchingPreview = require('./useContinueWatchingPreview');
|
||||||
const styles = require('./styles');
|
const styles = require('./styles');
|
||||||
|
|
@ -16,6 +16,7 @@ const Board = () => {
|
||||||
const streamingServer = useStreamingServer();
|
const streamingServer = useStreamingServer();
|
||||||
const continueWatchingPreview = useContinueWatchingPreview();
|
const continueWatchingPreview = useContinueWatchingPreview();
|
||||||
const [board, loadBoardRows] = useBoard();
|
const [board, loadBoardRows] = useBoard();
|
||||||
|
const notifications = useNotifications();
|
||||||
const boardCatalogsOffset = continueWatchingPreview.items.length > 0 ? 1 : 0;
|
const boardCatalogsOffset = continueWatchingPreview.items.length > 0 ? 1 : 0;
|
||||||
const scrollContainerRef = React.useRef();
|
const scrollContainerRef = React.useRef();
|
||||||
const onVisibleRangeChange = React.useCallback(() => {
|
const onVisibleRangeChange = React.useCallback(() => {
|
||||||
|
|
@ -48,6 +49,7 @@ const Board = () => {
|
||||||
title={t('BOARD_CONTINUE_WATCHING')}
|
title={t('BOARD_CONTINUE_WATCHING')}
|
||||||
catalog={continueWatchingPreview}
|
catalog={continueWatchingPreview}
|
||||||
itemComponent={ContinueWatchingItem}
|
itemComponent={ContinueWatchingItem}
|
||||||
|
notifications={notifications}
|
||||||
/>
|
/>
|
||||||
:
|
:
|
||||||
null
|
null
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ const PropTypes = require('prop-types');
|
||||||
const classnames = require('classnames');
|
const classnames = require('classnames');
|
||||||
const { default: Icon } = require('@stremio/stremio-icons/react');
|
const { default: Icon } = require('@stremio/stremio-icons/react');
|
||||||
const NotFound = require('stremio/routes/NotFound');
|
const NotFound = require('stremio/routes/NotFound');
|
||||||
const { Button, DelayedRenderer, Multiselect, MainNavBars, LibItem, Image, ModalDialog, PaginationInput, useProfile, routesRegexp, useBinaryState, withCoreSuspender } = require('stremio/common');
|
const { Button, DelayedRenderer, Multiselect, MainNavBars, LibItem, Image, ModalDialog, PaginationInput, useProfile, useNotifications, routesRegexp, useBinaryState, withCoreSuspender } = require('stremio/common');
|
||||||
const useLibrary = require('./useLibrary');
|
const useLibrary = require('./useLibrary');
|
||||||
const useSelectableInputs = require('./useSelectableInputs');
|
const useSelectableInputs = require('./useSelectableInputs');
|
||||||
const styles = require('./styles');
|
const styles = require('./styles');
|
||||||
|
|
@ -45,6 +45,7 @@ function withModel(Library) {
|
||||||
|
|
||||||
const Library = ({ model, urlParams, queryParams }) => {
|
const Library = ({ model, urlParams, queryParams }) => {
|
||||||
const profile = useProfile();
|
const profile = useProfile();
|
||||||
|
const notifications = useNotifications();
|
||||||
const library = useLibrary(model, urlParams, queryParams);
|
const library = useLibrary(model, urlParams, queryParams);
|
||||||
const [typeSelect, sortSelect, paginationInput] = useSelectableInputs(library);
|
const [typeSelect, sortSelect, paginationInput] = useSelectableInputs(library);
|
||||||
const [inputsModalOpen, openInputsModal, closeInputsModal] = useBinaryState(false);
|
const [inputsModalOpen, openInputsModal, closeInputsModal] = useBinaryState(false);
|
||||||
|
|
@ -108,7 +109,7 @@ const Library = ({ model, urlParams, queryParams }) => {
|
||||||
:
|
:
|
||||||
<div className={classnames(styles['meta-items-container'], 'animation-fade-in')}>
|
<div className={classnames(styles['meta-items-container'], 'animation-fade-in')}>
|
||||||
{library.catalog.map((libItem, index) => (
|
{library.catalog.map((libItem, index) => (
|
||||||
<LibItem {...libItem} removable={model === 'library'} key={index} />
|
<LibItem {...libItem} notifications={notifications} removable={model === 'library'} key={index} />
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue