The modal's controls wear the house
Browse files at this commitb25082b60450e2dc311983808fc0b9064a8393c2Parent: 4a0abe4- fix
- the modal's controls wear the house
4 changed files +305 -28
- Cargo.lock +1 -0
- crates/izlek-web/Cargo.toml +2 -0
- crates/izlek-web/src/detail.rs +206 -18
- style/main.scss +96 -10
Cargo.lockmodified+1 -0
| @@ -1876,6 +1876,7 @@ dependencies = [ | |||
| 1876 | "axum", | 1876 | "axum", |
| 1877 | "console_error_panic_hook", | 1877 | "console_error_panic_hook", |
| 1878 | "izlek-core", | 1878 | "izlek-core", |
| 1879 | + "js-sys", | ||
| 1879 | "leptos", | 1880 | "leptos", |
| 1880 | "leptos_axum", | 1881 | "leptos_axum", |
| 1881 | "leptos_meta", | 1882 | "leptos_meta", |
crates/izlek-web/Cargo.tomlmodified+2 -0
| @@ -39,6 +39,7 @@ serde_json = { workspace = true, optional = true } | |||
| 39 | 39 | ||
| 40 | console_error_panic_hook = { version = "0.1.7", optional = true } | 40 | console_error_panic_hook = { version = "0.1.7", optional = true } |
| 41 | wasm-bindgen = { version = "0.2", optional = true } | 41 | wasm-bindgen = { version = "0.2", optional = true } |
| 42 | +js-sys = { version = "0.3", optional = true } | ||
| 42 | 43 | ||
| 43 | [features] | 44 | [features] |
| 44 | default = [] | 45 | default = [] |
| @@ -46,6 +47,7 @@ hydrate = [ | |||
| 46 | "leptos/hydrate", | 47 | "leptos/hydrate", |
| 47 | "dep:console_error_panic_hook", | 48 | "dep:console_error_panic_hook", |
| 48 | "dep:wasm-bindgen", | 49 | "dep:wasm-bindgen", |
| 50 | + "dep:js-sys", | ||
| 49 | ] | 51 | ] |
| 50 | ssr = [ | 52 | ssr = [ |
| 51 | "leptos/ssr", | 53 | "leptos/ssr", |
crates/izlek-web/src/detail.rsmodified+206 -18
| @@ -983,6 +983,43 @@ fn DeadlineControl( | |||
| 983 | }); | 983 | }); |
| 984 | let toggle = format!("deadline-{}", task_id.get_value()); | 984 | let toggle = format!("deadline-{}", task_id.get_value()); |
| 985 | 985 | ||
| 986 | + let initial = parse_ymd(&deadline_input); | ||
| 987 | + let chosen = RwSignal::new(deadline_input); | ||
| 988 | + let view_pos = RwSignal::new(initial.map(|(y, m, _)| (y, m)).unwrap_or((1970, 1))); | ||
| 989 | + let today = RwSignal::new(None::<(i32, u8, u8)>); | ||
| 990 | + Effect::new(move |_| { | ||
| 991 | + #[cfg(feature = "hydrate")] | ||
| 992 | + { | ||
| 993 | + let now = js_sys::Date::new_0(); | ||
| 994 | + let day = ( | ||
| 995 | + now.get_full_year() as i32, | ||
| 996 | + now.get_month() as u8 + 1, | ||
| 997 | + now.get_date() as u8, | ||
| 998 | + ); | ||
| 999 | + today.set(Some(day)); | ||
| 1000 | + if initial.is_none() { | ||
| 1001 | + view_pos.set((day.0, day.1)); | ||
| 1002 | + } | ||
| 1003 | + } | ||
| 1004 | + }); | ||
| 1005 | + | ||
| 1006 | + // Copy, not moved: this fires from three separate buttons in the grid and | ||
| 1007 | + // footer, and each needs its own call. | ||
| 1008 | + let close = move || { | ||
| 1009 | + #[cfg(feature = "hydrate")] | ||
| 1010 | + { | ||
| 1011 | + use leptos::wasm_bindgen::JsCast; | ||
| 1012 | + let toggle = format!("deadline-{}", task_id.get_value()); | ||
| 1013 | + if let Some(input) = leptos::web_sys::window() | ||
| 1014 | + .and_then(|w| w.document()) | ||
| 1015 | + .and_then(|doc| doc.get_element_by_id(&toggle)) | ||
| 1016 | + .and_then(|el| el.dyn_into::<leptos::web_sys::HtmlInputElement>().ok()) | ||
| 1017 | + { | ||
| 1018 | + input.set_checked(false); | ||
| 1019 | + } | ||
| 1020 | + } | ||
| 1021 | + }; | ||
| 1022 | + | ||
| 986 | Either::Right(view! { | 1023 | Either::Right(view! { |
| 987 | <div class="edit edit-pop"> | 1024 | <div class="edit edit-pop"> |
| 988 | <input | 1025 | <input |
| @@ -1004,10 +1041,101 @@ fn DeadlineControl( | |||
| 1004 | <span class="field-text">{deadline_label}</span> | 1041 | <span class="field-text">{deadline_label}</span> |
| 1005 | {glyph::chevron()} | 1042 | {glyph::chevron()} |
| 1006 | </label> | 1043 | </label> |
| 1007 | - <div class="edit-form pop-panel"> | 1044 | + <div class="edit-form pop-panel datepick-panel"> |
| 1008 | <ActionForm action=action attr:class="pop-form"> | 1045 | <ActionForm action=action attr:class="pop-form"> |
| 1009 | <input type="hidden" name="task_id" value=move || task_id.get_value()/> | 1046 | <input type="hidden" name="task_id" value=move || task_id.get_value()/> |
| 1010 | - <input class="detail-date" type="date" name="deadline" value=deadline_input/> | 1047 | + <input type="hidden" name="deadline" value=move || chosen.get()/> |
| 1048 | + <div class="datepick-head"> | ||
| 1049 | + <button | ||
| 1050 | + class="datepick-nav datepick-prev" | ||
| 1051 | + type="button" | ||
| 1052 | + aria-label="Previous month" | ||
| 1053 | + on:click=move |_| { | ||
| 1054 | + view_pos.update(|pos| *pos = prev_month(*pos)); | ||
| 1055 | + } | ||
| 1056 | + > | ||
| 1057 | + {glyph::chevron()} | ||
| 1058 | + </button> | ||
| 1059 | + <span class="datepick-title">{move || month_title(view_pos.get())}</span> | ||
| 1060 | + <button | ||
| 1061 | + class="datepick-nav datepick-next" | ||
| 1062 | + type="button" | ||
| 1063 | + aria-label="Next month" | ||
| 1064 | + on:click=move |_| { | ||
| 1065 | + view_pos.update(|pos| *pos = next_month(*pos)); | ||
| 1066 | + } | ||
| 1067 | + > | ||
| 1068 | + {glyph::chevron()} | ||
| 1069 | + </button> | ||
| 1070 | + </div> | ||
| 1071 | + <div class="datepick-weekdays"> | ||
| 1072 | + <span>"M"</span> | ||
| 1073 | + <span>"T"</span> | ||
| 1074 | + <span>"W"</span> | ||
| 1075 | + <span>"T"</span> | ||
| 1076 | + <span>"F"</span> | ||
| 1077 | + <span>"S"</span> | ||
| 1078 | + <span>"S"</span> | ||
| 1079 | + </div> | ||
| 1080 | + <div class="datepick-grid"> | ||
| 1081 | + {move || { | ||
| 1082 | + let pos = view_pos.get(); | ||
| 1083 | + let selected = parse_ymd(&chosen.get()).map(|(y, m, d)| (y, m, d)); | ||
| 1084 | + let today_ymd = today.get(); | ||
| 1085 | + month_cells(pos) | ||
| 1086 | + .into_iter() | ||
| 1087 | + .map(|cell| { | ||
| 1088 | + match cell { | ||
| 1089 | + None => view! { <span class="datepick-cell"></span> }.into_any(), | ||
| 1090 | + Some(day) => { | ||
| 1091 | + let is_today = today_ymd == Some((pos.0, pos.1, day)); | ||
| 1092 | + let is_selected = selected == Some((pos.0, pos.1, day)); | ||
| 1093 | + view! { | ||
| 1094 | + <button | ||
| 1095 | + class="datepick-cell datepick-day" | ||
| 1096 | + class:datepick-today=is_today | ||
| 1097 | + class:datepick-selected=is_selected | ||
| 1098 | + type="button" | ||
| 1099 | + on:click=move |_| { | ||
| 1100 | + chosen.set(ymd_string(pos.0, pos.1, day)); | ||
| 1101 | + close(); | ||
| 1102 | + } | ||
| 1103 | + > | ||
| 1104 | + {day} | ||
| 1105 | + </button> | ||
| 1106 | + } | ||
| 1107 | + .into_any() | ||
| 1108 | + } | ||
| 1109 | + } | ||
| 1110 | + }) | ||
| 1111 | + .collect_view() | ||
| 1112 | + }} | ||
| 1113 | + </div> | ||
| 1114 | + <div class="datepick-foot"> | ||
| 1115 | + <button | ||
| 1116 | + class="datepick-action" | ||
| 1117 | + type="button" | ||
| 1118 | + on:click=move |_| { | ||
| 1119 | + chosen.set(String::new()); | ||
| 1120 | + close(); | ||
| 1121 | + } | ||
| 1122 | + > | ||
| 1123 | + "Clear" | ||
| 1124 | + </button> | ||
| 1125 | + <button | ||
| 1126 | + class="datepick-action" | ||
| 1127 | + type="button" | ||
| 1128 | + on:click=move |_| { | ||
| 1129 | + if let Some((y, m, d)) = today.get() { | ||
| 1130 | + view_pos.set((y, m)); | ||
| 1131 | + chosen.set(ymd_string(y, m, d)); | ||
| 1132 | + close(); | ||
| 1133 | + } | ||
| 1134 | + } | ||
| 1135 | + > | ||
| 1136 | + "Today" | ||
| 1137 | + </button> | ||
| 1138 | + </div> | ||
| 1011 | <div class="edit-row"> | 1139 | <div class="edit-row"> |
| 1012 | <button | 1140 | <button |
| 1013 | class="edit-save" | 1141 | class="edit-save" |
| @@ -1026,6 +1154,49 @@ fn DeadlineControl( | |||
| 1026 | </div> | 1154 | </div> |
| 1027 | }) | 1155 | }) |
| 1028 | } | 1156 | } |
| 1157 | + | ||
| 1158 | +/// `yyyy-mm-dd` into its three numbers, or nothing for the unset deadline. | ||
| 1159 | +fn parse_ymd(input: &str) -> Option<(i32, u8, u8)> { | ||
| 1160 | + let mut parts = input.splitn(3, '-'); | ||
| 1161 | + let year = parts.next()?.parse().ok()?; | ||
| 1162 | + let month = parts.next()?.parse().ok()?; | ||
| 1163 | + let day = parts.next()?.parse().ok()?; | ||
| 1164 | + Some((year, month, day)) | ||
| 1165 | +} | ||
| 1166 | + | ||
| 1167 | +fn ymd_string(year: i32, month: u8, day: u8) -> String { | ||
| 1168 | + format!("{year:04}-{month:02}-{day:02}") | ||
| 1169 | +} | ||
| 1170 | + | ||
| 1171 | +fn prev_month((year, month): (i32, u8)) -> (i32, u8) { | ||
| 1172 | + if month == 1 { (year - 1, 12) } else { (year, month - 1) } | ||
| 1173 | +} | ||
| 1174 | + | ||
| 1175 | +fn next_month((year, month): (i32, u8)) -> (i32, u8) { | ||
| 1176 | + if month == 12 { (year + 1, 1) } else { (year, month + 1) } | ||
| 1177 | +} | ||
| 1178 | + | ||
| 1179 | +fn month_title((year, month): (i32, u8)) -> String { | ||
| 1180 | + time::Month::try_from(month) | ||
| 1181 | + .map(|named| format!("{named} {year}")) | ||
| 1182 | + .unwrap_or_else(|_| format!("{month} {year}")) | ||
| 1183 | +} | ||
| 1184 | + | ||
| 1185 | +/// The grid for one month: blanks for the lead-in before day 1 (the week | ||
| 1186 | +/// starts Monday, as the header row says), then every day in the month. | ||
| 1187 | +fn month_cells((year, month): (i32, u8)) -> Vec<Option<u8>> { | ||
| 1188 | + let Ok(time_month) = time::Month::try_from(month) else { | ||
| 1189 | + return Vec::new(); | ||
| 1190 | + }; | ||
| 1191 | + let lead = time::Date::from_calendar_date(year, time_month, 1) | ||
| 1192 | + .map(|date| date.weekday().number_days_from_monday()) | ||
| 1193 | + .unwrap_or(0); | ||
| 1194 | + let days = time_month.length(year); | ||
| 1195 | + (0..lead) | ||
| 1196 | + .map(|_| None) | ||
| 1197 | + .chain((1..=days).map(Some)) | ||
| 1198 | + .collect() | ||
| 1199 | +} | ||
| 1029 | /// The round "+" from the artboard, and the list of people it opens. | 1200 | /// The round "+" from the artboard, and the list of people it opens. |
| 1030 | /// | 1201 | /// |
| 1031 | /// A native `<select>` cannot be made to look like this control, so the picker | 1202 | /// A native `<select>` cannot be made to look like this control, so the picker |
| @@ -1437,6 +1608,7 @@ fn DetailScreen( | |||
| 1437 | {refused(drop_file_refusal)} | 1608 | {refused(drop_file_refusal)} |
| 1438 | {may_comment | 1609 | {may_comment |
| 1439 | .then(|| { | 1610 | .then(|| { |
| 1611 | + let upload_input_id = format!("file-upload-{}", id.get_value()); | ||
| 1440 | view! { | 1612 | view! { |
| 1441 | <form | 1613 | <form |
| 1442 | class="file-upload" | 1614 | class="file-upload" |
| @@ -1445,10 +1617,34 @@ fn DetailScreen( | |||
| 1445 | enctype="multipart/form-data" | 1617 | enctype="multipart/form-data" |
| 1446 | > | 1618 | > |
| 1447 | <input type="hidden" name="task_id" value=move || id.get_value()/> | 1619 | <input type="hidden" name="task_id" value=move || id.get_value()/> |
| 1448 | - <input type="file" name="file" accept=accept required/> | 1620 | + <label class="file-upload-submit" for=upload_input_id.clone()> |
| 1449 | - <button class="file-upload-submit" type="submit"> | 1621 | + "Attach" |
| 1450 | - "Upload" | 1622 | + </label> |
| 1451 | - </button> | 1623 | + <input |
| 1624 | + class="visually-hidden" | ||
| 1625 | + id=upload_input_id | ||
| 1626 | + type="file" | ||
| 1627 | + name="file" | ||
| 1628 | + accept=accept | ||
| 1629 | + required | ||
| 1630 | + on:change=move |event| { | ||
| 1631 | + let _ = &event; | ||
| 1632 | + #[cfg(feature = "hydrate")] | ||
| 1633 | + { | ||
| 1634 | + use leptos::wasm_bindgen::JsCast; | ||
| 1635 | + if let Some(input) = event | ||
| 1636 | + .target() | ||
| 1637 | + .and_then(|target| { | ||
| 1638 | + target.dyn_into::<leptos::web_sys::HtmlInputElement>().ok() | ||
| 1639 | + }) | ||
| 1640 | + { | ||
| 1641 | + if let Some(form) = input.form() { | ||
| 1642 | + let _ = form.request_submit(); | ||
| 1643 | + } | ||
| 1644 | + } | ||
| 1645 | + } | ||
| 1646 | + } | ||
| 1647 | + /> | ||
| 1452 | </form> | 1648 | </form> |
| 1453 | {refused(upload_refusal)} | 1649 | {refused(upload_refusal)} |
| 1454 | } | 1650 | } |
| @@ -1630,20 +1826,12 @@ fn AssigneeChip( | |||
| 1630 | }); | 1826 | }); |
| 1631 | let name = person.display_name.clone(); | 1827 | let name = person.display_name.clone(); |
| 1632 | let person_id = person.id.clone(); | 1828 | let person_id = person.id.clone(); |
| 1633 | - // A chip carries a first name or no name at all. Half a name with an | 1829 | + let remove_title = format!("Take {name} off this task"); |
| 1634 | - // ellipsis after it — "Be…" — is noise where a name should be, and an | ||
| 1635 | - // avatar on its own still says who it is. | ||
| 1636 | - let full_name = name.clone(); | ||
| 1637 | - let first_name = name | ||
| 1638 | - .split_whitespace() | ||
| 1639 | - .next() | ||
| 1640 | - .unwrap_or(name.as_str()) | ||
| 1641 | - .to_owned(); | ||
| 1642 | 1830 | ||
| 1643 | view! { | 1831 | view! { |
| 1644 | - <span class="assignee-chip" title=full_name> | 1832 | + <span class="assignee-chip" title=name.clone()> |
| 1645 | <Avatar person=person extra="avatar-sm"/> | 1833 | <Avatar person=person extra="avatar-sm"/> |
| 1646 | - <span class="assignee-name">{first_name}</span> | 1834 | + <span class="assignee-name">{name.clone()}</span> |
| 1647 | {may_write | 1835 | {may_write |
| 1648 | .then(|| { | 1836 | .then(|| { |
| 1649 | view! { | 1837 | view! { |
| @@ -1653,7 +1841,7 @@ fn AssigneeChip( | |||
| 1653 | <button | 1841 | <button |
| 1654 | class="assignee-remove" | 1842 | class="assignee-remove" |
| 1655 | type="submit" | 1843 | type="submit" |
| 1656 | - title=format!("Take {name} off this task") | 1844 | + title=remove_title |
| 1657 | > | 1845 | > |
| 1658 | {glyph::cross()} | 1846 | {glyph::cross()} |
| 1659 | </button> | 1847 | </button> |
style/main.scssmodified+96 -10
| @@ -1033,16 +1033,98 @@ a { | |||
| 1033 | .glyph { color: #a04a24; } | 1033 | .glyph { color: #a04a24; } |
| 1034 | } | 1034 | } |
| 1035 | 1035 | ||
| 1036 | -.detail-date { | 1036 | +// -- deadline calendar ------------------------------------------------------- |
| 1037 | - width: 100%; | 1037 | + |
| 1038 | - height: 32px; | 1038 | +.datepick-panel { width: 190px; } |
| 1039 | - padding: 0 8px; | 1039 | + |
| 1040 | - border: 1px solid var(--border-strong); | 1040 | +.datepick-head { |
| 1041 | - border-radius: var(--radius); | 1041 | + display: flex; |
| 1042 | - background: var(--surface); | 1042 | + align-items: center; |
| 1043 | + justify-content: space-between; | ||
| 1044 | + margin-bottom: 6px; | ||
| 1045 | +} | ||
| 1046 | + | ||
| 1047 | +.datepick-title { | ||
| 1048 | + font-family: var(--font-mono); | ||
| 1049 | + font-size: 11px; | ||
| 1050 | + color: var(--ink); | ||
| 1051 | +} | ||
| 1052 | + | ||
| 1053 | +.datepick-nav { | ||
| 1054 | + display: inline-flex; | ||
| 1055 | + align-items: center; | ||
| 1056 | + justify-content: center; | ||
| 1057 | + width: 20px; | ||
| 1058 | + height: 20px; | ||
| 1059 | + border: none; | ||
| 1060 | + border-radius: 4px; | ||
| 1061 | + background: transparent; | ||
| 1062 | + color: var(--muted); | ||
| 1063 | + cursor: pointer; | ||
| 1064 | + | ||
| 1065 | + &:hover { background: #f3f1ea; } | ||
| 1066 | +} | ||
| 1067 | + | ||
| 1068 | +.datepick-prev .glyph { transform: rotate(90deg); } | ||
| 1069 | +.datepick-next .glyph { transform: rotate(-90deg); } | ||
| 1070 | + | ||
| 1071 | +.datepick-weekdays, | ||
| 1072 | +.datepick-grid { | ||
| 1073 | + display: grid; | ||
| 1074 | + grid-template-columns: repeat(7, 1fr); | ||
| 1075 | +} | ||
| 1076 | + | ||
| 1077 | +.datepick-weekdays { | ||
| 1078 | + margin-bottom: 2px; | ||
| 1079 | + font-family: var(--font-mono); | ||
| 1080 | + font-size: 10px; | ||
| 1081 | + color: var(--muted-soft); | ||
| 1082 | + text-align: center; | ||
| 1083 | +} | ||
| 1084 | + | ||
| 1085 | +.datepick-cell { | ||
| 1086 | + height: 24px; | ||
| 1087 | + border: none; | ||
| 1088 | + background: transparent; | ||
| 1043 | font-family: inherit; | 1089 | font-family: inherit; |
| 1044 | - font-size: 13px; | 1090 | + font-size: 11px; |
| 1091 | +} | ||
| 1092 | + | ||
| 1093 | +.datepick-day { | ||
| 1094 | + border-radius: 5px; | ||
| 1045 | color: var(--ink); | 1095 | color: var(--ink); |
| 1096 | + cursor: pointer; | ||
| 1097 | + | ||
| 1098 | + &:hover { background: #f3f1ea; } | ||
| 1099 | +} | ||
| 1100 | + | ||
| 1101 | +.datepick-today { box-shadow: inset 0 0 0 1px var(--accent); } | ||
| 1102 | + | ||
| 1103 | +.datepick-selected { | ||
| 1104 | + background: var(--accent); | ||
| 1105 | + color: var(--surface); | ||
| 1106 | + | ||
| 1107 | + &:hover { background: var(--accent); } | ||
| 1108 | +} | ||
| 1109 | + | ||
| 1110 | +.datepick-foot { | ||
| 1111 | + display: flex; | ||
| 1112 | + align-items: center; | ||
| 1113 | + justify-content: space-between; | ||
| 1114 | + margin-top: 6px; | ||
| 1115 | + padding-top: 6px; | ||
| 1116 | + border-top: 1px solid var(--border); | ||
| 1117 | +} | ||
| 1118 | + | ||
| 1119 | +.datepick-action { | ||
| 1120 | + border: none; | ||
| 1121 | + background: transparent; | ||
| 1122 | + font-family: inherit; | ||
| 1123 | + font-size: 11px; | ||
| 1124 | + color: var(--accent); | ||
| 1125 | + cursor: pointer; | ||
| 1126 | + | ||
| 1127 | + &:hover { color: var(--accent-ink); } | ||
| 1046 | } | 1128 | } |
| 1047 | 1129 | ||
| 1048 | // -- assignees -------------------------------------------------------------- | 1130 | // -- assignees -------------------------------------------------------------- |
| @@ -1058,8 +1140,9 @@ a { | |||
| 1058 | border-radius: var(--radius); | 1140 | border-radius: var(--radius); |
| 1059 | } | 1141 | } |
| 1060 | 1142 | ||
| 1061 | -// Chips never shrink and never truncate: the row gives up labels instead, and | 1143 | +// Chips never shrink: the row gives up labels instead, and what is left is a |
| 1062 | -// what is left is a whole first name or an avatar on its own. | 1144 | +// whole name or an avatar on its own. A name too long for the row ellipsizes |
| 1145 | +// rather than losing whole words. | ||
| 1063 | .assignee-chip { | 1146 | .assignee-chip { |
| 1064 | display: inline-flex; | 1147 | display: inline-flex; |
| 1065 | flex: none; | 1148 | flex: none; |
| @@ -1073,6 +1156,9 @@ a { | |||
| 1073 | } | 1156 | } |
| 1074 | 1157 | ||
| 1075 | .assignee-name { | 1158 | .assignee-name { |
| 1159 | + max-width: 120px; | ||
| 1160 | + overflow: hidden; | ||
| 1161 | + text-overflow: ellipsis; | ||
| 1076 | font-size: 12px; | 1162 | font-size: 12px; |
| 1077 | color: var(--ink); | 1163 | color: var(--ink); |
| 1078 | } | 1164 | } |