Skip to content

Commit 1b7875f

Browse files
committed
update state view
1 parent 14af5f4 commit 1b7875f

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

src/home/room_screen.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::{
3030
user_profile::{AvatarState, ShowUserProfileAction, UserProfile, UserProfileAndRoomId, UserProfilePaneInfo, UserProfileSlidingPaneRef, UserProfileSlidingPaneWidgetExt},
3131
user_profile_cache,
3232
}, shared::{
33-
avatar::AvatarWidgetRefExt, callout_tooltip::TooltipAction, html_or_plaintext::{HtmlOrPlaintextRef, HtmlOrPlaintextWidgetRefExt, RobrixHtmlLinkAction}, image_viewer_modal::{get_global_image_viewer_modal, load_image_data, show_state, LoadState, IMAGE_LOAD_TIMEOUT}, jump_to_bottom_button::{JumpToBottomButtonWidgetExt, UnreadMessageCount}, popup_list::{enqueue_popup_notification, PopupItem, PopupKind}, restore_status_view::RestoreStatusViewWidgetExt, styles::COLOR_FG_DANGER_RED, text_or_image::{TextOrImageAction, TextOrImageRef, TextOrImageWidgetRefExt}, timestamp::TimestampWidgetRefExt, typing_animation::TypingAnimationWidgetExt
33+
avatar::AvatarWidgetRefExt, callout_tooltip::TooltipAction, html_or_plaintext::{HtmlOrPlaintextRef, HtmlOrPlaintextWidgetRefExt, RobrixHtmlLinkAction}, image_viewer_modal::{get_global_image_viewer_modal, load_image_data, update_state_views, LoadState, IMAGE_LOAD_TIMEOUT}, jump_to_bottom_button::{JumpToBottomButtonWidgetExt, UnreadMessageCount}, popup_list::{enqueue_popup_notification, PopupItem, PopupKind}, restore_status_view::RestoreStatusViewWidgetExt, styles::COLOR_FG_DANGER_RED, text_or_image::{TextOrImageAction, TextOrImageRef, TextOrImageWidgetRefExt}, timestamp::TimestampWidgetRefExt, typing_animation::TypingAnimationWidgetExt
3434
}, sliding_sync::{get_client, submit_async_request, take_timeline_endpoints, BackwardsPaginateUntilEventRequest, MatrixRequest, PaginationDirection, TimelineRequestSender, UserPowerLevels}, utils::{self, room_name_or_id, unix_time_millis_to_datetime, ImageFormat, MEDIA_THUMBNAIL_FORMAT}
3535
};
3636
use crate::home::event_reaction_list::ReactionListWidgetRefExt;
@@ -4447,18 +4447,18 @@ fn populate_image_modal(cx: &mut Cx, timer: &mut Timer, mxc_uri: Option<OwnedMxc
44474447
},
44484448
Err(_) => {
44494449
cx.stop_timer(*timer);
4450-
show_state(cx, view_set, 1);
4450+
update_state_views(cx, view_set, LoadState::Error);
44514451
return LoadState::Error;
44524452
}
44534453
}
44544454
}
44554455
(MediaCacheEntry::Requested, _)
44564456
| (MediaCacheEntry::Loaded(_), MediaFormat::Thumbnail(_)) => {
4457-
show_state(cx, view_set, 0);
4457+
update_state_views(cx, view_set, LoadState::Loading);
44584458
}
44594459
(MediaCacheEntry::Failed, _) => {
44604460
cx.stop_timer(*timer);
4461-
show_state(cx, view_set, 1);
4461+
update_state_views(cx, view_set, LoadState::Error);
44624462
}
44634463
}
44644464
}

src/shared/image_viewer_modal.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -516,18 +516,20 @@ fn round_to_3_decimal_places(dvec2: DVec2) -> DVec2 {
516516
}
517517
}
518518

519-
/// Shows the view at the given state index in the provided view set,
519+
/// Shows the view at the given load state in the provided view set,
520520
/// and hides all other views in the set. The zoomable image is also
521521
/// hidden.
522522
///
523-
/// The ViewSet that contains the loading, error and timeout views.
524-
pub fn show_state(cx: &mut Cx, view_set: ViewSet, state_index: usize) {
523+
/// The ViewSet is in this order: the loading, error and timeout views.
524+
pub fn update_state_views(cx: &mut Cx, view_set: ViewSet, load_state: LoadState) {
525525
for (i, view_ref) in view_set.iter().enumerate() {
526-
if i == state_index {
527-
view_ref.set_visible(cx, true);
528-
} else {
529-
view_ref.set_visible(cx, false);
530-
}
526+
let should_show = match load_state {
527+
LoadState::Loading => i == 0,
528+
LoadState::Error => i == 1,
529+
LoadState::Timeout => i == 2,
530+
LoadState::Loaded => false, // Hide all views when loaded
531+
};
532+
view_ref.set_visible(cx, should_show);
531533
}
532534
}
533535

@@ -549,4 +551,5 @@ pub enum LoadState {
549551
Loading,
550552
Loaded,
551553
Error,
554+
Timeout,
552555
}

src/shared/text_or_image.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
use makepad_widgets::*;
77
use matrix_sdk::ruma::{OwnedMxcUri, OwnedRoomId};
8-
use crate::shared::image_viewer_modal::{get_global_image_viewer_modal, show_state};
8+
use crate::shared::image_viewer_modal::{get_global_image_viewer_modal, update_state_views, LoadState};
99
use crate::home::room_screen::RoomScreenProps;
1010

1111
live_design! {
@@ -79,7 +79,7 @@ impl Widget for TextOrImage {
7979
let image_viewer_modal = get_global_image_viewer_modal(cx);
8080
if let Some(view_set) = image_viewer_modal.get_view_set() {
8181
// Display Loading spinner
82-
show_state(cx, view_set, 0);
82+
update_state_views(cx, view_set, LoadState::Loading);
8383
}
8484
// Get room_id from RoomScreenProps in scope
8585
if let Some(room_props) = scope.props.get::<RoomScreenProps>() {

0 commit comments

Comments
 (0)