Skip to content

Commit

Permalink
feat: add ctx MarkAsWatched action
Browse files Browse the repository at this point in the history
  • Loading branch information
tymmesyde committed Feb 26, 2025
1 parent 64a8bb9 commit 2ffd2cd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/models/ctx/update_library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,25 @@ pub fn update_library<E: Env + 'static>(
}))
.unchanged(),
},
Msg::Action(Action::Ctx(ActionCtx::MarkAsWatched(id, watched))) => {
match library.items.get(id) {
Some(library_item) => {
let mut library_item = library_item.to_owned();
library_item.mark_as_watched::<E>(*watched);

Effects::msg(Msg::Internal(Internal::UpdateLibraryItem(library_item)))
.join(Effects::msg(Msg::Event(
Event::LibraryItemMarkedAsWatched { id: id.to_owned() },
)))
.unchanged()
}
_ => Effects::msg(Msg::Event(Event::Error {
error: CtxError::from(OtherError::LibraryItemNotFound),
source: Box::new(Event::LibraryItemMarkedAsWatched { id: id.to_owned() }),
}))
.unchanged(),
}
}
Msg::Action(Action::Ctx(ActionCtx::ToggleLibraryItemNotifications(id, state))) => {
match library.items.get(id) {
Some(library_item) => {
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 @@ -45,6 +45,7 @@ pub enum ActionCtx {
AddToLibrary(MetaItemPreview),
RemoveFromLibrary(String),
RewindLibraryItem(String),
MarkAsWatched(String, bool),
LibraryItemMarkAsWatched {
id: LibraryItemId,
is_watched: bool,
Expand Down
1 change: 0 additions & 1 deletion src/runtime/msg/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ pub enum Event {
/// The LibraryItem with the given id has been marked as watched or unwatched (Overrides the previous watched state)
LibraryItemMarkedAsWatched {
id: LibraryItemId,
is_watched: bool,
},
/// The notifications for the given LibraryItemId have been dismissed
NotificationsDismissed {
Expand Down

0 comments on commit 2ffd2cd

Please sign in to comment.