Something went wrong. Try again.
forked from evanpurkhiser/things3-cloud
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101use std::sync::Arc;
use iocraft::prelude::*;
use crate::{ common::{ICONS, counted, shown_title}, store::{Area, Task, ThingsStore}, ui::components::{ tags_badge::TagsBadge, tasks::{TaskList, TaskOptions}, },};
const LIST_INDENT: u32 = 2;
#[derive(Default, Props)]pub struct AreaViewProps<'a> { pub area: Option<&'a Area>, pub tasks: Vec<&'a Task>, pub projects: Vec<&'a Task>, pub detailed: bool,}
#[component]pub fn AreaView<'a>(hooks: Hooks, props: &AreaViewProps<'a>) -> impl Into<AnyElement<'a>> { let store = hooks.use_context::<Arc<ThingsStore>>().clone(); let Some(area) = props.area else { return element! { Text(content: "") }.into_any(); };
let project_count = props.projects.len(); let task_count = props.tasks.len();
let mut parts = Vec::new(); if project_count > 0 { parts.push(counted(project_count, "project")); } if task_count > 0 { parts.push(counted(task_count, "task")); } let count_str = if parts.is_empty() { String::new() } else { format!(" ({})", parts.join(", ")) };
let mut item_uuids = props .projects .iter() .map(|p| p.uuid.clone()) .collect::<Vec<_>>(); item_uuids.extend(props.tasks.iter().map(|t| t.uuid.clone())); let id_prefix_len = store.unique_prefix_length(&item_uuids);
// projects and to-dos alike carry the markers of what Today lists let options = TaskOptions { detailed: props.detailed, show_project: false, show_area: false, show_today_markers: true, show_staged_today_marker: false, };
element! { View(flex_direction: FlexDirection::Column) { View(flex_direction: FlexDirection::Row, gap: 1) { Text( content: format!("{} {}{}", ICONS.area, shown_title(&area.title), count_str), wrap: TextWrap::NoWrap, color: Color::Magenta, weight: Weight::Bold, ) TagsBadge(tags: area.tags.clone()) }
#(if !props.tasks.is_empty() { Some(element! { View(flex_direction: FlexDirection::Column) { Text(content: "", wrap: TextWrap::NoWrap) View(flex_direction: FlexDirection::Column, padding_left: LIST_INDENT) { TaskList(items: props.tasks.clone(), id_prefix_len, options) } } }) } else { None })
#(if !props.projects.is_empty() { Some(element! { View(flex_direction: FlexDirection::Column) { Text(content: "", wrap: TextWrap::NoWrap) View(flex_direction: FlexDirection::Column, padding_left: LIST_INDENT) { TaskList(items: props.projects.clone(), id_prefix_len, options) } } }) } else { None }) } } .into_any()}