Skip to content

Commit

Permalink
feat: Model Calendar
Browse files Browse the repository at this point in the history
Signed-off-by: Lachezar Lechev <[email protected]>
  • Loading branch information
elpiel committed Jun 13, 2024
1 parent 43c70b2 commit 5bba3a3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 38 deletions.
3 changes: 3 additions & 0 deletions src/model/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
pub mod deep_links_ext;

mod serialize_calendar;
use serialize_calendar::*;

mod serialize_catalogs_with_extra;
use serialize_catalogs_with_extra::*;

Expand Down
25 changes: 10 additions & 15 deletions src/model/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,7 @@ use wasm_bindgen::JsValue;

use stremio_core::{
models::{
addon_details::AddonDetails,
catalog_with_filters::CatalogWithFilters,
catalogs_with_extra::CatalogsWithExtra,
continue_watching_preview::ContinueWatchingPreview,
ctx::Ctx,
data_export::DataExport,
installed_addons_with_filters::InstalledAddonsWithFilters,
library_with_filters::{ContinueWatchingFilter, LibraryWithFilters, NotRemovedFilter},
link::Link,
local_search::LocalSearch,
meta_details::MetaDetails,
player::Player,
streaming_server::StreamingServer,
addon_details::AddonDetails, calendar::Calendar, catalog_with_filters::CatalogWithFilters, catalogs_with_extra::CatalogsWithExtra, continue_watching_preview::ContinueWatchingPreview, ctx::Ctx, data_export::DataExport, installed_addons_with_filters::InstalledAddonsWithFilters, library_with_filters::{ContinueWatchingFilter, LibraryWithFilters, NotRemovedFilter}, link::Link, local_search::LocalSearch, meta_details::MetaDetails, player::Player, streaming_server::StreamingServer
},
runtime::Effects,
types::{
Expand All @@ -40,6 +28,8 @@ use crate::{
},
};

use super::serialize_calendar;

#[derive(Model, Clone)]
#[cfg_attr(debug_assertions, derive(Serialize))]
#[model(WebEnv)]
Expand All @@ -52,6 +42,7 @@ pub struct WebModel {
pub discover: CatalogWithFilters<MetaItemPreview>,
pub library: LibraryWithFilters<NotRemovedFilter>,
pub continue_watching: LibraryWithFilters<ContinueWatchingFilter>,
pub calendar: Calendar,
pub search: CatalogsWithExtra,
/// Pre-loaded results for local search
pub local_search: LocalSearch,
Expand All @@ -69,7 +60,7 @@ impl WebModel {
library: LibraryBucket,
streams: StreamsBucket,
notifications: NotificationsBucket,
calendar: CalendarBucket,
calendar_bucket: CalendarBucket,
search_history: SearchHistoryBucket,
dismissed_events: DismissedEventsBucket,
) -> (WebModel, Effects) {
Expand All @@ -86,13 +77,15 @@ impl WebModel {
InstalledAddonsWithFilters::new(&profile);
let (streaming_server, streaming_server_effects) = StreamingServer::new::<WebEnv>(&profile);
let (local_search, local_search_effects) = LocalSearch::new::<WebEnv>();

let calendar = Calendar::new(calendar_bucket);

let model = WebModel {
ctx: Ctx::new(
profile,
library,
streams,
notifications,
calendar,
search_history,
dismissed_events,
),
Expand All @@ -104,6 +97,7 @@ impl WebModel {
discover,
library: library_,
continue_watching,
calendar,
search: Default::default(),
meta_details: Default::default(),
remote_addons,
Expand Down Expand Up @@ -153,6 +147,7 @@ impl WebModel {
"continuewatching".to_owned(),
),
WebModelField::Search => serialize_catalogs_with_extra(&self.search, &self.ctx),
WebModelField::Calendar => serialize_calendar(&self.calendar),
WebModelField::LocalSearch => serialize_local_search(&self.local_search),
WebModelField::MetaDetails => {
serialize_meta_details(&self.meta_details, &self.ctx, &self.streaming_server)
Expand Down
25 changes: 25 additions & 0 deletions src/model/serialize_calendar.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
pub use model::Calendar;

use gloo_utils::format::JsValueSerdeExt;
use wasm_bindgen::JsValue;

pub fn serialize_calendar(calendar: &stremio_core::models::calendar::Calendar) -> JsValue {
<JsValue as JsValueSerdeExt>::from_serde(&Calendar::from(calendar)).expect("JsValue from Calendar")
}

mod model {
use serde::Serialize;

#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Calendar<'a> {
#[serde(flatten)]
pub calendar: &'a stremio_core::models::calendar::Calendar,
}

impl<'a> From<&'a stremio_core::models::calendar::Calendar> for Calendar<'a> {
fn from(calendar: &'a stremio_core::models::calendar::Calendar) -> Self {
Self { calendar }
}
}
}
23 changes: 0 additions & 23 deletions src/model/serialize_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ mod model {
use serde::Serialize;

use stremio_core::deep_links::SearchHistoryItemDeepLinks;
use stremio_core::types::calendar::CalendarItem;
use stremio_core::types::{
events::Events, notifications::NotificationItem, profile::Profile, resource::MetaItemId,
};
Expand All @@ -27,7 +26,6 @@ mod model {
pub struct Ctx<'a> {
/// keep the original Profile model inside.
pub profile: &'a Profile,
pub calendar: Calendar<'a>,
pub notifications: Notifications<'a>,
pub search_history: Vec<SearchHistoryItem<'a>>,
pub events: &'a Events,
Expand All @@ -42,15 +40,6 @@ mod model {
pub created: DateTime<Utc>,
}

#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Calendar<'a> {
/// Override the notifications to simplify the mapping
pub items: HashMap<MetaItemId, Vec<&'a CalendarItem>>,
pub last_updated: Option<DateTime<Utc>>,
pub created: DateTime<Utc>,
}

#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SearchHistoryItem<'a> {
Expand All @@ -62,18 +51,6 @@ mod model {
fn from(ctx: &'a stremio_core::models::ctx::Ctx) -> Self {
Self {
profile: &ctx.profile,
calendar: Calendar {
items: ctx
.calendar
.items
.iter()
.map(|(meta_id, new_videos)| {
(meta_id.to_owned(), new_videos.values().collect())
})
.collect(),
last_updated: ctx.calendar.last_updated,
created: ctx.calendar.created,
},
notifications: Notifications {
items: ctx
.notifications
Expand Down

0 comments on commit 5bba3a3

Please sign in to comment.