Skip to content
This repository has been archived by the owner on Dec 24, 2024. It is now read-only.

Feat/calendar #113

Open
wants to merge 7 commits into
base: development
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.*"
Expand Down
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
17 changes: 14 additions & 3 deletions src/model/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
};
Expand All @@ -39,6 +41,8 @@ use crate::{
},
};

use super::serialize_calendar;

#[derive(Model, Clone)]
#[cfg_attr(debug_assertions, derive(Serialize))]
#[model(WebEnv)]
Expand All @@ -51,6 +55,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 @@ -68,6 +73,7 @@ impl WebModel {
library: LibraryBucket,
streams: StreamsBucket,
notifications: NotificationsBucket,
calendar_bucket: CalendarBucket,
search_history: SearchHistoryBucket,
dismissed_events: DismissedEventsBucket,
) -> (WebModel, Effects) {
Expand All @@ -84,6 +90,9 @@ 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,
Expand All @@ -101,6 +110,7 @@ impl WebModel {
discover,
library: library_,
continue_watching,
calendar,
search: Default::default(),
meta_details: Default::default(),
remote_addons,
Expand Down Expand Up @@ -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)
Expand Down
26 changes: 26 additions & 0 deletions src/model/serialize_calendar.rs
Original file line number Diff line number Diff line change
@@ -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 {
<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 }
}
}
}
17 changes: 11 additions & 6 deletions src/stremio_core_web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};

Expand Down Expand Up @@ -70,6 +70,7 @@ pub async fn initialize_runtime(emit_to_ui: js_sys::Function) -> Result<(), JsVa
WebEnv::get_storage::<LibraryBucket>(LIBRARY_STORAGE_KEY),
WebEnv::get_storage::<StreamsBucket>(STREAMS_STORAGE_KEY),
WebEnv::get_storage::<NotificationsBucket>(NOTIFICATIONS_STORAGE_KEY),
WebEnv::get_storage::<CalendarBucket>(CALENDAR_STORAGE_KEY),
WebEnv::get_storage::<SearchHistoryBucket>(SEARCH_HISTORY_STORAGE_KEY),
WebEnv::get_storage::<DismissedEventsBucket>(DISMISSED_EVENTS_STORAGE_KEY),
);
Expand All @@ -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,
)) => {
Expand All @@ -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::<WebEnv>(profile.uid(), vec![]));
let calendar_bucket = calendar_bucket
.unwrap_or(CalendarBucket::new::<WebEnv>(profile.uid(), vec![]));
let search_history_bucket =
search_history_bucket.unwrap_or(SearchHistoryBucket::new(profile.uid()));
let dismissed_events_bucket = dismissed_events_bucket
Expand All @@ -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,
);
Expand Down
Loading