diff --git a/crates/izlek-web/src/board.rs b/crates/izlek-web/src/board.rs index 014d947..13f1681 100644 --- a/crates/izlek-web/src/board.rs +++ b/crates/izlek-web/src/board.rs @@ -81,7 +81,8 @@ async fn create_task_shared( column_id: &str, description: &str, deadline_raw: &str, - time_raw: &str, + clock_hour: Option<&str>, + clock_minute: Option<&str>, ) -> Result> { let user = match require_writer(cx).await { @@ -93,10 +94,14 @@ async fn create_task_shared( return Ok(Some(Refusal::EmptyTitle)); } let zone = izlek_core::detail::parse_zone(&user.timezone); + let time = match crate::detail::combine_clock(clock_hour, clock_minute) { + Ok(time) => time, + Err(refusal) => return Ok(Some(refusal)), + }; let (deadline, clock_at) = match crate::detail::moment_field( Some(deadline_raw), (None, None), - Some(time_raw), + time.as_deref(), zone, ) { Ok(pair) => pair, @@ -161,7 +166,9 @@ struct CreateTaskForm { #[serde(default)] deadline: String, #[serde(default)] - clock_time: String, + clock_hour: Option, + #[serde(default)] + clock_minute: Option, } /// A browser without script's way onto the board: a real form post, same @@ -174,7 +181,8 @@ async fn create_task(cx: &Cx, Form(input): Form) -> Redirect { &input.column_id, &input.description, &input.deadline, - &input.clock_time, + input.clock_hour.as_deref(), + input.clock_minute.as_deref(), ) .await? { diff --git a/crates/izlek-web/src/detail.rs b/crates/izlek-web/src/detail.rs index b739da5..58aa989 100644 --- a/crates/izlek-web/src/detail.rs +++ b/crates/izlek-web/src/detail.rs @@ -236,7 +236,9 @@ struct SaveTaskForm { #[serde(default)] deadline: Option, #[serde(default)] - clock_time: Option, + clock_hour: Option, + #[serde(default)] + clock_minute: Option, } #[derive(Deserialize)] @@ -542,11 +544,23 @@ fn parse_hhmm(raw: &str) -> Option<(u8, u8)> { (hour <= 23 && minute <= 59).then_some((hour, minute)) } -/// The moment field's menu words: every five minutes of the day, -/// zero-padded, the value and the label the same word — the logs filters' -/// shape, at 288 options a `data-search` box is what makes it usable. -fn clock_steps() -> impl Iterator { - (0..24 * 12).map(|step| format!("{:02}:{:02}", step / 12, (step % 12) * 5)) +/// The posted hour and minute words as one `HH:MM` for [`moment_field`], +/// which stays the one validator of the shape. Both absent: the form said +/// nothing about the time. Both empty: the popover's Clear, clearing the +/// clock. Both set: the moment, however the hands typed it. One without +/// the other is a form gone wrong, not something to guess past. +pub(crate) fn combine_clock( + hour: Option<&str>, + minute: Option<&str>, +) -> std::result::Result, Refusal> { + match (hour, minute) { + (None, None) => Ok(None), + (Some(""), Some("")) => Ok(Some(String::new())), + (Some(hour), Some(minute)) => { + Ok(Some(format!("{}:{}", hour.trim(), minute.trim()))) + } + _ => Err(Refusal::BadClock), + } } /// Saves the title, the description and the moment field — the deadline day @@ -576,10 +590,14 @@ async fn save_task(cx: &Cx, Form(input): Form) -> Redirect { None => facts.description.clone(), }; let zone = parse_zone(&user.timezone); + let time = match combine_clock(input.clock_hour.as_deref(), input.clock_minute.as_deref()) { + Ok(time) => time, + Err(refusal) => return redirect(cx, Some(refusal)), + }; let (deadline, clock_at) = match moment_field( input.deadline.as_deref(), (facts.row.deadline, facts.row.clock_at), - input.clock_time.as_deref(), + time.as_deref(), zone, ) { Ok(pair) => pair, @@ -1274,7 +1292,7 @@ async fn deadline_control( may_write: bool, lang: Lang, ) -> Result { - use time::macros::format_description; + let overdue = task.is_overdue(today); let local = task.clock_at.map(|at| at.to_offset(zone)); @@ -1312,17 +1330,12 @@ async fn deadline_control( } let toggle = format!("deadline-{}", task.id); let input_value = task.deadline_input(); - let time_selected = local - .map(|at| at.format(&format_description!("[hour]:[minute]"))) - .transpose() + let hour_value = local + .map(|at| format!("{:02}", at.hour())) + .unwrap_or_default(); + let minute_value = local + .map(|at| format!("{:02}", at.minute())) .unwrap_or_default(); - let steps: Vec = clock_steps().collect(); - // A clock off the five-minute grid is still the truth that is stored: - // its exact option is appended, never rounded onto a step. - let time_exact = time_selected - .as_ref() - .filter(|value| !steps.iter().any(|step| step == *value)) - .cloned(); let change_aria = t(lang, Key::ChangeTheDeadline); let no_deadline = t(lang, Key::NoDeadline); view! { @@ -1338,15 +1351,11 @@ async fn deadline_control(
(datepicker_grid(cx, "deadline", &input_value, true, lang).await?) - +
+ + (":") + +
(refused(cx, "save_task", lang).await?) @@ -1432,7 +1441,7 @@ pub(crate) async fn datepicker_script(cx: &Cx, lang: Lang) -> Result { var input = panel.querySelector('.datepick-input');\ if (!input) {{ return; }}\ input.value = ymd ? (ymd.y + '-' + pad(ymd.m) + '-' + pad(ymd.d)) : '';\ - if (!ymd) {{ var clock = panel.querySelector('[name=clock_time]'); if (clock) {{ clock.value = ''; }} }}\ + if (!ymd) {{ var hh = panel.querySelector('[name=clock_hour]'); if (hh) {{ hh.value = ''; }} var mm = panel.querySelector('[name=clock_minute]'); if (mm) {{ mm.value = ''; }} }}\ var pop = panel.closest('.datepick-pop');\ var label = pop.querySelector('.datepick-label');\ if (label) {{ label.textContent = ymd ? (MONTHS[ymd.m - 1].slice(0, 3) + ' ' + pad(ymd.d)) : label.dataset.empty; }}\ @@ -2570,7 +2579,6 @@ async fn sheet_view( /// as [`task_modal`], with a form posting straight to `/api/create_task`. /// Wired off the board top bar's "New task" button as `/?new=1`. pub async fn new_task_modal(cx: &Cx, columns: &[(String, String)], lang: Lang) -> Result { - let steps: Vec = clock_steps().collect(); view! { cx => diff --git a/crates/izlek-web/src/i18n.rs b/crates/izlek-web/src/i18n.rs index 6f886b1..bd91ce3 100644 --- a/crates/izlek-web/src/i18n.rs +++ b/crates/izlek-web/src/i18n.rs @@ -358,7 +358,8 @@ pub enum Key { InvitedByLabel, MailBatchLabel, ReminderMinutesLabel, - ClockTime, + ClockHour, + ClockMinute, } /// The lone templated phrase — a name in the middle reads worse as two @@ -1019,8 +1020,10 @@ pub fn t(lang: Lang, key: Key) -> &'static str { (MailBatchLabel, Tr) => "Posta gecikmesi (dakika)", (ReminderMinutesLabel, En) => "Reminder (minutes)", (ReminderMinutesLabel, Tr) => "Hatırlatma (dakika)", - (ClockTime, En) => "Time", - (ClockTime, Tr) => "Saat", + (ClockHour, En) => "Hour", + (ClockHour, Tr) => "Saat", + (ClockMinute, En) => "Minute", + (ClockMinute, Tr) => "Dakika", } } diff --git a/crates/izlek-web/tests/browser/moment.mjs b/crates/izlek-web/tests/browser/moment.mjs index f6e8bd5..7f83c10 100644 --- a/crates/izlek-web/tests/browser/moment.mjs +++ b/crates/izlek-web/tests/browser/moment.mjs @@ -99,34 +99,11 @@ const chipLabel = `${MONTHS[picked.month - 1]} ${pad(picked.day)} · 16:20`; const fieldLabel = `${MONTHS[picked.month - 1]} ${pad(picked.day)} 16:20`; -// The time rides the same panel as a house dropdown: the select is -// enhanced into a trigger and a panel, so a hand on it clicks the trigger, -// types to filter, and presses the row — which also exercises the search -// box the data-search attribute buys. The dd pick writes the select's -// value; the modal select carries no data-autosubmit, so nothing posts -// until the form's own button. -await page.click( - '.modal-new-task select[name="clock_time"] >> xpath=preceding-sibling::button[1]', -); -const menu = page.locator('.dd-panel.dd-open'); -await menu.locator('.dd-search').fill('16:'); -const filtered = await menu.locator('.dd-search').evaluate((el) => { - const panel = el.closest('.dd-panel'); - const row = panel.querySelector('.dd-option[data-value="16:20"]'); - return { - search: el.value, - rows: panel.querySelectorAll('.dd-option').length, - hidden: panel.querySelectorAll('.dd-option-hidden').length, - rowOn: !!row && !row.classList.contains('dd-option-hidden'), - }; -}); -if (filtered.search !== '16:') failures.push(`the search box read '${filtered.search}'`); -if (filtered.rows !== 289) failures.push(`the menu holds ${filtered.rows} rows, not 289`); -if (!filtered.rowOn) failures.push("typing '16:' did not leave the 16:20 row on the menu"); -// Press the row through its own handler. The panel's scroll-close race can -// make a point-and-click flake here; the handler is the house code either -// way, and the value it writes is asserted below. -await menu.locator('.dd-option[data-value="16:20"]').evaluate((el) => el.click()); +// The time rides the same panel as two two-digit boxes — hour, colon, +// minute — typed before the day press, so the one form post carries both. +// Neither box autosubmits: a lone box is half a value. +await page.fill('.modal-new-task input[name="clock_hour"]', '16'); +await page.fill('.modal-new-task input[name="clock_minute"]', '20'); // Then the day press, whose pick() writes the hidden input in place — in // the modal nothing autosubmits, so the value is read in the same tick as @@ -145,7 +122,7 @@ if (!/^\d{4}-\d{2}-\d{2}$/.test(written.after)) { failures.push(`the day pick never wrote the hidden input: '${written.after}'`); } const atSubmit = await page.evaluate(() => ({ - time: document.querySelector('.modal-new-task select[name="clock_time"]')?.value, + time: `${document.querySelector('.modal-new-task input[name="clock_hour"]')?.value}:${document.querySelector('.modal-new-task input[name="clock_minute"]')?.value}`, day: document.querySelector('.modal-new-task .datepick-input')?.value, })); if (atSubmit.time !== '16:20') failures.push(`the time box read '${atSubmit.time}' at submit`); diff --git a/crates/izlek-web/tests/browser/run.sh b/crates/izlek-web/tests/browser/run.sh index be0c056..1b4507a 100755 --- a/crates/izlek-web/tests/browser/run.sh +++ b/crates/izlek-web/tests/browser/run.sh @@ -39,7 +39,11 @@ if [[ ! -f $IZLEK_PLAYWRIGHT ]]; then (cd "$home" && npx playwright install --only-shell chromium) fi -cargo build --manifest-path "$repo/Cargo.toml" -p izlek-web +# The bundler runs the build itself and rewrites the content-hash files in +# target//assets. A plain `cargo build` leaves the previous bundle +# in place, and the server would serve the old css from it — a css change +# would pass every check here while the page shows the last build. +(cd "$repo" && topcoat asset bundle -p izlek-web) mkdir -p "$work/config" printf 'database = "izlek.db"\nlisten = "127.0.0.1:%s"\n' "$port" > "$work/config/izlek.toml" diff --git a/crates/izlek-web/tests/http.rs b/crates/izlek-web/tests/http.rs index 0afc0c4..c1e33c2 100644 --- a/crates/izlek-web/tests/http.rs +++ b/crates/izlek-web/tests/http.rs @@ -8268,7 +8268,8 @@ async fn a_clock_saved_on_a_task_renders_in_the_viewers_stored_timezone() { &[ ("task_id", &task), ("deadline", "2026-09-02"), - ("clock_time", "11:00"), + ("clock_hour", "11"), + ("clock_minute", "00"), ], ) .await; @@ -8289,7 +8290,8 @@ async fn a_clock_saved_on_a_task_renders_in_the_viewers_stored_timezone() { .await; let html = String::from_utf8_lossy(&page.bytes); assert!( - html.contains(r#""#), + html.contains(r#"aria-label="Hour" value="11""#) + && html.contains(r#"aria-label="Minute" value="00""#), "{html}" ); assert!(html.contains(">Sep 02 11:00<"), "{html}"); @@ -8318,7 +8320,8 @@ async fn a_clock_saved_on_a_task_renders_in_the_viewers_stored_timezone() { .await; let html = String::from_utf8_lossy(&shifted.bytes); assert!( - html.contains(r#""#), + html.contains(r#"aria-label="Hour" value="14""#) + && html.contains(r#"aria-label="Minute" value="00""#), "{html}" ); assert!(html.contains(">Sep 02 14:00<"), "{html}"); @@ -8337,7 +8340,8 @@ async fn an_empty_time_clears_the_clock_and_a_clear_clears_both() { &[ ("task_id", &task), ("deadline", "2026-09-02"), - ("clock_time", "11:00"), + ("clock_hour", "11"), + ("clock_minute", "00"), ], ) .await; @@ -8385,7 +8389,7 @@ async fn an_empty_time_clears_the_clock_and_a_clear_clears_both() { .post( "/api/save_task", Some(&admin_cookie), - &[("task_id", &task), ("clock_time", "")], + &[("task_id", &task), ("clock_hour", ""), ("clock_minute", "")], ) .await; assert!( @@ -8410,13 +8414,16 @@ async fn an_empty_time_clears_the_clock_and_a_clear_clears_both() { let html = String::from_utf8_lossy(&page.bytes); assert!(html.contains(">Sep 02<"), "{html}"); // An empty time renders as no selected step at all — the bare "--". - assert!(html.contains(r#"name="clock_time""#), "{html}"); + assert!( + html.contains(r#"name="clock_hour""#) && html.contains(r#"name="clock_minute""#), + "{html}" + ); assert!(!html.contains(">Sep 02 11:00<"), "{html}"); let saved = app .post( "/api/save_task", Some(&admin_cookie), - &[("task_id", &task), ("deadline", ""), ("clock_time", "")], + &[("task_id", &task), ("deadline", ""), ("clock_hour", ""), ("clock_minute", "")], ) .await; assert!( @@ -8454,7 +8461,8 @@ async fn a_title_edit_keeps_the_clock() { &[ ("task_id", &task), ("deadline", "2026-09-02"), - ("clock_time", "11:00"), + ("clock_hour", "11"), + ("clock_minute", "00"), ], ) .await; @@ -8511,7 +8519,8 @@ async fn a_description_edit_keeps_the_clock() { &[ ("task_id", &task), ("deadline", "2026-09-02"), - ("clock_time", "11:00"), + ("clock_hour", "11"), + ("clock_minute", "00"), ], ) .await; @@ -8570,7 +8579,7 @@ async fn a_time_that_cannot_be_used_is_refused_and_saves_nothing() { ("task_id", task.as_str()), ("title", "Renamed"), ("deadline", "2026-09-02"), - ("clock_time", "not-a-time"), + ("clock_hour", "not-a-time"), ], ) .await; @@ -8602,7 +8611,11 @@ async fn a_time_that_cannot_be_used_is_refused_and_saves_nothing() { "/api/save_task", Some(&admin_cookie), &format!("/?task={orphan}"), - &[("task_id", orphan.as_str()), ("clock_time", "16:20")], + &[ + ("task_id", orphan.as_str()), + ("clock_hour", "16"), + ("clock_minute", "20"), + ], ) .await; let location = answer.location.as_deref().unwrap_or_default(); @@ -8612,8 +8625,27 @@ async fn a_time_that_cannot_be_used_is_refused_and_saves_nothing() { ); let facts = app.store.task(&orphan).await.unwrap().expect("task gone"); assert!(facts.row.clock_at.is_none(), "a dayless time was stored"); + // And the mirror mistake: a minute with no hour is the same half of + // nothing. + let orphan2 = a_task(&app, &admin_cookie, &column, "Orphan Too").await; + let answer = app + .post_without_script( + "/api/save_task", + Some(&admin_cookie), + &format!("/?task={orphan2}"), + &[("task_id", orphan2.as_str()), ("clock_minute", "45")], + ) + .await; + let location = answer.location.as_deref().unwrap_or_default(); + assert!( + location.contains("refusal=bad-clock&on=save_task"), + "{location}" + ); + let facts = app.store.task(&orphan2).await.unwrap().expect("task gone"); + assert!(facts.row.clock_at.is_none(), "a lone minute was stored"); } + #[tokio::test] async fn a_card_wears_the_clock_chip_in_the_viewers_zone_instead_of_the_deadline() { let app = App::open().await; @@ -8647,7 +8679,8 @@ async fn a_card_wears_the_clock_chip_in_the_viewers_zone_instead_of_the_deadline ("title", "Kickoff"), ("column_id", &column), ("deadline", "2026-09-02"), - ("clock_time", "14:00"), + ("clock_hour", "14"), + ("clock_minute", "00"), ], ) .await; @@ -8704,7 +8737,7 @@ async fn a_time_set_on_an_existing_day_writes_both_columns() { .post( "/api/save_task", Some(&admin_cookie), - &[("task_id", &task), ("clock_time", "16:20")], + &[("task_id", &task), ("clock_hour", "16"), ("clock_minute", "20")], ) .await; assert!( @@ -8733,7 +8766,8 @@ async fn a_time_set_on_an_existing_day_writes_both_columns() { ("title", "Kickoff"), ("column_id", &column), ("deadline", "2026-09-10"), - ("clock_time", "09:30"), + ("clock_hour", "9"), + ("clock_minute", "30"), ], ) .await; @@ -8941,7 +8975,8 @@ async fn the_logs_feed_says_the_clock_in_its_own_words() { &[ ("task_id", &task), ("deadline", "2026-09-02"), - ("clock_time", "11:00"), + ("clock_hour", "11"), + ("clock_minute", "00"), ], ) .await; @@ -8991,8 +9026,8 @@ async fn the_datepicker_script_guards_a_panel_with_no_day_input() { // The moment field's panel: the grid's hidden day input and the time // box ride the same form. assert!( - html.contains(r#"name="clock_time" aria-label="Time" data-autosubmit="" data-search="""#), - "the moment select lost its searchable chrome: {html}" + html.contains(r#"name="clock_hour""#) && html.contains(r#"name="clock_minute""#), + "the moment boxes lost their names: {html}" ); assert!(html.contains("datepick-input"), "{html}"); } @@ -9011,7 +9046,7 @@ async fn an_off_step_clock_renders_itself_not_a_rounded_step() { .post( "/api/save_task", Some(&admin_cookie), - &[("task_id", &task), ("deadline", "2026-09-02"), ("clock_time", "11:23")], + &[("task_id", &task), ("deadline", "2026-09-02"), ("clock_hour", "11"), ("clock_minute", "23")], ) .await; assert!( @@ -9027,7 +9062,8 @@ async fn an_off_step_clock_renders_itself_not_a_rounded_step() { let page = app.get(&format!("/?task={task}"), Some(&admin_cookie)).await; let html = String::from_utf8_lossy(&page.bytes); assert!( - html.contains(r#""#), + html.contains(r#"aria-label="Hour" value="11""#) + && html.contains(r#"aria-label="Minute" value="23""#), "{html}" ); assert!(html.contains(">Sep 02 11:23<"), "{html}"); diff --git a/style/main.scss b/style/main.scss index 1c5b4f6..02695e6 100644 --- a/style/main.scss +++ b/style/main.scss @@ -1920,9 +1920,26 @@ img.avatar { .datepick-panel { width: 190px; } -// The time menu rides the same panel as the day grid; a select's intrinsic -// width is wider than the panel, so it is told to fill, not to size itself. -.datepick-panel .field-input { width: 100%; } +// The time row rides the same panel as the day grid: two two-digit boxes +// and a colon between them, one line. An input's intrinsic width is wider +// than its half, so each box fills its half and centers what is typed. +.datepick-time { + display: flex; + gap: 4px; + align-items: center; + margin-top: 6px; +} + +.datepick-time .field-input { + width: 100%; + min-width: 0; + text-align: center; +} + +.datepick-colon { + font-family: var(--font-mono); + color: var(--ink-soft); +} .datepick-head { display: flex;