1. Give components one clear responsibility
NewInspection owns an unfinished draft. On success it transfers trimmed values into shared state and clears only its own fields. TreeInspectionCard receives a record and the selected crew as props; it does not invent either. TreeRoundsDashboard composes those boundaries and derives the count.
The IDs are allocated once when a record is created, not every time the view builds. In a service-backed app use the service's durable ID instead. The list key and explicit widget identity then follow that record, rather than its current position.
{"id":"fission-tabs-1","tabs":[{"index":0,"label":"src/state.rs","value":"src-state-rs"},{"index":1,"label":"src/form.rs","value":"src-form-rs"},{"index":2,"label":"src/card.rs","value":"src-card-rs"},{"index":3,"label":"src/app.rs","value":"src-app-rs"},{"index":4,"label":"src/translations.rs","value":"src-translations-rs"},{"index":5,"label":"i18n/en-US.yaml","value":"i18n-en-us-yaml"},{"index":6,"label":"i18n/es-ES.yaml","value":"i18n-es-es-yaml"},{"index":7,"label":"src/lib.rs","value":"src-lib-rs"},{"index":8,"label":"preview/lib.rs","value":"preview-lib-rs"}]}
{"id":"fission-tabs-1","index":0,"label":"src/state.rs","value":"src-state-rs"}
use fission::prelude::*;
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct TreeInspection {
pub id: u64,
pub species: String,
pub location: String,
pub finding: String,
pub crew: Option<String>,
}
#[derive(Debug, Default)]
pub struct TreeRoundsState {
pub inspections: Vec<TreeInspection>,
next_id: u64,
}
impl GlobalState for TreeRoundsState {}
impl TreeRoundsState {
pub fn add(&mut self, species: String, location: String, finding: String) -> bool {
if [species.as_str(), location.as_str(), finding.as_str()]
.iter().any(|value| value.trim().is_empty()) { return false; }
let Some(id) = self.next_id.checked_add(1) else { return false; };
self.next_id = id;
self.inspections.push(TreeInspection {
id, species: species.trim().to_owned(), location: location.trim().to_owned(),
finding: finding.trim().to_owned(), crew: None,
});
true
}
pub fn assign(&mut self, id: u64, crew: String) {
let crew = crew.trim();
if crew.is_empty() { return; }
if let Some(inspection) = self.inspections.iter_mut().find(|value| value.id == id) {
if inspection.crew.is_none() { inspection.crew = Some(crew.to_owned()); }
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn assignment_targets_one_record_and_does_not_invent_completion() {
let mut state = TreeRoundsState::default();
assert!(!state.add("".into(), "Shelter".into(), "Split limb".into()));
assert!(state.add("Plane".into(), "Shelter".into(), "Split limb".into()));
assert!(state.add("Birch".into(), "Gate".into(), "Raised root".into()));
let id = state.inspections[0].id;
state.inspections.reverse();
state.assign(id, "Tree crew".into());
assert_eq!(state.inspections.iter().filter(|value| value.crew.is_some()).count(), 1);
assert_eq!(state.inspections.iter().find(|value| value.id == id).unwrap().crew.as_deref(), Some("Tree crew"));
state.assign(id, "Another crew".into());
assert_eq!(state.inspections.iter().find(|value| value.id == id).unwrap().crew.as_deref(), Some("Tree crew"));
}
}
{"id":"fission-tabs-1","index":1,"label":"src/form.rs","value":"src-form-rs"}
use fission::prelude::*;
use crate::state::TreeRoundsState;
fission_component! {
pub NewInspection<TreeRoundsState> {
state {
species: String = String::new(),
location: String = String::new(),
finding: String = String::new(),
}
}
view(form, state, cx) { let tokens = &cx.view.env().theme.tokens; } =>
Column(gap: tokens.spacing.s, children: [
Text(cx.tr("tree.new")).weight(tokens.typography.font_weight_bold),
TextInput(label: Some(cx.tr("tree.species").into()), bind: form.species,
semantics_identifier: "inspection.species".to_owned()),
TextInput(label: Some(cx.tr("tree.location").into()), bind: form.location,
semantics_identifier: "inspection.location".to_owned()),
TextInput(label: Some(cx.tr("tree.finding").into()), bind: form.finding,
multiline: true, semantics_identifier: "inspection.finding".to_owned()),
Button(
child: Text(cx.tr("tree.add")), key: "inspection.add",
disabled: form.species.trim().is_empty() || form.location.trim().is_empty()
|| form.finding.trim().is_empty(),
on_press: reduce {
if state.add(form.species.clone(), form.location.clone(), form.finding.clone()) {
form.species.clear();
form.location.clear();
form.finding.clear();
}
},
),
])
}
{"id":"fission-tabs-1","index":2,"label":"src/card.rs","value":"src-card-rs"}
use fission::prelude::*;
use crate::state::{TreeInspection, TreeRoundsState};
fission_component! {
pub TreeInspectionCard<TreeRoundsState> {
props { inspection: TreeInspection, selected_crew: String }
}
view(card, state, cx) { let tokens = &cx.view.env().theme.tokens; } =>
SemanticsRegion(
identifier: Some(format!("tree.inspection.{}", card.inspection.id)),
label: Some(format!("{}: {}", cx.tr("tree.inspection"), card.inspection.location)),
child: Container(
Column(gap: tokens.spacing.s, children: [
Text(card.inspection.species.clone()).weight(tokens.typography.font_weight_bold),
Text(card.inspection.location.clone()).color(tokens.colors.text_secondary),
Text(card.inspection.finding.clone()),
if let Some(crew) = &card.inspection.crew {
Text(format!("{}: {crew}", cx.tr("tree.assigned")))
} else {
Button(
child: Text(cx.tr("tree.assign")), key: "inspection.assign",
disabled: card.selected_crew.trim().is_empty(),
on_press: reduce {
state.assign(card.inspection.id, card.selected_crew.clone());
},
)
},
])
).padding_all(tokens.spacing.m).bg(tokens.colors.surface)
.border(tokens.colors.border, 1.0).border_radius(tokens.radii.medium),
)
}
{"id":"fission-tabs-1","index":3,"label":"src/app.rs","value":"src-app-rs"}
use fission::prelude::*;
use crate::{card::TreeInspectionCard, form::NewInspection, state::TreeRoundsState};
fission_component! {
pub TreeRoundsDashboard<TreeRoundsState> {
state { crew: String = String::new() }
}
view(dashboard, state, cx) {
let tokens = &cx.view.env().theme.tokens;
let unassigned = state.inspections.iter().filter(|value| value.crew.is_none()).count();
} =>
SafeArea(child: Scroll(child: Container(
Column(gap: tokens.spacing.l, children: [
Text(cx.tr("tree.title")).size(tokens.typography.heading2_size),
Text(cx.tr("tree.scope")),
NewInspection(),
Divider(),
TextInput(label: Some(cx.tr("tree.crew").into()), bind: dashboard.crew,
helper_text: Some(cx.tr("tree.crew_help").into()),
semantics_identifier: "inspection.crew".to_owned()),
Text(format!("{}: {unassigned}", cx.tr("tree.unassigned"))),
if state.inspections.is_empty() {
Text(cx.tr("tree.empty"))
} else {
Column(gap: tokens.spacing.m, children: [
for inspection in &state.inspections {
TreeInspectionCard(
inspection.clone(), dashboard.crew.clone(), key: inspection.id,
).id(WidgetId::explicit(&format!("tree-card.{}", inspection.id)))
},
])
},
])
).padding_all(tokens.spacing.l)))
}
{"id":"fission-tabs-1","index":4,"label":"src/translations.rs","value":"src-translations-rs"}
use std::collections::HashMap;
use fission::prelude::*;
pub fn create_env() -> Env {
let mut env = Env::default();
env.locale = Locale::from("en-US");
for (locale, source) in [
("en-US", include_str!("../i18n/en-US.yaml")),
("es-ES", include_str!("../i18n/es-ES.yaml")),
] {
let messages: HashMap<String, String> =
serde_yaml::from_str(source).expect("valid checked-in translations");
env.i18n.add_bundle(TranslationBundle { locale: Locale::from(locale), messages });
}
env
}
{"id":"fission-tabs-1","index":5,"label":"i18n/en-US.yaml","value":"i18n-en-us-yaml"}
tree.title: "Tree inspection queue"
tree.new: "Add an inspection"
tree.species: "Tree species"
tree.location: "Location or landmark"
tree.finding: "What needs attention?"
tree.add: "Add inspection"
tree.crew: "Crew to assign"
tree.crew_help: "Enter the crew agreed by dispatch. This app does not verify a roster or notify a crew."
tree.inspection: "Inspection"
tree.assigned: "Assigned crew"
tree.assign: "Assign the selected crew"
tree.unassigned: "Inspections needing a crew"
tree.empty: "No inspections yet. Enter a tree, location and finding above."
tree.scope: "Records and assignments stay in this session only. Assignment is not proof the inspection or work is complete."
{"id":"fission-tabs-1","index":6,"label":"i18n/es-ES.yaml","value":"i18n-es-es-yaml"}
tree.title: "Cola de inspecciones de árboles"
tree.new: "Añadir una inspección"
tree.species: "Especie del árbol"
tree.location: "Ubicación o punto de referencia"
tree.finding: "¿Qué necesita atención?"
tree.add: "Añadir inspección"
tree.crew: "Equipo que se asignará"
tree.crew_help: "Introduce el equipo acordado. Esta aplicación no verifica equipos ni les envía avisos."
tree.inspection: "Inspección"
tree.assigned: "Equipo asignado"
tree.assign: "Asignar el equipo elegido"
tree.unassigned: "Inspecciones sin equipo"
tree.empty: "Aún no hay inspecciones. Introduce árbol, ubicación y observación."
tree.scope: "Los registros y las asignaciones solo duran esta sesión. Asignar no significa completar la inspección o el trabajo."
{"id":"fission-tabs-1","index":7,"label":"src/lib.rs","value":"src-lib-rs"}
pub mod app;
pub mod state;
mod form;
mod card;
mod translations;
use app::TreeRoundsDashboard;
use state::TreeRoundsState;
use fission::prelude::*;
#[cfg(not(any(target_arch = "wasm32", target_os = "android", target_os = "ios")))]
pub fn run_desktop() -> anyhow::Result<()> {
DesktopApp::<TreeRoundsState, _>::new(TreeRoundsDashboard::new())
.with_env(translations::create_env())
.run()
}
#[cfg(any(target_os = "android", target_os = "ios"))]
fn mobile_app() -> MobileApp<TreeRoundsState, TreeRoundsDashboard> {
let app = MobileApp::<TreeRoundsState, _>::new(TreeRoundsDashboard::new())
.with_env(translations::create_env());
#[cfg(all(target_os = "android", debug_assertions))]
let app = app.with_test_control_port(48761);
app
}
#[cfg(any(target_os = "android", target_os = "ios"))]
pub fn run_mobile() -> anyhow::Result<()> { mobile_app().run() }
#[cfg(target_os = "android")]
#[no_mangle]
fn android_main(app_handle: AndroidApp) {
let _ = mobile_app().run_with_android_app(app_handle);
}
#[cfg(target_arch = "wasm32")]
#[wasm_bindgen::prelude::wasm_bindgen(start)]
pub fn run_web() -> Result<(), wasm_bindgen::JsValue> {
console_error_panic_hook::set_once();
WebApp::<TreeRoundsState, _>::new(TreeRoundsDashboard::new())
.with_env(translations::create_env())
.run()
.map_err(|error| wasm_bindgen::JsValue::from_str(&error.to_string()))
}
{"id":"fission-tabs-1","index":8,"label":"preview/lib.rs","value":"preview-lib-rs"}
include!("../src/lib.rs");
{"id":"fission-tabs-1"}
Create two different inspections, enter a crew and assign one card. Its details must remain intact, the other card must remain unassigned and the count must fall by exactly one. The button assigns the crew named in the field; it does not claim to schedule a route, notify people or complete the work.
Show the app previewHide the app preview
Show the app preview
Hide the app preview