Unload handled in Library
@@ -38,8 +38,8 @@ pub struct Selected {
#[derive(Default, Debug, Clone, Serialize)]
pub struct LibraryFiltered {
pub library_state: LibraryState,
- pub selected: Option<Selected>,
pub type_names: Vec<String>,
+ pub selected: Option<Selected>,
pub lib_items: Vec<LibItem>,
}
@@ -66,6 +66,12 @@ impl<Env: Environment + 'static> UpdateWithCtx<Ctx<Env>> for LibraryFiltered {
);
selected_effects.join(lib_items_effects)
}
+ Msg::Action(Action::Unload) => {
+ let selected_effects = selected_update(&mut self.selected, SelectedAction::Clear);
+ let lib_items_effects =
+ lib_items_update(&mut self.lib_items, LibItemsAction::Clear);
+ selected_effects.join(lib_items_effects)
+ }
Msg::Internal(Internal::CtxLoaded(_))
| Msg::Event(Event::CtxChanged)
| Msg::Internal(Internal::LibLoaded(_))
@@ -122,11 +128,37 @@ fn library_state_update(library_state: &mut LibraryState, action: LibraryStateAc
}
}
+enum TypeNamesAction<'a> {
+ LibraryChanged { library: &'a LibraryLoadable },
+}
+
+fn type_names_update(type_names: &mut Vec<String>, action: TypeNamesAction) -> Effects {
+ let next_type_names = match action {
+ TypeNamesAction::LibraryChanged {
+ library: LibraryLoadable::Ready(bucket),
+ } => bucket
+ .items
+ .values()
+ .filter(|lib_item| !lib_item.removed)
+ .map(|lib_item| lib_item.type_name.to_owned())
+ .unique()
+ .collect(),
+ _ => vec![],
+ };
+ if next_type_names.ne(type_names) {
+ *type_names = next_type_names;
+ Effects::none()
+ } else {
+ Effects::none().unchanged()
+ }
+}
+
enum SelectedAction<'a> {
Select {
type_name: &'a String,
sort_prop: &'a Option<String>,
},
+ Clear,
}
fn selected_update(selected: &mut Option<Selected>, action: SelectedAction) -> Effects {
@@ -150,6 +182,7 @@ fn selected_update(selected: &mut Option<Selected>, action: SelectedAction) -> E
sort_prop,
})
}
+ SelectedAction::Clear => None,
};
if next_selected.ne(selected) {
*selected = next_selected;
@@ -159,36 +192,12 @@ fn selected_update(selected: &mut Option<Selected>, action: SelectedAction) -> E
}
}
-enum TypeNamesAction<'a> {
- LibraryChanged { library: &'a LibraryLoadable },
-}
-
-fn type_names_update(type_names: &mut Vec<String>, action: TypeNamesAction) -> Effects {
- let next_type_names = match action {
- TypeNamesAction::LibraryChanged {
- library: LibraryLoadable::Ready(bucket),
- } => bucket
- .items
- .values()
- .filter(|lib_item| !lib_item.removed)
- .map(|lib_item| lib_item.type_name.to_owned())
- .unique()
- .collect(),
- _ => vec![],
- };
- if next_type_names.ne(type_names) {
- *type_names = next_type_names;
- Effects::none()
- } else {
- Effects::none().unchanged()
- }
-}
-
enum LibItemsAction<'a> {
Select {
selected: &'a Option<Selected>,
library: &'a LibraryLoadable,
},
+ Clear,
LibraryChanged {
library: &'a LibraryLoadable,
selected: &'a Option<Selected>,
