feat: is_loading use HashSet<Uuid>

each set loading function uses a unique uuid, so that the loading animation will always be played, previously would stop on any remove_loading call
This commit is contained in:
Jack Wills
2022-09-07 14:33:03 +00:00
parent 34275b0220
commit 66583e1b03
4 changed files with 38 additions and 31 deletions
+10 -11
View File
@@ -1,5 +1,6 @@
use std::{collections::HashMap, fmt};
use std::{collections::{HashMap, HashSet}, fmt};
use tui::layout::{Constraint, Rect};
use uuid::Uuid;
use crate::app_data::Header;
@@ -174,9 +175,7 @@ pub struct GuiState {
panel_map: HashMap<SelectablePanel, Rect>,
heading_map: HashMap<Header, Rect>,
loading_icon: Loading,
// Should be a vec, each time loading add a new to the vec, and reset remove from vec
// for for if is_loading just check if vec is empty or not
is_loading: bool,
is_loading: HashSet<Uuid>,
pub selected_panel: SelectablePanel,
pub show_help: bool,
pub info_box_text: Option<String>,
@@ -190,7 +189,7 @@ impl GuiState {
loading_icon: Loading::One,
selected_panel: SelectablePanel::Containers,
show_help: false,
is_loading: false,
is_loading: HashSet::new(),
info_box_text: None,
}
}
@@ -250,14 +249,14 @@ impl GuiState {
}
/// Advance loading animation
pub fn next_loading(&mut self) {
pub fn next_loading(&mut self, uuid: Uuid) {
self.loading_icon = self.loading_icon.next();
self.is_loading = true;
}
self.is_loading.insert(uuid);
}
/// if is_loading, return loading animation frame, else single space
pub fn get_loading(&mut self) -> String {
if self.is_loading {
if !self.is_loading.is_empty() {
self.loading_icon.to_string()
} else {
String::from(" ")
@@ -265,8 +264,8 @@ impl GuiState {
}
/// set is_loading to false, but keep animation frame at same state
pub fn reset_loading(&mut self) {
self.is_loading = false;
pub fn remove_loading(&mut self, uuid: Uuid) {
self.is_loading.remove(&uuid);
}
/// Set info box content