A report needs a recognisable problem, a location and enough detail for the technician. The form owns its draft locally. Adding a valid report creates a record in GlobalState and clears the draft; an incomplete report leaves the input intact.
The record ID is allocated once when the record is created. It is not the row position. We use it for the route and the row's retained widget identity, so changing the list cannot attach an old row to a different repair. This in-memory sequence is sufficient for one app run; a shared service would supply its own durable IDs.
{"id":"fission-tabs-1","tabs":[{"index":0,"label":"src/app.rs","value":"src-app-rs"},{"index":1,"label":"src/app/state.rs","value":"src-app-state-rs"},{"index":2,"label":"src/app/new_order.rs","value":"src-app-new-order-rs"},{"index":3,"label":"src/app/card.rs","value":"src-app-card-rs"},{"index":4,"label":"src/app/queue.rs","value":"src-app-queue-rs"},{"index":5,"label":"src/lib.rs","value":"src-lib-rs"},{"index":6,"label":"src/translations.rs","value":"src-translations-rs"},{"index":7,"label":"i18n/en-US.yaml","value":"i18n-en-us-yaml"},{"index":8,"label":"i18n/es-ES.yaml","value":"i18n-es-es-yaml"},{"index":9,"label":"preview/lib.rs","value":"preview-lib-rs"}]}
{"id":"fission-tabs-1","index":0,"label":"src/app.rs","value":"src-app-rs"}
pub mod state;
mod card;
mod new_order;
mod queue;
pub use state::{route_changed, WorkOrderState};
use fission::prelude::*;
fission_component! {
pub WorkOrdersApp<WorkOrderState> {}
view(_app, _state, _cx) =>
queue::WorkOrderQueue
}
{"id":"fission-tabs-1","index":1,"label":"src/app/state.rs","value":"src-app-state-rs"}
use fission::prelude::*;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct WorkOrder {
pub id: u64,
pub title: String,
pub location: String,
pub report: String,
pub resolved: bool,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct WorkOrderState {
pub current_path: String,
pub orders: Vec<WorkOrder>,
next_id: u64,
}
impl Default for WorkOrderState {
fn default() -> Self {
Self { current_path: "/".into(), orders: Vec::new(), next_id: 1 }
}
}
impl GlobalState for WorkOrderState {}
impl WorkOrderState {
pub fn add(&mut self, title: String, location: String, report: String) -> bool {
if title.trim().is_empty() || location.trim().is_empty() || report.trim().is_empty() {
return false;
}
let Some(next_id) = self.next_id.checked_add(1) else { return false };
self.orders.push(WorkOrder {
id: self.next_id,
title: title.trim().to_owned(),
location: location.trim().to_owned(),
report: report.trim().to_owned(),
resolved: false,
});
self.next_id = next_id;
true
}
pub fn resolve(&mut self, id: u64) {
if let Some(order) = self.orders.iter_mut().find(|order| order.id == id) {
order.resolved = true;
}
}
}
pub fn route_changed(
state: &mut WorkOrderState,
action: fission::core::action::ShellRouteChanged,
_cx: &mut ReducerContext<WorkOrderState>,
) {
state.current_path = action.location.pathname;
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn invalid_report_does_not_allocate_an_id() {
let mut state = WorkOrderState::default();
assert!(!state.add("Boiler".into(), "Basement".into(), " ".into()));
assert!(state.add("Boiler".into(), "Basement".into(), "Pressure is dropping".into()));
assert_eq!(state.orders[0].id, 1);
}
#[test]
fn resolving_only_changes_the_matching_record() {
let mut state = WorkOrderState::default();
state.add("Boiler".into(), "Basement".into(), "Pressure is dropping".into());
state.add("Window".into(), "Flat 2A".into(), "Latch will not close".into());
state.resolve(1);
assert!(state.orders[0].resolved);
assert!(!state.orders[1].resolved);
let before = state.clone();
state.resolve(9999);
assert_eq!(state, before);
}
}
{"id":"fission-tabs-1","index":2,"label":"src/app/new_order.rs","value":"src-app-new-order-rs"}
use fission::prelude::*;
use super::state::WorkOrderState;
fission_component! {
pub NewWorkOrder<WorkOrderState> {
state {
title: String = String::new(),
location: String = String::new(),
report: String = String::new(),
invalid: bool = false,
}
}
view(draft, state, cx) {
let tokens = &cx.view.env().theme.tokens;
} =>
Column(gap: tokens.spacing.s, children: [
Text(cx.tr("orders.new")).size(tokens.typography.heading2_size),
TextInput(
label: Some(cx.tr("orders.title").into()),
bind: draft.title,
required: true,
semantics_identifier: "orders.draft.title".to_string(),
),
TextInput(
label: Some(cx.tr("orders.location").into()),
bind: draft.location,
required: true,
semantics_identifier: "orders.draft.location".to_string(),
),
TextInput(
label: Some(cx.tr("orders.report").into()),
bind: draft.report,
required: true,
multiline: true,
semantics_identifier: "orders.draft.report".to_string(),
),
Button(
child: Text(cx.tr("orders.add")),
key: "add-work-order",
on_press: reduce {
if state.add(draft.title.clone(), draft.location.clone(), draft.report.clone()) {
draft.title.clear();
draft.location.clear();
draft.report.clear();
draft.invalid = false;
} else {
draft.invalid = true;
}
},
).semantics_identifier("orders.add"),
if draft.invalid { Text(cx.tr("orders.invalid")).color(tokens.colors.error) },
])
}
{"id":"fission-tabs-1","index":3,"label":"src/app/card.rs","value":"src-app-card-rs"}
use fission::prelude::*;
use super::state::{WorkOrder, WorkOrderState};
fission_component! {
pub WorkOrderCard<WorkOrderState> {
props {
order: WorkOrder,
open_action: Option<ActionEnvelope>,
}
}
view(card, _state, cx) {
let tokens = &cx.view.env().theme.tokens;
} =>
Container(Column(gap: tokens.spacing.s, children: [
Text(format!("#{}", card.order.id)).color(tokens.colors.text_secondary),
Text(card.order.title.clone()).weight(tokens.typography.font_weight_semibold),
Text(card.order.location.clone()),
Text(cx.tr(if card.order.resolved { "orders.resolved" } else { "orders.open" })),
if let Some(action) = card.open_action.clone() {
Button(
child: Text(cx.tr("orders.details")),
key: "open-work-order",
on_press: action,
).semantics_identifier(format!("orders.open.{}", card.order.id))
},
]))
.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":4,"label":"src/app/queue.rs","value":"src-app-queue-rs"}
use fission::prelude::*;
use super::card::WorkOrderCard;
use super::new_order::NewWorkOrder;
use super::state::WorkOrderState;
fission_component! {
pub WorkOrderQueue<WorkOrderState> {}
view(_queue, state, cx) {
let tokens = &cx.view.env().theme.tokens;
let open = state.orders.iter().filter(|order| !order.resolved).count();
} =>
Container(SafeArea(child: Scroll(child:
Container(Column(gap: tokens.spacing.l, children: [
Text(cx.tr("orders.queue")).size(tokens.typography.heading1_size),
Text(cx.tr("orders.open_count").replace("{count}", &open.to_string())),
NewWorkOrder(),
Divider(),
if state.orders.is_empty() {
EmptyState(
title: cx.tr("orders.empty"),
description: Some(cx.tr("orders.empty_help")),
)
} else {
Column(gap: tokens.spacing.s, children: [
for order in &state.orders {
WorkOrderCard(order.clone(), None, key: order.id)
.id(WidgetId::explicit(&format!("work-order.{}", order.id)))
},
])
},
]))
.padding_all(tokens.spacing.l)
.width_length(Length::percent(100.0))
.max_width(760.0),
)))
.height_length(Length::vh(100.0))
}
{"id":"fission-tabs-1","index":5,"label":"src/lib.rs","value":"src-lib-rs"}
pub mod app;
mod translations;
use app::WorkOrdersApp;
use fission::prelude::*;
#[cfg(not(any(target_arch = "wasm32", target_os = "android", target_os = "ios")))]
pub fn run_desktop() -> anyhow::Result<()> {
DesktopApp::<app::WorkOrderState, _>::new(WorkOrdersApp)
.with_env(translations::create_env())
.with_route_handler(app::route_changed)
.run()
}
#[cfg(any(target_os = "android", target_os = "ios"))]
fn mobile_app() -> MobileApp<app::WorkOrderState, WorkOrdersApp> {
let app = MobileApp::<app::WorkOrderState, _>::new(WorkOrdersApp)
.with_env(translations::create_env())
.with_route_handler(app::route_changed);
#[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::<app::WorkOrderState, _>::new(WorkOrdersApp)
.with_env(translations::create_env())
.with_route_handler(app::route_changed)
.run()
.map_err(|error| wasm_bindgen::JsValue::from_str(&error.to_string()))
}
{"id":"fission-tabs-1","index":6,"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":7,"label":"i18n/en-US.yaml","value":"i18n-en-us-yaml"}
orders.queue: "Maintenance work orders"
orders.open_count: "Open repairs: {count}"
orders.new: "Report a repair"
orders.title: "Problem"
orders.location: "Property and location"
orders.report: "What needs attention?"
orders.add: "Add work order"
orders.invalid: "Complete all three fields before adding a work order."
orders.empty: "No repairs reported yet"
orders.empty_help: "Enter a location and a description to create the first work order."
orders.open: "Open"
orders.resolved: "Resolved"
orders.details: "View repair"
orders.back: "Back to work orders"
orders.resolve: "Mark repair resolved"
orders.not_found: "Work order not found"
orders.not_found_help: "The link may be wrong, or this app run does not contain that repair."
{"id":"fission-tabs-1","index":8,"label":"i18n/es-ES.yaml","value":"i18n-es-es-yaml"}
orders.queue: "Órdenes de mantenimiento"
orders.open_count: "Reparaciones abiertas: {count}"
orders.new: "Informar de una reparación"
orders.title: "Problema"
orders.location: "Edificio y ubicación"
orders.report: "¿Qué necesita atención?"
orders.add: "Añadir orden de trabajo"
orders.invalid: "Completa los tres campos antes de añadir una orden."
orders.empty: "Aún no hay reparaciones"
orders.empty_help: "Introduce una ubicación y una descripción para crear la primera orden."
orders.open: "Abierta"
orders.resolved: "Resuelta"
orders.details: "Ver reparación"
orders.back: "Volver a las órdenes"
orders.resolve: "Marcar reparación como resuelta"
orders.not_found: "No se encontró la orden"
orders.not_found_help: "El enlace puede ser incorrecto o esta ejecución no contiene esa reparación."
{"id":"fission-tabs-1","index":9,"label":"preview/lib.rs","value":"preview-lib-rs"}
mod app;
mod translations;
use fission::prelude::*;
use wasm_bindgen::prelude::*;
#[wasm_bindgen(start)]
pub fn run() -> Result<(), JsValue> {
console_error_panic_hook::set_once();
WebApp::<app::WorkOrderState, _>::new(app::WorkOrdersApp)
.with_env(translations::create_env())
.with_navigation(WebNavigationConfig::new(WebRouteStrategy::Hash))
.with_route_handler(app::route_changed)
.mount("#fission-web-mount")
.run()
.map_err(|error| JsValue::from_str(&error.to_string()))
}
{"id":"fission-tabs-1"}