use selected video streams
use super::addons::*;
+use crate::state_types::msg::Internal::*;
use crate::state_types::*;
-use crate::types::addons::{AggrRequest, ResourceRef};
+use crate::types::addons::{AggrRequest, ResourceRef, ResourceRequest};
use crate::types::{MetaDetail, Stream};
use serde_derive::*;
@@ -55,8 +56,49 @@ impl<Env: Environment + 'static> UpdateWithCtx<Ctx<Env>> for MetaDetails {
metas_effects
}
}
- _ => addon_aggr_update(&mut self.metas, msg)
- .join(addon_aggr_update(&mut self.streams, msg)),
+ Msg::Internal(AddonResponse(_, _)) => {
+ let metas_effects = addon_aggr_update(&mut self.metas, msg);
+ let streams_effects: Effects =
+ if let Some((_, Some(streams_resource_ref))) = &self.selected {
+ if let Some((meta_transport_url, streams_from_meta)) = self
+ .metas
+ .iter()
+ .find_map(|metas_group| match &metas_group.content {
+ Loadable::Ready(meta_item) => {
+ meta_item.videos.iter().find_map(|video| {
+ if video.id == streams_resource_ref.id
+ && !video.streams.is_empty()
+ {
+ Some((
+ metas_group.req.base.to_owned(),
+ video.streams.to_owned(),
+ ))
+ } else {
+ None
+ }
+ })
+ }
+ _ => None,
+ })
+ {
+ self.streams = vec![ItemsGroup {
+ req: ResourceRequest {
+ base: meta_transport_url,
+ path: streams_resource_ref.to_owned(),
+ },
+ content: Loadable::Ready(streams_from_meta),
+ }];
+ Effects::none()
+ } else {
+ addon_aggr_update(&mut self.streams, msg)
+ }
+ } else {
+ Effects::none().unchanged()
+ };
+
+ metas_effects.join(streams_effects)
+ }
+ _ => Effects::none().unchanged(),
}
}
}
