Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add notifications toggle on details #438

Merged
merged 5 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/routes/MetaDetails/MetaDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ const MetaDetails = ({ urlParams, queryParams }) => {
}
});
}, [metaDetails]);
const toggleNotifications = React.useCallback(() => {
if (metaDetails.libraryItem) {
core.transport.dispatch({
action: 'Ctx',
args: {
action: 'ToggleLibraryItemNotifications',
args: [metaDetails.libraryItem._id, !metaDetails.libraryItem.state.noNotif],
}
});
}
}, [metaDetails.libraryItem]);
const seasonOnSelect = React.useCallback((event) => {
setSeason(event.value);
}, [setSeason]);
Expand Down Expand Up @@ -156,8 +167,10 @@ const MetaDetails = ({ urlParams, queryParams }) => {
<VideosList
className={styles['videos-list']}
metaItem={metaDetails.metaItem}
libraryItem={metaDetails.libraryItem}
season={season}
seasonOnSelect={seasonOnSelect}
toggleNotifications={toggleNotifications}
/>
:
null
Expand Down
1 change: 0 additions & 1 deletion src/routes/MetaDetails/VideosList/SeasonsBar/styles.less
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
display: flex;
flex-direction: row;
justify-content: space-between;
padding: 1rem;
overflow: visible;

.prev-season-button, .next-season-button {
Expand Down
20 changes: 16 additions & 4 deletions src/routes/MetaDetails/VideosList/VideosList.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ const React = require('react');
const PropTypes = require('prop-types');
const classnames = require('classnames');
const { t } = require('i18next');
const Image = require('stremio/common/Image');
const SearchBar = require('stremio/common/SearchBar');
const { Image, SearchBar, Checkbox } = require('stremio/common');
const SeasonsBar = require('./SeasonsBar');
const Video = require('./Video');
const styles = require('./styles');

const VideosList = ({ className, metaItem, season, seasonOnSelect }) => {
const VideosList = ({ className, metaItem, libraryItem, season, seasonOnSelect, toggleNotifications }) => {
const showNotificationsToggle = React.useMemo(() => {
return metaItem?.content?.content?.inLibrary && metaItem?.content?.content?.videos?.length;
}, [metaItem]);
const videos = React.useMemo(() => {
return metaItem && metaItem.content.type === 'Ready' ?
metaItem.content.content.videos
Expand Down Expand Up @@ -80,6 +82,14 @@ const VideosList = ({ className, metaItem, season, seasonOnSelect }) => {
</div>
:
<React.Fragment>
{
showNotificationsToggle && libraryItem ?
<Checkbox className={styles['notifications-checkbox']} checked={!libraryItem.state.noNotif} onClick={toggleNotifications}>
{t('DETAIL_RECEIVE_NOTIF_SERIES')}
</Checkbox>
:
null
}
{
seasons.length > 0 ?
<SeasonsBar
Expand Down Expand Up @@ -133,8 +143,10 @@ const VideosList = ({ className, metaItem, season, seasonOnSelect }) => {
VideosList.propTypes = {
className: PropTypes.string,
metaItem: PropTypes.object,
libraryItem: PropTypes.object,
season: PropTypes.number,
seasonOnSelect: PropTypes.func
seasonOnSelect: PropTypes.func,
toggleNotifications: PropTypes.func,
};

module.exports = VideosList;
14 changes: 14 additions & 0 deletions src/routes/MetaDetails/VideosList/styles.less
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
.videos-list-container {
display: flex;
flex-direction: column;
padding-top: 0.5rem;

.message-container {
flex: 1;
Expand Down Expand Up @@ -35,9 +36,22 @@
}
}

.notifications-checkbox {
flex: none;
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-start;
gap: 1rem;
height: 3rem;
padding: 0 1.5rem;
color: @color-surface-light5-90;
}

.seasons-bar {
flex: none;
align-self: stretch;
margin: 0.5rem 1rem 1rem 1rem;
}

.search-bar {
Expand Down
8 changes: 7 additions & 1 deletion src/types/models/Ctx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@ type Profile = {
type Notifications = {
uid: string,
created: string,
items: Record<string, Video[]>,
items: Record<string, NotificationItem[]>,
};

type NotificationItem = {
metaId: string,
videoId: string,
videoReleased: string,
}

type Ctx = {
profile: Profile,
notifications: Notifications,
Expand Down
1 change: 1 addition & 0 deletions src/types/models/MetaDetails.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type MetaDetails = {
addon: Addon,
content: Loadable<MetaItemMetaDetails>,
} | null,
libraryItem: LibraryItem | null,
selected: {
metaPath: ResourceRequestPath,
streamPath: ResourceRequestPath,
Expand Down