diff --git a/crates/izlek-core/migrations/0017_ui_preference.sql b/crates/izlek-core/migrations/0017_ui_preference.sql new file mode 100644 index 0000000..0774e06 --- /dev/null +++ b/crates/izlek-core/migrations/0017_ui_preference.sql @@ -0,0 +1,3 @@ +-- Which interface this person uses. Display-only, as the preferences before +-- it: no stored data depends on it. +ALTER TABLE user ADD COLUMN ui TEXT NOT NULL DEFAULT 'instrument'; diff --git a/crates/izlek-core/src/store/mod.rs b/crates/izlek-core/src/store/mod.rs index 62bca9e..0c94cb9 100644 --- a/crates/izlek-core/src/store/mod.rs +++ b/crates/izlek-core/src/store/mod.rs @@ -150,6 +150,8 @@ pub struct User { pub theme: String, /// Display-only, as [`Self::timezone`]. pub language: String, + /// Display-only, as [`Self::timezone`]. + pub ui: String, } impl User { @@ -596,6 +598,7 @@ pub trait Store: BoardReads + DetailReads + 'static { timezone: &str, theme: &str, language: &str, + ui: &str, ) -> Result<()>; async fn set_role(&self, user_id: &str, role: Role) -> Result<()>; diff --git a/crates/izlek-core/src/store/turso_store.rs b/crates/izlek-core/src/store/turso_store.rs index b80fedf..c50db08 100644 --- a/crates/izlek-core/src/store/turso_store.rs +++ b/crates/izlek-core/src/store/turso_store.rs @@ -69,6 +69,7 @@ const MIGRATIONS: &[(i64, &str)] = &[ 16, include_str!("../../migrations/0016_display_preferences.sql"), ), + (17, include_str!("../../migrations/0017_ui_preference.sql")), ]; /// The board a fresh workspace gets, and its columns. `Done` is the column @@ -583,11 +584,12 @@ fn user_from(row: &Row) -> Result { timezone: text(row, 10)?, theme: text(row, 11)?, language: text(row, 12)?, + ui: text(row, 13)?, }) } const USER_COLUMNS: &str = "id, workspace_id, email, display_name, role, password_hash, \ - photo_path, created_at, last_signed_in_at, invited_by, timezone, theme, language"; + photo_path, created_at, last_signed_in_at, invited_by, timezone, theme, language, ui"; fn signin_link_from(row: &Row) -> Result { Ok(SigninLink { @@ -997,12 +999,13 @@ impl Store for TursoStore { timezone: &str, theme: &str, language: &str, + ui: &str, ) -> Result<()> { let conn = self.conn.lock().await; let n = conn .execute( - "UPDATE user SET timezone = ?1, theme = ?2, language = ?3 WHERE id = ?4", - params![timezone, theme, language, user_id], + "UPDATE user SET timezone = ?1, theme = ?2, language = ?3, ui = ?4 WHERE id = ?5", + params![timezone, theme, language, ui, user_id], ) .await .map_err(backend)?; diff --git a/crates/izlek-core/tests/store.rs b/crates/izlek-core/tests/store.rs index fce8f63..880f62a 100644 --- a/crates/izlek-core/tests/store.rs +++ b/crates/izlek-core/tests/store.rs @@ -236,14 +236,14 @@ async fn migrations_apply_once_and_survive_reopen() { let path = dir.join("izlek.db").to_string_lossy().into_owned(); let first = TursoStore::open(&path).await.unwrap(); - assert_eq!(first.schema_version().await.unwrap(), 16); + assert_eq!(first.schema_version().await.unwrap(), 17); claim(&first).await; drop(first); // Re-opening must not re-run 0001 (which would fail on CREATE TABLE) and // must not lose what the first open wrote. let second = TursoStore::open(&path).await.unwrap(); - assert_eq!(second.schema_version().await.unwrap(), 16); + assert_eq!(second.schema_version().await.unwrap(), 17); assert_eq!(second.workspace().await.unwrap().unwrap().name, "Izlek"); drop(second); let _ = std::fs::remove_dir_all(&dir); @@ -260,7 +260,7 @@ async fn migration_0013_rebuilds_mail_rule_without_losing_its_ledger() { a_pre_0013_store_with_a_rule_send_and_decision().await; let store = TursoStore::open(path.to_str().unwrap()).await.unwrap(); - assert_eq!(store.schema_version().await.unwrap(), 16); + assert_eq!(store.schema_version().await.unwrap(), 17); assert_eq!(store.board(&workspace).await.unwrap().unwrap().id, board); let rules = store.mail_rules(&board).await.unwrap(); @@ -864,9 +864,10 @@ async fn display_preferences_default_and_persist_across_reopen() { assert_eq!(admin.timezone, "UTC"); assert_eq!(admin.theme, "light"); assert_eq!(admin.language, "en"); + assert_eq!(admin.ui, "instrument"); store - .set_preferences(&admin_id, "Europe/Istanbul", "dark", "tr") + .set_preferences(&admin_id, "Europe/Istanbul", "dark", "tr", "ledger") .await .unwrap(); drop(store); @@ -876,6 +877,7 @@ async fn display_preferences_default_and_persist_across_reopen() { assert_eq!(admin.timezone, "Europe/Istanbul"); assert_eq!(admin.theme, "dark"); assert_eq!(admin.language, "tr"); + assert_eq!(admin.ui, "ledger"); drop(reopened); let _ = std::fs::remove_dir_all(&dir); diff --git a/crates/izlek-web/src/i18n.rs b/crates/izlek-web/src/i18n.rs index 881f105..753e970 100644 --- a/crates/izlek-web/src/i18n.rs +++ b/crates/izlek-web/src/i18n.rs @@ -107,6 +107,7 @@ pub enum Key { ThemeLabel, LightOption, DarkOption, + UiLabel, LanguageLabel, Saved, SignOut, @@ -438,6 +439,8 @@ pub fn t(lang: Lang, key: Key) -> &'static str { (TimezoneLabel, Tr) => "SAAT DİLİMİ", (ThemeLabel, En) => "THEME", (ThemeLabel, Tr) => "TEMA", + (UiLabel, En) => "INTERFACE", + (UiLabel, Tr) => "ARAYÜZ", (LightOption, En) => "Light", (LightOption, Tr) => "Açık", (DarkOption, En) => "Dark", diff --git a/crates/izlek-web/src/layout.rs b/crates/izlek-web/src/layout.rs index afdb786..71234bb 100644 --- a/crates/izlek-web/src/layout.rs +++ b/crates/izlek-web/src/layout.rs @@ -109,6 +109,8 @@ pub async fn soft_nav_script(cx: &Cx) -> Result { if (root.getAttribute('lang')) { document.documentElement.setAttribute('lang', root.getAttribute('lang')); } \ if (root.hasAttribute('data-theme')) { document.documentElement.setAttribute('data-theme', root.getAttribute('data-theme')); } \ else { document.documentElement.removeAttribute('data-theme'); } \ + if (root.hasAttribute('data-ui')) { document.documentElement.setAttribute('data-ui', root.getAttribute('data-ui')); } \ + else { document.documentElement.removeAttribute('data-ui'); } \ if (url) { history.replaceState(null, '', url); } \ window.scrollTo(fresh ? 0 : x, fresh ? 0 : y); \ wire(); \ @@ -286,6 +288,7 @@ async fn root_layout(cx: &Cx, slot: Result) -> Result { Err(_) => None, }; let dark = asking.is_some_and(|user| user.theme == "dark"); + let ui = asking.map_or("instrument", |user| user.ui.as_str()); let lang = asking.map_or(Lang::En, |user| Lang::from_code(&user.language)); let content = match slot { @@ -301,7 +304,7 @@ async fn root_layout(cx: &Cx, slot: Result) -> Result { view! { - + diff --git a/crates/izlek-web/src/server.rs b/crates/izlek-web/src/server.rs index 05d5ceb..d2bd4a0 100644 --- a/crates/izlek-web/src/server.rs +++ b/crates/izlek-web/src/server.rs @@ -311,6 +311,8 @@ pub enum Refusal { BadZone, /// The theme field was not one of the values the form offers. BadTheme, + /// The ui field was not one of the values the form offers. + BadUi, /// The language field was not one of the values the form offers. BadLanguage, /// The email field did not look like an address. @@ -367,6 +369,7 @@ impl Refusal { } Refusal::BadZone => "That is not a timezone.".to_string(), Refusal::BadTheme => "That is not a theme.".to_string(), + Refusal::BadUi => "That is not an interface.".to_string(), Refusal::BadLanguage => "That is not a language.".to_string(), Refusal::BadEmail => "That is not an address.".to_string(), Refusal::BadFileType => { @@ -418,6 +421,7 @@ impl Refusal { } Refusal::BadZone => "Bu bir saat dilimi değil.".to_string(), Refusal::BadTheme => "Bu bir tema değil.".to_string(), + Refusal::BadUi => "Bu bir arayüz değil.".to_string(), Refusal::BadLanguage => "Bu bir dil değil.".to_string(), Refusal::BadEmail => "Bu bir adres değil.".to_string(), Refusal::BadFileType => { @@ -463,6 +467,7 @@ impl Refusal { "bad-limit" => Refusal::BadLimit, "bad-zone" => Refusal::BadZone, "bad-theme" => Refusal::BadTheme, + "bad-ui" => Refusal::BadUi, "bad-language" => Refusal::BadLanguage, "bad-email" => Refusal::BadEmail, "bad-file-type" => Refusal::BadFileType, @@ -515,6 +520,7 @@ impl Refusal { Refusal::BadLimit => "bad-limit", Refusal::BadZone => "bad-zone", Refusal::BadTheme => "bad-theme", + Refusal::BadUi => "bad-ui", Refusal::BadLanguage => "bad-language", Refusal::BadEmail => "bad-email", Refusal::BadFileType => "bad-file-type", diff --git a/crates/izlek-web/src/settings.rs b/crates/izlek-web/src/settings.rs index 6f11d9e..7ee0062 100644 --- a/crates/izlek-web/src/settings.rs +++ b/crates/izlek-web/src/settings.rs @@ -446,7 +446,7 @@ async fn send_test_mail(cx: &Cx) -> Result<(StatusCode, HeaderMap, Vec)> { struct SaveProfileForm { display_name: String, /// Absent on a form that never got the field — kept as it was, same as - /// `timezone`/`theme`/`language` below. + /// `timezone`/`theme`/`language`/`ui` below. #[serde(default)] email: Option, #[serde(default)] @@ -455,11 +455,16 @@ struct SaveProfileForm { theme: Option, #[serde(default)] language: Option, + #[serde(default)] + ui: Option, } /// The values the theme field offers. const THEME_OPTIONS: [&str; 2] = ["light", "dark"]; +/// The values the ui field offers. +const UI_OPTIONS: [&str; 2] = ["instrument", "ledger"]; + /// The values the language field offers. const LANGUAGE_OPTIONS: [&str; 2] = ["en", "tr"]; @@ -502,6 +507,10 @@ async fn save_profile(cx: &Cx, Form(input): Form) -> Result<(St if !THEME_OPTIONS.contains(&theme.as_str()) { return Ok(saved_or_refused("save_profile", Some(Refusal::BadTheme))); } + let ui = input.ui.unwrap_or_else(|| user.ui.clone()); + if !UI_OPTIONS.contains(&ui.as_str()) { + return Ok(saved_or_refused("save_profile", Some(Refusal::BadUi))); + } let language = input.language.unwrap_or_else(|| user.language.clone()); if !LANGUAGE_OPTIONS.contains(&language.as_str()) { return Ok(saved_or_refused("save_profile", Some(Refusal::BadLanguage))); @@ -521,7 +530,7 @@ async fn save_profile(cx: &Cx, Form(input): Form) -> Result<(St let outcome = store .set_profile(&user.id, &display_name, user.photo_path.as_deref()) .await - .and(store.set_preferences(&user.id, &timezone, &theme, &language).await) + .and(store.set_preferences(&user.id, &timezone, &theme, &language, &ui).await) .and(store.set_email(&user.id, &user.workspace_id, &email).await); let refusal = match outcome { Ok(()) => None, @@ -832,6 +841,13 @@ async fn settings_page(cx: &Cx) -> Result { +