2. Keep drafts intact whilst labels and errors change
The enquiry draft is retained local UI state. Preparing a valid subject puts it into shared state for review, but changing language does neither. Error state is represented by attempted and the current validation result, not by an English error string.
The Spanish action is deliberately longer. Let it take the space it needs; shortening every translation to match the English width hides the layout problem rather than solving it.
{"id":"fission-tabs-1","tabs":[{"index":0,"label":"src/enquiry_draft.rs","value":"src-enquiry-draft-rs"},{"index":1,"label":"src/app.rs","value":"src-app-rs"},{"index":2,"label":"src/lib.rs","value":"src-lib-rs"},{"index":3,"label":"preview/lib.rs","value":"preview-lib-rs"}]}
{"id":"fission-tabs-1","index":0,"label":"src/enquiry_draft.rs","value":"src-enquiry-draft-rs"}
use fission::prelude::*;
use crate::state::EnquiryState;
fission_component! {
pub EnquiryDraft<EnquiryState> {
state {
subject: String = String::new(),
attempted: bool = false,
}
}
view(draft, state, cx) {
let tokens = &cx.view.env().theme.tokens;
let invalid = draft.attempted && draft.subject.trim().chars().count() < 5;
} =>
Column(gap: tokens.spacing.m, children: [
TextInput(
label: Some(cx.tr("enquiry.subject").into()),
helper_text: Some(cx.tr("enquiry.subject_help").into()),
error_text: if invalid { Some(cx.tr("enquiry.invalid").into()) } else { None },
validation_message: if invalid { Some(cx.tr("enquiry.invalid")) } else { None },
required: true,
bind: draft.subject,
semantics_identifier: "enquiry.subject".to_string(),
),
Button(
child: Text(cx.tr("enquiry.prepare")),
key: "prepare-enquiry",
on_press: reduce {
draft.attempted = true;
if state.prepare(&draft.subject) { draft.attempted = false; }
},
).semantics_identifier("enquiry.prepare"),
if let Some(subject) = &state.prepared_subject {
Card(child: Column(gap: tokens.spacing.s, children: [
Text(cx.tr("enquiry.prepared")).weight(tokens.typography.font_weight_semibold),
Text(subject.clone()),
Text(cx.tr("enquiry.not_sent")),
]))
} else {
EmptyState(
title: cx.tr("enquiry.empty"),
description: cx.tr("enquiry.empty_help"),
)
},
])
}
{"id":"fission-tabs-1","index":1,"label":"src/app.rs","value":"src-app-rs"}
use fission::prelude::*;
use crate::language_picker::LanguagePicker;
use crate::state::EnquiryState;
use crate::enquiry_draft::EnquiryDraft;
fission_component! {
pub EnquiryApp<EnquiryState> {}
view(_app, _state, cx) {
let tokens = &cx.view.env().theme.tokens;
} =>
SafeArea(
child: Scroll(
child: Container(
child: Column(gap: tokens.spacing.l, children: [
Text(cx.tr("enquiry.title")).size(tokens.typography.heading2_size),
Text(cx.tr("enquiry.context")),
LanguagePicker(),
Divider(),
EnquiryDraft(),
]),
).padding_all(tokens.spacing.l),
),
)
}
{"id":"fission-tabs-1","index":2,"label":"src/lib.rs","value":"src-lib-rs"}
pub mod app;
mod state;
mod language_picker;
mod enquiry_draft;
mod translations;
use app::EnquiryApp;
use state::EnquiryState;
use fission::prelude::*;
#[cfg(not(any(target_arch = "wasm32", target_os = "android", target_os = "ios")))]
pub fn run_desktop() -> anyhow::Result<()> {
DesktopApp::<EnquiryState, _>::new(EnquiryApp)
.with_env(translations::create_env())
.with_sync_env(translations::sync_env)
.run()
}
#[cfg(any(target_os = "android", target_os = "ios"))]
fn mobile_app() -> MobileApp<EnquiryState, EnquiryApp> {
let app = MobileApp::<EnquiryState, _>::new(EnquiryApp)
.with_env(translations::create_env())
.with_sync_env(translations::sync_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::<EnquiryState, _>::new(EnquiryApp)
.with_env(translations::create_env())
.with_sync_env(translations::sync_env)
.run()
.map_err(|error| wasm_bindgen::JsValue::from_str(&error.to_string()))
}
{"id":"fission-tabs-1","index":3,"label":"preview/lib.rs","value":"preview-lib-rs"}
mod app;
mod state;
mod language_picker;
mod enquiry_draft;
mod translations;
use fission::prelude::*;
use wasm_bindgen::prelude::*;
#[wasm_bindgen(start)]
pub fn run() -> Result<(), JsValue> {
console_error_panic_hook::set_once();
WebApp::<state::EnquiryState, _>::new(app::EnquiryApp)
.with_env(translations::create_env())
.with_sync_env(translations::sync_env)
.mount("#fission-web-mount")
.run()
.map_err(|error| JsValue::from_str(&error.to_string()))
}
{"id":"fission-tabs-1"}
Try preparing an empty subject, then switch language whilst the validation error is visible. The error, input label, long action and empty-state guidance should all use the new language. Enter a valid subject and prepare it, then switch again: your text should remain exactly as entered.
The bundle test checks key parity and empty messages. It does not prove that every authored key is correct, that the translation is good, or that a long label fits; those need review and rendered checks.
Show the app previewHide the app preview
Show the app preview
Hide the app preview