3.1 KiB
3.1 KiB
paths
| paths | ||||||
|---|---|---|---|---|---|---|
|
Frontend rules
Components
- Leptos 0.6 API only. Components are
#[component]functions returningimpl IntoView, one page or dialog per file insrc/pages/; reusable building blocks go tosrc/components/. Register new files in the respectivemod.rs(pub modonly if used fromapp.rs). - This code runs on the server (SSR) and in the browser (hydration). Browser-only APIs (
window(),web_sys) must not run during SSR — keep them in event handlers/effects or behind#[cfg(not(feature = "ssr"))]. Markup must render the same on both sides or hydration breaks. - A new admin page needs a
<Route path="admin/..."/>insrc/app.rswrapped in<AdminPortal>, and a menu entry insrc/components/admin_portal.rs. Paths starting with/adminare login-protected by the middleware; data access is still guarded byperm_check!in the server fn.
Data loading and forms
- Load data with
create_blocking_resource/create_resourcecalling the server fn, rendered inside<Transition fallback=...>with{trl("Loading...")}. Use a dialog'sopener.visible()as the resource source so lists reload after the dialog closes (seesrc/pages/users.rs). - Handle all three outcomes of a server call:
Err(e),Ok(ApiResponse::Error(msg)),Ok(ApiResponse::Data(d)). - Edit/create dialogs:
DialogOpener::new()in the parent,create_server_action::<ServerFnStruct>()in the dialog, wrapped in<DataForm opener=.. action=.. title="..">. It supplies the modal, Save/Close buttons, client validation and server error display. Confirmations use<QuestionDialog>. - Form field names follow the server fn argument:
name="company[name]". Pass the id as a hidden input. Fill inputs withprop:value={move || signal.get().field}. DataForm/ModalDialogtaketitleas an untranslated English key (&'static str); they translate it themselves.
Translations
- Every user-visible string goes through
trl("English text"); never hard-code Czech (or any text) in a view. The English text is the key and the fallback. - When you add or change a key, add the Czech translation to the
csmap insrc/locales/catalogues.rs. This includes validationmessages andApiResponse::Errorstrings from the backend. trl()returns a closure — use it directly as{trl("...")}or attribute value; call it (trl("...")()) when aStringis needed.- Dates shown to users go through
loc_date(), weekday names throughshow_day().
Styling
- UI is the Bootstrap-based admin template in
assets/vendor/plus Boxicons (<i class="bx bx-...">). Reuse its classes (card,table,btn btn-primary,form-control,row/col) before writing CSS. - Custom styles go to
style/main.scss. Never editassets/vendor/. - The public page banner style is
assets/data/banner.css, rewritten at runtime by the appearance upload (/*bg-img*/marker) — keep that marker / thebackground-image: url('...')form intact. - Stylesheets and meta tags are declared in
src/components/header.rs.