Skip to content

Commit

Permalink
refactor: wrap GetModalResponse in Option for ctx events
Browse files Browse the repository at this point in the history
  • Loading branch information
tymmesyde committed Dec 12, 2023
1 parent 3fd5bfb commit 4d1943a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/models/ctx/update_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn get_modal<E: Env + 'static>() -> Effect {
};

EffectFuture::Concurrent(
fetch_api::<E, _, _, GetModalResponse>(&request)
fetch_api::<E, _, _, Option<GetModalResponse>>(&request)
.map_err(CtxError::from)
.and_then(|result| match result {
APIResult::Ok { result } => future::ok(result),
Expand All @@ -60,7 +60,7 @@ fn get_notification<E: Env + 'static>() -> Effect {
};

EffectFuture::Concurrent(
fetch_api::<E, _, _, GetNotificationResponse>(&request)
fetch_api::<E, _, _, Option<GetNotificationResponse>>(&request)
.map_err(CtxError::from)
.and_then(|result| match result {
APIResult::Ok { result } => future::ok(result),
Expand Down
7 changes: 5 additions & 2 deletions src/runtime/msg/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ pub enum Internal {
/// The result of querying the data for LocalSearch
LoadLocalSearchResult(Url, Result<Vec<Searchable>, EnvError>),
/// Result for getModal request
GetModalResult(APIRequest, Result<GetModalResponse, CtxError>),
GetModalResult(APIRequest, Result<Option<GetModalResponse>, CtxError>),
/// Result for getNotification request
GetNotificationResult(APIRequest, Result<GetNotificationResponse, CtxError>),
GetNotificationResult(
APIRequest,
Result<Option<GetNotificationResponse>, CtxError>,
),
}
4 changes: 2 additions & 2 deletions src/types/events/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ use crate::{

#[derive(Default, PartialEq, Eq, Serialize, Clone, Debug)]
pub struct Events {
pub modal: Loadable<GetModalResponse, CtxError>,
pub notification: Loadable<GetNotificationResponse, CtxError>,
pub modal: Loadable<Option<GetModalResponse>, CtxError>,
pub notification: Loadable<Option<GetNotificationResponse>, CtxError>,
}
8 changes: 4 additions & 4 deletions src/unit_tests/ctx/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,25 @@ fn test_events() {
match request {
Request { url, .. } if url == "https://api.strem.io/api/getModal" => {
future::ok(Box::new(APIResult::Ok {
result: GetModalResponse {
result: Some(GetModalResponse {
id: "id".to_owned(),
title: "title".to_owned(),
message: "message".to_owned(),
image_url: "https://image_url".parse().unwrap(),
addon: None,
external_url: None,
},
}),
}) as Box<dyn Any + Send>)
.boxed_env()
}
Request { url, .. } if url == "https://api.strem.io/api/getNotification" => {
future::ok(Box::new(APIResult::Ok {
result: GetNotificationResponse {
result: Some(GetNotificationResponse {
id: "id".to_owned(),
title: "title".to_owned(),
message: "message".to_owned(),
external_url: None,
},
}),
}) as Box<dyn Any + Send>)
.boxed_env()
}
Expand Down

0 comments on commit 4d1943a

Please sign in to comment.