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

Feature: Mark item as watched in library #639

Merged
merged 15 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 10 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
26 changes: 26 additions & 0 deletions src/models/ctx/update_library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ pub fn update_library<E: Env + 'static>(
}))
.unchanged(),
},
Msg::Action(Action::Ctx(ActionCtx::LibraryItemMarkAsWatched { id, is_watched })) => {
match library.items.get(id) {
Some(library_item) => {
Effects::msg(Msg::Internal(Internal::LibraryItemMarkAsWatched { id: library_item.id.clone(), is_watched: *is_watched }))
.unchanged()
}
_ => Effects::none().unchanged(),

}
},
Msg::Internal(Internal::UpdateLibraryItem(library_item))
if library
.items
Expand Down Expand Up @@ -275,6 +285,22 @@ pub fn update_library<E: Env + 'static>(
}))
.unchanged(),
},
Msg::Internal(Internal::LibraryItemMarkAsWatched { id, is_watched }) => {
match library.items.get(id) {
Some(library_item) => {
let mut library_item = library_item.to_owned();
if *is_watched {
library_item.state.last_watched = Some(E::now());
} else {
library_item.state.times_watched = 0;
}

Effects::msg(Msg::Internal(Internal::UpdateLibraryItem(library_item)))
.unchanged()
}
_ => Effects::none().unchanged(),
}
}
_ => Effects::none().unchanged(),
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/models/meta_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ impl<E: Env + 'static> UpdateWithCtx<E> for MetaDetails {
(last_watched, _) => last_watched.to_owned(),
};
}
Effects::msg(Msg::Internal(Internal::LibraryItemMarkAsWatched {id: video.id.clone(), is_watched: (*is_watched) }))
.unchanged();
Effects::msg(Msg::Internal(Internal::UpdateLibraryItem(library_item)))
.unchanged()
}
Expand Down
1 change: 1 addition & 0 deletions src/runtime/msg/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub enum ActionCtx {
AddToLibrary(MetaItemPreview),
RemoveFromLibrary(String),
RewindLibraryItem(String),
LibraryItemMarkAsWatched{id: LibraryItemId, is_watched: bool},
/// If boolean is set to `true` it will disable notifications for the LibraryItem.
ToggleLibraryItemNotifications(LibraryItemId, bool),
/// Dismiss all Notification for a given [`MetaItemId`].
Expand Down
4 changes: 4 additions & 0 deletions src/runtime/msg/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ pub enum Event {
LibraryItemNotificationsToggled {
id: LibraryItemId,
},
LibraryItemMarkedAsWatched {
id: LibraryItemId,
is_watched: bool,
},
/// The notifications for the given LibraryItemId have been dismissed
NotificationsDismissed {
id: LibraryItemId,
Expand Down
2 changes: 2 additions & 0 deletions src/runtime/msg/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,6 @@ pub enum Internal {
),
/// When dismissed events changed
DismissedEventsChanged,
/// Marks a library item as watched or unwatched. (Overrides the current state)
LibraryItemMarkAsWatched { id: LibraryItemId, is_watched: bool },
}
Loading