diff --git a/Cargo.lock b/Cargo.lock index 2936c40..1fa5181 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1013,7 +1013,7 @@ dependencies = [ [[package]] name = "stremio-core" version = "0.1.0" -source = "git+https://github.com/Stremio/stremio-core?branch=development#7005dbe0d5621418d759e924da42387f1dffe52d" +source = "git+https://github.com/Stremio/stremio-core?branch=feat/calendar#22350f3a9e6fef0e2d487c83e93aa0ea42b47789" dependencies = [ "anyhow", "base64 0.21.7", @@ -1092,7 +1092,7 @@ dependencies = [ [[package]] name = "stremio-derive" version = "0.1.0" -source = "git+https://github.com/Stremio/stremio-core?branch=development#7005dbe0d5621418d759e924da42387f1dffe52d" +source = "git+https://github.com/Stremio/stremio-core?branch=feat/calendar#22350f3a9e6fef0e2d487c83e93aa0ea42b47789" dependencies = [ "case", "proc-macro-crate", @@ -1126,7 +1126,7 @@ dependencies = [ [[package]] name = "stremio-watched-bitfield" version = "0.1.0" -source = "git+https://github.com/Stremio/stremio-core?branch=development#7005dbe0d5621418d759e924da42387f1dffe52d" +source = "git+https://github.com/Stremio/stremio-core?branch=feat/calendar#22350f3a9e6fef0e2d487c83e93aa0ea42b47789" dependencies = [ "base64 0.13.1", "flate2", diff --git a/Cargo.toml b/Cargo.toml index c511938..d7d9942 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ default = [] log-trace = [] [dependencies] -stremio-core = { git = "https://github.com/Stremio/stremio-core", features = ["derive", "analytics"], branch = "development" } +stremio-core = { git = "https://github.com/Stremio/stremio-core", features = ["derive", "analytics"], branch = "feat/calendar" } serde = { version = "1.0.*", features = ["derive"] } serde_json = "1.0.*" futures = "0.3.*" diff --git a/src/model/mod.rs b/src/model/mod.rs index 916c500..baa64aa 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -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::*; diff --git a/src/model/model.rs b/src/model/model.rs index 8037898..7108f83 100644 --- a/src/model/model.rs +++ b/src/model/model.rs @@ -7,6 +7,7 @@ use wasm_bindgen::JsValue; use stremio_core::{ models::{ addon_details::AddonDetails, + calendar::Calendar, catalog_with_filters::CatalogWithFilters, catalogs_with_extra::CatalogsWithExtra, continue_watching_preview::ContinueWatchingPreview, @@ -22,9 +23,10 @@ use stremio_core::{ }, runtime::Effects, types::{ - addon::DescriptorPreview, api::LinkAuthKey, events::DismissedEventsBucket, - library::LibraryBucket, notifications::NotificationsBucket, profile::Profile, - resource::MetaItemPreview, search_history::SearchHistoryBucket, streams::StreamsBucket, + addon::DescriptorPreview, api::LinkAuthKey, calendar::CalendarBucket, + events::DismissedEventsBucket, library::LibraryBucket, notifications::NotificationsBucket, + profile::Profile, resource::MetaItemPreview, search_history::SearchHistoryBucket, + streams::StreamsBucket, }, Model, }; @@ -39,6 +41,8 @@ use crate::{ }, }; +use super::serialize_calendar; + #[derive(Model, Clone)] #[cfg_attr(debug_assertions, derive(Serialize))] #[model(WebEnv)] @@ -51,6 +55,7 @@ pub struct WebModel { pub discover: CatalogWithFilters, pub library: LibraryWithFilters, pub continue_watching: LibraryWithFilters, + pub calendar: Calendar, pub search: CatalogsWithExtra, /// Pre-loaded results for local search pub local_search: LocalSearch, @@ -68,6 +73,7 @@ impl WebModel { library: LibraryBucket, streams: StreamsBucket, notifications: NotificationsBucket, + calendar_bucket: CalendarBucket, search_history: SearchHistoryBucket, dismissed_events: DismissedEventsBucket, ) -> (WebModel, Effects) { @@ -84,6 +90,9 @@ impl WebModel { InstalledAddonsWithFilters::new(&profile); let (streaming_server, streaming_server_effects) = StreamingServer::new::(&profile); let (local_search, local_search_effects) = LocalSearch::new::(); + + let calendar = Calendar::new(calendar_bucket); + let model = WebModel { ctx: Ctx::new( profile, @@ -101,6 +110,7 @@ impl WebModel { discover, library: library_, continue_watching, + calendar, search: Default::default(), meta_details: Default::default(), remote_addons, @@ -150,6 +160,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) diff --git a/src/model/serialize_calendar.rs b/src/model/serialize_calendar.rs new file mode 100644 index 0000000..3dba114 --- /dev/null +++ b/src/model/serialize_calendar.rs @@ -0,0 +1,26 @@ +pub use model::Calendar; + +use gloo_utils::format::JsValueSerdeExt; +use wasm_bindgen::JsValue; + +pub fn serialize_calendar(calendar: &stremio_core::models::calendar::Calendar) -> JsValue { + ::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 } + } + } +} diff --git a/src/stremio_core_web.rs b/src/stremio_core_web.rs index 1688a8e..b2de008 100644 --- a/src/stremio_core_web.rs +++ b/src/stremio_core_web.rs @@ -10,16 +10,16 @@ use wasm_bindgen::{prelude::wasm_bindgen, JsValue}; use stremio_core::{ constants::{ - DISMISSED_EVENTS_STORAGE_KEY, LIBRARY_RECENT_STORAGE_KEY, LIBRARY_STORAGE_KEY, - NOTIFICATIONS_STORAGE_KEY, PROFILE_STORAGE_KEY, SEARCH_HISTORY_STORAGE_KEY, - STREAMS_STORAGE_KEY, + CALENDAR_STORAGE_KEY, DISMISSED_EVENTS_STORAGE_KEY, LIBRARY_RECENT_STORAGE_KEY, + LIBRARY_STORAGE_KEY, NOTIFICATIONS_STORAGE_KEY, PROFILE_STORAGE_KEY, + SEARCH_HISTORY_STORAGE_KEY, STREAMS_STORAGE_KEY, }, models::common::Loadable, runtime::{msg::Action, Env, EnvError, Runtime, RuntimeAction, RuntimeEvent}, types::{ - events::DismissedEventsBucket, library::LibraryBucket, notifications::NotificationsBucket, - profile::Profile, resource::Stream, search_history::SearchHistoryBucket, - streams::StreamsBucket, + calendar::CalendarBucket, events::DismissedEventsBucket, library::LibraryBucket, + notifications::NotificationsBucket, profile::Profile, resource::Stream, + search_history::SearchHistoryBucket, streams::StreamsBucket, }, }; @@ -70,6 +70,7 @@ pub async fn initialize_runtime(emit_to_ui: js_sys::Function) -> Result<(), JsVa WebEnv::get_storage::(LIBRARY_STORAGE_KEY), WebEnv::get_storage::(STREAMS_STORAGE_KEY), WebEnv::get_storage::(NOTIFICATIONS_STORAGE_KEY), + WebEnv::get_storage::(CALENDAR_STORAGE_KEY), WebEnv::get_storage::(SEARCH_HISTORY_STORAGE_KEY), WebEnv::get_storage::(DISMISSED_EVENTS_STORAGE_KEY), ); @@ -80,6 +81,7 @@ pub async fn initialize_runtime(emit_to_ui: js_sys::Function) -> Result<(), JsVa other_bucket, streams_bucket, notifications_bucket, + calendar_bucket, search_history_bucket, dismissed_events_bucket, )) => { @@ -95,6 +97,8 @@ pub async fn initialize_runtime(emit_to_ui: js_sys::Function) -> Result<(), JsVa streams_bucket.unwrap_or_else(|| StreamsBucket::new(profile.uid())); let notifications_bucket = notifications_bucket .unwrap_or(NotificationsBucket::new::(profile.uid(), vec![])); + let calendar_bucket = calendar_bucket + .unwrap_or(CalendarBucket::new::(profile.uid(), vec![])); let search_history_bucket = search_history_bucket.unwrap_or(SearchHistoryBucket::new(profile.uid())); let dismissed_events_bucket = dismissed_events_bucket @@ -104,6 +108,7 @@ pub async fn initialize_runtime(emit_to_ui: js_sys::Function) -> Result<(), JsVa library, streams_bucket, notifications_bucket, + calendar_bucket, search_history_bucket, dismissed_events_bucket, );