Skip to content

Commit

Permalink
fix: statistics as loadable in 1 of 2 cases:
Browse files Browse the repository at this point in the history
1. it's the first time we are loading the statistics request
2. we have a different request

Signed-off-by: Lachezar Lechev <[email protected]>
  • Loading branch information
elpiel committed Dec 5, 2023
1 parent c74d1c1 commit e1108e7
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/models/streaming_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub struct StreamingServer {
pub base_url: Loadable<Url, EnvError>,
pub playback_devices: Loadable<Vec<PlaybackDevice>, EnvError>,
pub torrent: Option<(String, Loadable<ResourcePath, EnvError>)>,
/// [`Loadable::Loading`] is used only on the first statistics request.
pub statistics: Option<Loadable<Statistics, EnvError>>,
}

Expand Down Expand Up @@ -179,7 +180,14 @@ impl<E: Env + 'static> UpdateWithCtx<E> for StreamingServer {
Msg::Action(Action::StreamingServer(ActionStreamingServer::GetStatistics(request))) => {
let selected_effects =
eq_update(&mut self.selected.statistics, Some(request.to_owned()));
let statistics_effects = eq_update(&mut self.statistics, Some(Loadable::Loading));
let is_different_request = self.selected.statistics.as_ref() != Some(request);
//set the Loading state only on the first fetch of the statistics
let statistics_effects = match (&self.statistics, is_different_request) {
(None, _) | (_, true) => {
eq_update(&mut self.statistics, Some(Loadable::Loading))
}
_ => Effects::none().unchanged(),
};
Effects::one(get_torrent_statistics::<E>(
&self.selected.transport_url,
request,
Expand Down

0 comments on commit e1108e7

Please sign in to comment.