@@ -4,29 +4,75 @@ use cosmic::iced::alignment::Alignment;
44use cosmic:: widget;
55use linux_pop_extension:: action_icons;
66use linux_pop_extension:: icons;
7- use linux_pop_extension:: { ContainerGroup , ContainerSummary } ;
7+ use linux_pop_extension:: {
8+ ContainerGroup , ContainerSummary , LIST_PAGE_SIZE , clamp_page, page_range, total_pages,
9+ } ;
810
911use super :: layout:: { FILL_PORTION_PROMPT , PAD_GROUP_HEADER , SPACING_NONE , SPACING_SM , SPACING_XXS } ;
1012use super :: widgets:: {
11- action_icon_button, action_svg_button, empty_state, item_labels, list_row, remove_confirm_row ,
12- scrollable_list , section_divider,
13+ action_icon_button, action_svg_button, empty_state, item_labels, list_row, paginated_list ,
14+ remove_confirm_row , section_divider,
1315} ;
1416use super :: { App , Message } ;
1517use crate :: app:: PendingRemove ;
1618
19+ enum ContainerListRow < ' a > {
20+ GroupHeader {
21+ group : & ' a ContainerGroup ,
22+ collapsed : bool ,
23+ } ,
24+ Container {
25+ container : & ' a ContainerSummary ,
26+ } ,
27+ }
28+
1729pub ( super ) fn containers_tab < ' a > ( state : & ' a App ) -> Element < ' a , Message > {
1830 if state. groups . is_empty ( ) && !state. loading && state. error . is_none ( ) {
1931 return empty_state ( "No containers" ) ;
2032 }
2133
34+ let rows = build_container_rows ( state) ;
35+ let total = total_pages ( rows. len ( ) , LIST_PAGE_SIZE ) ;
36+ let page = clamp_page ( state. tab_pages . containers , total) ;
37+ let range = page_range ( page, LIST_PAGE_SIZE , rows. len ( ) ) ;
38+
2239 let mut list = widget:: column![ ] . spacing ( SPACING_NONE ) ;
23- for ( index, group ) in state . groups . iter ( ) . enumerate ( ) {
24- if index > 0 {
40+ for ( index, row ) in rows [ range ] . iter ( ) . enumerate ( ) {
41+ if index > 0 && matches ! ( row , ContainerListRow :: GroupHeader { .. } ) {
2542 list = list. push ( section_divider ( ) ) ;
2643 }
27- list = list. push ( group_section ( state, group) ) ;
44+ match row {
45+ ContainerListRow :: GroupHeader { group, collapsed } => {
46+ list = list. push ( group_header_row (
47+ group,
48+ * collapsed,
49+ group_toolbar ( group, * collapsed) ,
50+ ) ) ;
51+ }
52+ ContainerListRow :: Container { container } => {
53+ list = list. push ( widget:: container ( container_row (
54+ container,
55+ & state. pending_remove ,
56+ ) ) ) ;
57+ }
58+ }
59+ }
60+
61+ paginated_list ( list. into ( ) , page, total)
62+ }
63+
64+ fn build_container_rows < ' a > ( state : & ' a App ) -> Vec < ContainerListRow < ' a > > {
65+ let mut rows = Vec :: new ( ) ;
66+ for group in & state. groups {
67+ let collapsed = state. collapsed_groups . contains ( & group. project ) ;
68+ rows. push ( ContainerListRow :: GroupHeader { group, collapsed } ) ;
69+ if !collapsed {
70+ for container in & group. containers {
71+ rows. push ( ContainerListRow :: Container { container } ) ;
72+ }
73+ }
2874 }
29- scrollable_list ( list . into ( ) )
75+ rows
3076}
3177
3278fn container_state_line ( container : & ContainerSummary ) -> String {
@@ -112,7 +158,7 @@ fn group_toolbar<'a>(group: &'a ContainerGroup, collapsed: bool) -> Element<'a,
112158 actions. into ( )
113159}
114160
115- fn group_header < ' a > (
161+ fn group_header_row < ' a > (
116162 group : & ' a ContainerGroup ,
117163 collapsed : bool ,
118164 toolbar : Element < ' a , Message > ,
@@ -145,19 +191,3 @@ fn group_header<'a>(
145191 . width ( Length :: Fill )
146192 . into ( )
147193}
148-
149- fn group_section < ' a > ( state : & ' a App , group : & ' a ContainerGroup ) -> Element < ' a , Message > {
150- let collapsed = state. collapsed_groups . contains ( & group. project ) ;
151- let header = group_header ( group, collapsed, group_toolbar ( group, collapsed) ) ;
152-
153- let mut section = widget:: column![ header] . spacing ( SPACING_NONE ) ;
154- if !collapsed {
155- for container in & group. containers {
156- section = section. push ( widget:: container ( container_row (
157- container,
158- & state. pending_remove ,
159- ) ) ) ;
160- }
161- }
162- section. into ( )
163- }
0 commit comments