Skip to main content

things3_cloud/ui/views/
areas.rs

1use iocraft::prelude::*;
2
3use crate::{
4    common::ICONS,
5    store::Area,
6    ui::components::{empty_text::EmptyText, id::Id, tags_badge::TagsBadge},
7};
8
9#[derive(Default, Props)]
10pub struct AreasViewProps {
11    pub areas: Vec<Area>,
12    pub id_prefix_len: usize,
13}
14
15#[component]
16pub fn AreasView<'a>(props: &'a AreasViewProps) -> impl Into<AnyElement<'a>> {
17    if props.areas.is_empty() {
18        return element!(EmptyText(content: "No areas.")).into_any();
19    }
20
21    element! {
22        View(flex_direction: FlexDirection::Column, gap: 1) {
23            Text(
24                content: format!("{} Areas  ({})", ICONS.area, props.areas.len()),
25                color: Color::Magenta,
26                weight: Weight::Bold,
27                wrap: TextWrap::NoWrap,
28            )
29            View(flex_direction: FlexDirection::Column, padding_left: 2) {
30                #(props.areas.iter().map(|area| element! {
31                    View(flex_direction: FlexDirection::Row, gap: 2) {
32                        View(flex_direction: FlexDirection::Row, gap: 1) {
33                            Id(id: &area.uuid, length: props.id_prefix_len)
34                            Text(content: ICONS.area, color: Color::DarkGrey)
35                            Text(content: area.title.clone(), wrap: TextWrap::NoWrap)
36                        }
37                        TagsBadge(tags: area.tags.clone())
38                    }
39                }))
40            }
41        }
42    }
43    .into_any()
44}