Skip to main content

max / makenotwork

3.3 KB · 83 lines History Blame Raw
1 //! The Askama entry point for the described publish-at field.
2 //!
3 //! One field, and it is the last site of `data-config` — a private per-app
4 //! attribute vocabulary that existed for exactly one behaviour: a
5 //! `datetime-local` box submits the characters a reader typed, and
6 //! `PUT /api/items/{id}` stores a moment. Something had to convert, and the
7 //! conversion was four lines in `frontend/src/core/dispatch.ts` keyed on an
8 //! attribute only this app understood.
9 //!
10 //! `makeover_layout::Field::as_instant` is the described version of the same
11 //! request: the value is submitted as the moment it names, and how is the
12 //! renderer's, because the browser is the only party that knows what "your
13 //! computer's time zone" means. `quasi-webview` ships the script;
14 //! `makeover-webview` marks the input; this file is the site that asks.
15 //!
16 //! # What is described here and what stays the host's
17 //!
18 //! Described: the kind, the name, the label, the standing hint, that it is
19 //! required, and that the value is submitted as an instant.
20 //!
21 //! Host: the form around it. `item_details.html` keeps the `<form>` with its
22 //! `hx-put` and its `data-after`, the same division `upload_field` makes — the
23 //! wrapper is the app's and the group inside it is the renderer's. Converting
24 //! the whole item-details tab is a screen conversion and not this.
25 //!
26 //! No wire contract moves. The route was already receiving an instant; what
27 //! changed is who computed it.
28
29 use makeover_layout::FieldKind;
30 use quasi_router::{Field, Node};
31
32 /// The publish-at field for an item's schedule form.
33 ///
34 /// The hint is the one the template carried, and it is still true for the same
35 /// reason it was: the reader types a time in their own zone. What is no longer
36 /// true is that nothing said so to the renderer.
37 #[must_use]
38 pub fn publish_at() -> String {
39 use quasi_axum::Serves as _;
40
41 let field = Field::new(FieldKind::DateTime, "publish_at", "Publish at")
42 .required()
43 .hint("Uses your computer's time zone.")
44 .submits_instant();
45
46 // No shell: a fragment landing inside a document Askama already built.
47 quasi_webview::Webview::new().fragment(&Node::field(field))
48 }
49
50 #[cfg(test)]
51 mod tests {
52 /// The assertion the whole change is for. Without the mark the form
53 /// submits `2026-09-01T14:30` and the route stores whatever it makes of
54 /// that, which is the bug `data-config` was patching.
55 #[test]
56 fn the_field_asks_to_be_submitted_as_a_moment() {
57 let html = super::publish_at();
58
59 assert!(html.contains(r#"type="datetime-local""#), "{html}");
60 assert!(html.contains(r#"name="publish_at""#), "{html}");
61 assert!(html.contains(r#"data-instant="true""#), "{html}");
62 assert!(html.contains(" required"), "{html}");
63 }
64
65 /// The private vocabulary does not come back in through the renderer.
66 #[test]
67 fn nothing_here_emits_data_config() {
68 assert!(!super::publish_at().contains("data-config"), "gone");
69 }
70
71 /// The label and the hint are the template's, moved rather than rewritten.
72 #[test]
73 fn the_question_and_its_standing_help_survived_the_move() {
74 let html = super::publish_at();
75
76 assert!(html.contains("Publish at"), "{html}");
77 assert!(
78 html.contains("Uses your computer&#39;s time zone."),
79 "{html}"
80 );
81 }
82 }
83