forge
Explore
Log in

Don't you dare go Hollow

The interface becomes a choice, saved like a theme

Browse files at this commit

86d9d52789b5294e506cb3bc68fc36769088b9d1Ahmet Kaan GümüşParent: 14f757d
  • feat
    • the interface becomes a choice, saved like a theme
Show full message
✨ feat(web): the interface becomes a choice, saved like a theme
crates/izlek-core/migrations/0017_ui_preference.sqladded+3 -0
@@ -0,0 +1,3 @@
1+-- Which interface this person uses. Display-only, as the preferences before
2+-- it: no stored data depends on it.
3+ALTER TABLE user ADD COLUMN ui TEXT NOT NULL DEFAULT 'instrument';
crates/izlek-core/src/store/mod.rsmodified+3 -0
@@ -150,6 +150,8 @@ pub struct User {
150150 pub theme: String,
151151 /// Display-only, as [`Self::timezone`].
152152 pub language: String,
153+ /// Display-only, as [`Self::timezone`].
154+ pub ui: String,
153155 }
154156
155157 impl User {
@@ -596,6 +598,7 @@ pub trait Store: BoardReads + DetailReads + 'static {
596598 timezone: &str,
597599 theme: &str,
598600 language: &str,
601+ ui: &str,
599602 ) -> Result<()>;
600603
601604 async fn set_role(&self, user_id: &str, role: Role) -> Result<()>;
crates/izlek-core/src/store/turso_store.rsmodified+6 -3
@@ -69,6 +69,7 @@ const MIGRATIONS: &[(i64, &str)] = &[
6969 16,
7070 include_str!("../../migrations/0016_display_preferences.sql"),
7171 ),
72+ (17, include_str!("../../migrations/0017_ui_preference.sql")),
7273 ];
7374
7475 /// The board a fresh workspace gets, and its columns. `Done` is the column
@@ -583,11 +584,12 @@ fn user_from(row: &Row) -> Result<User> {
583584 timezone: text(row, 10)?,
584585 theme: text(row, 11)?,
585586 language: text(row, 12)?,
587+ ui: text(row, 13)?,
586588 })
587589 }
588590
589591 const USER_COLUMNS: &str = "id, workspace_id, email, display_name, role, password_hash, \
590- photo_path, created_at, last_signed_in_at, invited_by, timezone, theme, language";
592+ photo_path, created_at, last_signed_in_at, invited_by, timezone, theme, language, ui";
591593
592594 fn signin_link_from(row: &Row) -> Result<SigninLink> {
593595 Ok(SigninLink {
@@ -997,12 +999,13 @@ impl Store for TursoStore {
997999 timezone: &str,
9981000 theme: &str,
9991001 language: &str,
1002+ ui: &str,
10001003 ) -> Result<()> {
10011004 let conn = self.conn.lock().await;
10021005 let n = conn
10031006 .execute(
1004- "UPDATE user SET timezone = ?1, theme = ?2, language = ?3 WHERE id = ?4",
1005- params![timezone, theme, language, user_id],
1007+ "UPDATE user SET timezone = ?1, theme = ?2, language = ?3, ui = ?4 WHERE id = ?5",
1008+ params![timezone, theme, language, ui, user_id],
10061009 )
10071010 .await
10081011 .map_err(backend)?;
crates/izlek-core/tests/store.rsmodified+6 -4
@@ -236,14 +236,14 @@ async fn migrations_apply_once_and_survive_reopen() {
236236 let path = dir.join("izlek.db").to_string_lossy().into_owned();
237237
238238 let first = TursoStore::open(&path).await.unwrap();
239- assert_eq!(first.schema_version().await.unwrap(), 16);
239+ assert_eq!(first.schema_version().await.unwrap(), 17);
240240 claim(&first).await;
241241 drop(first);
242242
243243 // Re-opening must not re-run 0001 (which would fail on CREATE TABLE) and
244244 // must not lose what the first open wrote.
245245 let second = TursoStore::open(&path).await.unwrap();
246- assert_eq!(second.schema_version().await.unwrap(), 16);
246+ assert_eq!(second.schema_version().await.unwrap(), 17);
247247 assert_eq!(second.workspace().await.unwrap().unwrap().name, "Izlek");
248248 drop(second);
249249 let _ = std::fs::remove_dir_all(&dir);
@@ -260,7 +260,7 @@ async fn migration_0013_rebuilds_mail_rule_without_losing_its_ledger() {
260260 a_pre_0013_store_with_a_rule_send_and_decision().await;
261261
262262 let store = TursoStore::open(path.to_str().unwrap()).await.unwrap();
263- assert_eq!(store.schema_version().await.unwrap(), 16);
263+ assert_eq!(store.schema_version().await.unwrap(), 17);
264264 assert_eq!(store.board(&workspace).await.unwrap().unwrap().id, board);
265265
266266 let rules = store.mail_rules(&board).await.unwrap();
@@ -864,9 +864,10 @@ async fn display_preferences_default_and_persist_across_reopen() {
864864 assert_eq!(admin.timezone, "UTC");
865865 assert_eq!(admin.theme, "light");
866866 assert_eq!(admin.language, "en");
867+ assert_eq!(admin.ui, "instrument");
867868
868869 store
869- .set_preferences(&admin_id, "Europe/Istanbul", "dark", "tr")
870+ .set_preferences(&admin_id, "Europe/Istanbul", "dark", "tr", "ledger")
870871 .await
871872 .unwrap();
872873 drop(store);
@@ -876,6 +877,7 @@ async fn display_preferences_default_and_persist_across_reopen() {
876877 assert_eq!(admin.timezone, "Europe/Istanbul");
877878 assert_eq!(admin.theme, "dark");
878879 assert_eq!(admin.language, "tr");
880+ assert_eq!(admin.ui, "ledger");
879881
880882 drop(reopened);
881883 let _ = std::fs::remove_dir_all(&dir);
crates/izlek-web/src/i18n.rsmodified+3 -0
@@ -107,6 +107,7 @@ pub enum Key {
107107 ThemeLabel,
108108 LightOption,
109109 DarkOption,
110+ UiLabel,
110111 LanguageLabel,
111112 Saved,
112113 SignOut,
@@ -438,6 +439,8 @@ pub fn t(lang: Lang, key: Key) -> &'static str {
438439 (TimezoneLabel, Tr) => "SAAT DİLİMİ",
439440 (ThemeLabel, En) => "THEME",
440441 (ThemeLabel, Tr) => "TEMA",
442+ (UiLabel, En) => "INTERFACE",
443+ (UiLabel, Tr) => "ARAYÜZ",
441444 (LightOption, En) => "Light",
442445 (LightOption, Tr) => "Açık",
443446 (DarkOption, En) => "Dark",
crates/izlek-web/src/layout.rsmodified+4 -1
@@ -109,6 +109,8 @@ pub async fn soft_nav_script(cx: &Cx) -> Result {
109109 if (root.getAttribute('lang')) { document.documentElement.setAttribute('lang', root.getAttribute('lang')); } \
110110 if (root.hasAttribute('data-theme')) { document.documentElement.setAttribute('data-theme', root.getAttribute('data-theme')); } \
111111 else { document.documentElement.removeAttribute('data-theme'); } \
112+ if (root.hasAttribute('data-ui')) { document.documentElement.setAttribute('data-ui', root.getAttribute('data-ui')); } \
113+ else { document.documentElement.removeAttribute('data-ui'); } \
112114 if (url) { history.replaceState(null, '', url); } \
113115 window.scrollTo(fresh ? 0 : x, fresh ? 0 : y); \
114116 wire(); \
@@ -286,6 +288,7 @@ async fn root_layout(cx: &Cx, slot: Result) -> Result {
286288 Err(_) => None,
287289 };
288290 let dark = asking.is_some_and(|user| user.theme == "dark");
291+ let ui = asking.map_or("instrument", |user| user.ui.as_str());
289292 let lang = asking.map_or(Lang::En, |user| Lang::from_code(&user.language));
290293
291294 let content = match slot {
@@ -301,7 +304,7 @@ async fn root_layout(cx: &Cx, slot: Result) -> Result {
301304
302305 view! {
303306 <!DOCTYPE html>
304- <html lang=(lang.code()) data-theme=(dark.then_some("dark"))>
307+ <html lang=(lang.code()) data-theme=(dark.then_some("dark")) data-ui=(ui)>
305308 <head>
306309 <meta charset="utf-8">
307310 <meta name="viewport" content="width=device-width, initial-scale=1">
crates/izlek-web/src/server.rsmodified+6 -0
@@ -311,6 +311,8 @@ pub enum Refusal {
311311 BadZone,
312312 /// The theme field was not one of the values the form offers.
313313 BadTheme,
314+ /// The ui field was not one of the values the form offers.
315+ BadUi,
314316 /// The language field was not one of the values the form offers.
315317 BadLanguage,
316318 /// The email field did not look like an address.
@@ -367,6 +369,7 @@ impl Refusal {
367369 }
368370 Refusal::BadZone => "That is not a timezone.".to_string(),
369371 Refusal::BadTheme => "That is not a theme.".to_string(),
372+ Refusal::BadUi => "That is not an interface.".to_string(),
370373 Refusal::BadLanguage => "That is not a language.".to_string(),
371374 Refusal::BadEmail => "That is not an address.".to_string(),
372375 Refusal::BadFileType => {
@@ -418,6 +421,7 @@ impl Refusal {
418421 }
419422 Refusal::BadZone => "Bu bir saat dilimi değil.".to_string(),
420423 Refusal::BadTheme => "Bu bir tema değil.".to_string(),
424+ Refusal::BadUi => "Bu bir arayüz değil.".to_string(),
421425 Refusal::BadLanguage => "Bu bir dil değil.".to_string(),
422426 Refusal::BadEmail => "Bu bir adres değil.".to_string(),
423427 Refusal::BadFileType => {
@@ -463,6 +467,7 @@ impl Refusal {
463467 "bad-limit" => Refusal::BadLimit,
464468 "bad-zone" => Refusal::BadZone,
465469 "bad-theme" => Refusal::BadTheme,
470+ "bad-ui" => Refusal::BadUi,
466471 "bad-language" => Refusal::BadLanguage,
467472 "bad-email" => Refusal::BadEmail,
468473 "bad-file-type" => Refusal::BadFileType,
@@ -515,6 +520,7 @@ impl Refusal {
515520 Refusal::BadLimit => "bad-limit",
516521 Refusal::BadZone => "bad-zone",
517522 Refusal::BadTheme => "bad-theme",
523+ Refusal::BadUi => "bad-ui",
518524 Refusal::BadLanguage => "bad-language",
519525 Refusal::BadEmail => "bad-email",
520526 Refusal::BadFileType => "bad-file-type",
crates/izlek-web/src/settings.rsmodified+18 -2
@@ -446,7 +446,7 @@ async fn send_test_mail(cx: &Cx) -> Result<(StatusCode, HeaderMap, Vec<u8>)> {
446446 struct SaveProfileForm {
447447 display_name: String,
448448 /// Absent on a form that never got the field — kept as it was, same as
449- /// `timezone`/`theme`/`language` below.
449+ /// `timezone`/`theme`/`language`/`ui` below.
450450 #[serde(default)]
451451 email: Option<String>,
452452 #[serde(default)]
@@ -455,11 +455,16 @@ struct SaveProfileForm {
455455 theme: Option<String>,
456456 #[serde(default)]
457457 language: Option<String>,
458+ #[serde(default)]
459+ ui: Option<String>,
458460 }
459461
460462 /// The values the theme field offers.
461463 const THEME_OPTIONS: [&str; 2] = ["light", "dark"];
462464
465+/// The values the ui field offers.
466+const UI_OPTIONS: [&str; 2] = ["instrument", "ledger"];
467+
463468 /// The values the language field offers.
464469 const LANGUAGE_OPTIONS: [&str; 2] = ["en", "tr"];
465470
@@ -502,6 +507,10 @@ async fn save_profile(cx: &Cx, Form(input): Form<SaveProfileForm>) -> Result<(St
502507 if !THEME_OPTIONS.contains(&theme.as_str()) {
503508 return Ok(saved_or_refused("save_profile", Some(Refusal::BadTheme)));
504509 }
510+ let ui = input.ui.unwrap_or_else(|| user.ui.clone());
511+ if !UI_OPTIONS.contains(&ui.as_str()) {
512+ return Ok(saved_or_refused("save_profile", Some(Refusal::BadUi)));
513+ }
505514 let language = input.language.unwrap_or_else(|| user.language.clone());
506515 if !LANGUAGE_OPTIONS.contains(&language.as_str()) {
507516 return Ok(saved_or_refused("save_profile", Some(Refusal::BadLanguage)));
@@ -521,7 +530,7 @@ async fn save_profile(cx: &Cx, Form(input): Form<SaveProfileForm>) -> Result<(St
521530 let outcome = store
522531 .set_profile(&user.id, &display_name, user.photo_path.as_deref())
523532 .await
524- .and(store.set_preferences(&user.id, &timezone, &theme, &language).await)
533+ .and(store.set_preferences(&user.id, &timezone, &theme, &language, &ui).await)
525534 .and(store.set_email(&user.id, &user.workspace_id, &email).await);
526535 let refusal = match outcome {
527536 Ok(()) => None,
@@ -832,6 +841,13 @@ async fn settings_page(cx: &Cx) -> Result {
832841 <option value="dark" selected=(user.theme == "dark")>(t(lang, Key::DarkOption))</option>
833842 </select>
834843 </label>
844+ <label class="field">
845+ <span class="field-label">(t(lang, Key::UiLabel))</span>
846+ <select class="field-input" name="ui">
847+ <option value="instrument" selected=(user.ui == "instrument")>"Instrument"</option>
848+ <option value="ledger" selected=(user.ui == "ledger")>"Ledger"</option>
849+ </select>
850+ </label>
835851 <label class="field">
836852 <span class="field-label">(t(lang, Key::LanguageLabel))</span>
837853 <select class="field-input" name="language">
crates/izlek-web/tests/http.rsmodified+43 -0
@@ -2818,6 +2818,49 @@ async fn an_unlisted_theme_is_refused() {
28182818 assert!(location.contains("refusal=bad-theme&on=save_profile"), "{location}");
28192819 }
28202820
2821+#[tokio::test]
2822+async fn the_ledger_ui_is_saved_and_marks_the_page() {
2823+ let app = App::open().await;
2824+ let admin_cookie = admin(&app).await;
2825+
2826+ let saved = app
2827+ .post(
2828+ "/api/save_profile",
2829+ Some(&admin_cookie),
2830+ &[("display_name", "Ada Lovelace"), ("ui", "ledger")],
2831+ )
2832+ .await;
2833+ assert!(
2834+ !saved.location.as_deref().unwrap_or_default().contains("refusal="),
2835+ "{:?}",
2836+ saved.location
2837+ );
2838+
2839+ let page = app.get("/settings", Some(&admin_cookie)).await;
2840+ let html = String::from_utf8_lossy(&page.bytes);
2841+ assert!(html.contains(r#"data-ui="ledger""#), "{html}");
2842+}
2843+
2844+#[tokio::test]
2845+async fn an_unlisted_ui_is_refused() {
2846+ let app = App::open().await;
2847+ let admin_cookie = admin(&app).await;
2848+
2849+ let answer = app
2850+ .post(
2851+ "/api/save_profile",
2852+ Some(&admin_cookie),
2853+ &[("display_name", "Ada Lovelace"), ("ui", "neon")],
2854+ )
2855+ .await;
2856+ let location = answer.location.as_deref().unwrap_or_default();
2857+ assert!(location.contains("refusal=bad-ui&on=save_profile"), "{location}");
2858+
2859+ let page = app.get("/settings", Some(&admin_cookie)).await;
2860+ let html = String::from_utf8_lossy(&page.bytes);
2861+ assert!(html.contains(r#"data-ui="instrument""#), "{html}");
2862+}
2863+
28212864 /// Creating a task files its own Created activity, but the column it lands
28222865 /// in also fires a `Transition` the way a drop does — a `StatusBecomes` rule
28232866 /// armed on that column must owe mail on creation, not only on a later move.