summaryrefslogtreecommitdiff
path: root/schist_desktop_gui/src/gui/components
diff options
context:
space:
mode:
Diffstat (limited to 'schist_desktop_gui/src/gui/components')
-rw-r--r--schist_desktop_gui/src/gui/components/buckets_view.rs55
1 files changed, 54 insertions, 1 deletions
diff --git a/schist_desktop_gui/src/gui/components/buckets_view.rs b/schist_desktop_gui/src/gui/components/buckets_view.rs
index b908fb3..8cbaa22 100644
--- a/schist_desktop_gui/src/gui/components/buckets_view.rs
+++ b/schist_desktop_gui/src/gui/components/buckets_view.rs
@@ -3,10 +3,14 @@ use iced::{
widget::{column, row, Container},
Length,
};
+use itertools::Itertools;
use schist_models::Bucket;
use crate::{
- gui::components::{navigation, BucketNavigationEntry, Navigation, Text},
+ gui::components::{
+ navigation::{self, InsertOptionResult},
+ BucketNavigationEntry, Navigation, Text,
+ },
style::SPACING_LG,
traits::{Component, Viewable},
};
@@ -23,6 +27,8 @@ pub enum Message {
SelectNext,
SelectPrev,
SetBuckets(Vec<Bucket>),
+ ExpandGroup(String, Vec<Bucket>),
+ CollapseGroup(String),
}
pub enum Action {
@@ -122,6 +128,53 @@ impl<'a> Component<'a, Message, Action> for BucketsView {
}
navigation::Action::None => Action::None,
},
+
+ Message::ExpandGroup(group, buckets) => {
+ match self.navigation.insert_after_first(
+ |bucket_navigation_entry| {
+ bucket_navigation_entry.is_group_and(|bucket_group_name| {
+ !bucket_group_name.is_open && bucket_group_name.group.eq(group.as_str())
+ })
+ },
+ &buckets
+ .iter()
+ .map(BucketNavigationEntry::from_bucket)
+ .collect(),
+ ) {
+ InsertOptionResult::InsertedOptions => {
+ self.navigation.replace_first(
+ |bucket_navigation_entry| {
+ bucket_navigation_entry.is_group_and(|g| {
+ println!(
+ "{} = {}? {}",
+ g.group,
+ group.as_str(),
+ g.group.eq(group.as_str())
+ );
+ g.group.eq(group.as_str())
+ })
+ },
+ &vec![BucketNavigationEntry::from_group_open(&group)],
+ );
+ Action::None
+ }
+ InsertOptionResult::NoSuchOption => Action::None,
+ }
+ }
+
+ Message::CollapseGroup(group) => {
+ self.navigation
+ .remove_options_where(|bucket_navigation_entry| {
+ bucket_navigation_entry.is_bucket_and(|bucket| bucket.group.eq(&group))
+ });
+ self.navigation.replace_first(
+ |bucket_navigation_entry| {
+ bucket_navigation_entry.is_group_and(|g| g.group.eq(&group))
+ },
+ &vec![BucketNavigationEntry::from_group_closed(&group)],
+ );
+ Action::None
+ }
}
}
}