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 {
150 pub theme: String,150 pub theme: String,
151 /// Display-only, as [`Self::timezone`].151 /// Display-only, as [`Self::timezone`].
152 pub language: String,152 pub language: String,
153+ /// Display-only, as [`Self::timezone`].
154+ pub ui: String,
153 }155 }
154 156
155 impl User {157 impl User {
@@ -596,6 +598,7 @@ pub trait Store: BoardReads + DetailReads + 'static {
596 timezone: &str,598 timezone: &str,
597 theme: &str,599 theme: &str,
598 language: &str,600 language: &str,
601+ ui: &str,
599 ) -> Result<()>;602 ) -> Result<()>;
600 603
601 async fn set_role(&self, user_id: &str, role: Role) -> Result<()>;604 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)] = &[
69 16,69 16,
70 include_str!("../../migrations/0016_display_preferences.sql"),70 include_str!("../../migrations/0016_display_preferences.sql"),
71 ),71 ),
72+ (17, include_str!("../../migrations/0017_ui_preference.sql")),
72 ];73 ];
73 74
74 /// The board a fresh workspace gets, and its columns. `Done` is the column75 /// The board a fresh workspace gets, and its columns. `Done` is the column
@@ -583,11 +584,12 @@ fn user_from(row: &Row) -> Result<User> {
583 timezone: text(row, 10)?,584 timezone: text(row, 10)?,
584 theme: text(row, 11)?,585 theme: text(row, 11)?,
585 language: text(row, 12)?,586 language: text(row, 12)?,
587+ ui: text(row, 13)?,
586 })588 })
587 }589 }
588 590
589 const USER_COLUMNS: &str = "id, workspace_id, email, display_name, role, password_hash, \591 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";
591 593
592 fn signin_link_from(row: &Row) -> Result<SigninLink> {594 fn signin_link_from(row: &Row) -> Result<SigninLink> {
593 Ok(SigninLink {595 Ok(SigninLink {
@@ -997,12 +999,13 @@ impl Store for TursoStore {
997 timezone: &str,999 timezone: &str,
998 theme: &str,1000 theme: &str,
999 language: &str,1001 language: &str,
1002+ ui: &str,
1000 ) -> Result<()> {1003 ) -> Result<()> {
1001 let conn = self.conn.lock().await;1004 let conn = self.conn.lock().await;
1002 let n = conn1005 let n = conn
1003 .execute(1006 .execute(
1004- "UPDATE user SET timezone = ?1, theme = ?2, language = ?3 WHERE id = ?4",1007+ "UPDATE user SET timezone = ?1, theme = ?2, language = ?3, ui = ?4 WHERE id = ?5",
1005- params![timezone, theme, language, user_id],1008+ params![timezone, theme, language, ui, user_id],
1006 )1009 )
1007 .await1010 .await
1008 .map_err(backend)?;1011 .map_err(backend)?;
crates/izlek-core/tests/store.rsmodified+6 -4
@@ -236,14 +236,14 @@ async fn migrations_apply_once_and_survive_reopen() {
236 let path = dir.join("izlek.db").to_string_lossy().into_owned();236 let path = dir.join("izlek.db").to_string_lossy().into_owned();
237 237
238 let first = TursoStore::open(&path).await.unwrap();238 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);
240 claim(&first).await;240 claim(&first).await;
241 drop(first);241 drop(first);
242 242
243 // Re-opening must not re-run 0001 (which would fail on CREATE TABLE) and243 // Re-opening must not re-run 0001 (which would fail on CREATE TABLE) and
244 // must not lose what the first open wrote.244 // must not lose what the first open wrote.
245 let second = TursoStore::open(&path).await.unwrap();245 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);
247 assert_eq!(second.workspace().await.unwrap().unwrap().name, "Izlek");247 assert_eq!(second.workspace().await.unwrap().unwrap().name, "Izlek");
248 drop(second);248 drop(second);
249 let _ = std::fs::remove_dir_all(&dir);249 let _ = std::fs::remove_dir_all(&dir);
@@ -260,7 +260,7 @@ async fn migration_0013_rebuilds_mail_rule_without_losing_its_ledger() {
260 a_pre_0013_store_with_a_rule_send_and_decision().await;260 a_pre_0013_store_with_a_rule_send_and_decision().await;
261 261
262 let store = TursoStore::open(path.to_str().unwrap()).await.unwrap();262 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);
264 assert_eq!(store.board(&workspace).await.unwrap().unwrap().id, board);264 assert_eq!(store.board(&workspace).await.unwrap().unwrap().id, board);
265 265
266 let rules = store.mail_rules(&board).await.unwrap();266 let rules = store.mail_rules(&board).await.unwrap();
@@ -864,9 +864,10 @@ async fn display_preferences_default_and_persist_across_reopen() {
864 assert_eq!(admin.timezone, "UTC");864 assert_eq!(admin.timezone, "UTC");
865 assert_eq!(admin.theme, "light");865 assert_eq!(admin.theme, "light");
866 assert_eq!(admin.language, "en");866 assert_eq!(admin.language, "en");
867+ assert_eq!(admin.ui, "instrument");
867 868
868 store869 store
869- .set_preferences(&admin_id, "Europe/Istanbul", "dark", "tr")870+ .set_preferences(&admin_id, "Europe/Istanbul", "dark", "tr", "ledger")
870 .await871 .await
871 .unwrap();872 .unwrap();
872 drop(store);873 drop(store);
@@ -876,6 +877,7 @@ async fn display_preferences_default_and_persist_across_reopen() {
876 assert_eq!(admin.timezone, "Europe/Istanbul");877 assert_eq!(admin.timezone, "Europe/Istanbul");
877 assert_eq!(admin.theme, "dark");878 assert_eq!(admin.theme, "dark");
878 assert_eq!(admin.language, "tr");879 assert_eq!(admin.language, "tr");
880+ assert_eq!(admin.ui, "ledger");
879 881
880 drop(reopened);882 drop(reopened);
881 let _ = std::fs::remove_dir_all(&dir);883 let _ = std::fs::remove_dir_all(&dir);
crates/izlek-web/src/i18n.rsmodified+3 -0
@@ -107,6 +107,7 @@ pub enum Key {
107 ThemeLabel,107 ThemeLabel,
108 LightOption,108 LightOption,
109 DarkOption,109 DarkOption,
110+ UiLabel,
110 LanguageLabel,111 LanguageLabel,
111 Saved,112 Saved,
112 SignOut,113 SignOut,
@@ -438,6 +439,8 @@ pub fn t(lang: Lang, key: Key) -> &'static str {
438 (TimezoneLabel, Tr) => "SAAT DİLİMİ",439 (TimezoneLabel, Tr) => "SAAT DİLİMİ",
439 (ThemeLabel, En) => "THEME",440 (ThemeLabel, En) => "THEME",
440 (ThemeLabel, Tr) => "TEMA",441 (ThemeLabel, Tr) => "TEMA",
442+ (UiLabel, En) => "INTERFACE",
443+ (UiLabel, Tr) => "ARAYÜZ",
441 (LightOption, En) => "Light",444 (LightOption, En) => "Light",
442 (LightOption, Tr) => "Açık",445 (LightOption, Tr) => "Açık",
443 (DarkOption, En) => "Dark",446 (DarkOption, En) => "Dark",
crates/izlek-web/src/layout.rsmodified+4 -1
@@ -109,6 +109,8 @@ pub async fn soft_nav_script(cx: &Cx) -> Result {
109 if (root.getAttribute('lang')) { document.documentElement.setAttribute('lang', root.getAttribute('lang')); } \109 if (root.getAttribute('lang')) { document.documentElement.setAttribute('lang', root.getAttribute('lang')); } \
110 if (root.hasAttribute('data-theme')) { document.documentElement.setAttribute('data-theme', root.getAttribute('data-theme')); } \110 if (root.hasAttribute('data-theme')) { document.documentElement.setAttribute('data-theme', root.getAttribute('data-theme')); } \
111 else { document.documentElement.removeAttribute('data-theme'); } \111 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'); } \
112 if (url) { history.replaceState(null, '', url); } \114 if (url) { history.replaceState(null, '', url); } \
113 window.scrollTo(fresh ? 0 : x, fresh ? 0 : y); \115 window.scrollTo(fresh ? 0 : x, fresh ? 0 : y); \
114 wire(); \116 wire(); \
@@ -286,6 +288,7 @@ async fn root_layout(cx: &Cx, slot: Result) -> Result {
286 Err(_) => None,288 Err(_) => None,
287 };289 };
288 let dark = asking.is_some_and(|user| user.theme == "dark");290 let dark = asking.is_some_and(|user| user.theme == "dark");
291+ let ui = asking.map_or("instrument", |user| user.ui.as_str());
289 let lang = asking.map_or(Lang::En, |user| Lang::from_code(&user.language));292 let lang = asking.map_or(Lang::En, |user| Lang::from_code(&user.language));
290 293
291 let content = match slot {294 let content = match slot {
@@ -301,7 +304,7 @@ async fn root_layout(cx: &Cx, slot: Result) -> Result {
301 304
302 view! {305 view! {
303 <!DOCTYPE html>306 <!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)>
305 <head>308 <head>
306 <meta charset="utf-8">309 <meta charset="utf-8">
307 <meta name="viewport" content="width=device-width, initial-scale=1">310 <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 {
311 BadZone,311 BadZone,
312 /// The theme field was not one of the values the form offers.312 /// The theme field was not one of the values the form offers.
313 BadTheme,313 BadTheme,
314+ /// The ui field was not one of the values the form offers.
315+ BadUi,
314 /// The language field was not one of the values the form offers.316 /// The language field was not one of the values the form offers.
315 BadLanguage,317 BadLanguage,
316 /// The email field did not look like an address.318 /// The email field did not look like an address.
@@ -367,6 +369,7 @@ impl Refusal {
367 }369 }
368 Refusal::BadZone => "That is not a timezone.".to_string(),370 Refusal::BadZone => "That is not a timezone.".to_string(),
369 Refusal::BadTheme => "That is not a theme.".to_string(),371 Refusal::BadTheme => "That is not a theme.".to_string(),
372+ Refusal::BadUi => "That is not an interface.".to_string(),
370 Refusal::BadLanguage => "That is not a language.".to_string(),373 Refusal::BadLanguage => "That is not a language.".to_string(),
371 Refusal::BadEmail => "That is not an address.".to_string(),374 Refusal::BadEmail => "That is not an address.".to_string(),
372 Refusal::BadFileType => {375 Refusal::BadFileType => {
@@ -418,6 +421,7 @@ impl Refusal {
418 }421 }
419 Refusal::BadZone => "Bu bir saat dilimi değil.".to_string(),422 Refusal::BadZone => "Bu bir saat dilimi değil.".to_string(),
420 Refusal::BadTheme => "Bu bir tema değil.".to_string(),423 Refusal::BadTheme => "Bu bir tema değil.".to_string(),
424+ Refusal::BadUi => "Bu bir arayüz değil.".to_string(),
421 Refusal::BadLanguage => "Bu bir dil değil.".to_string(),425 Refusal::BadLanguage => "Bu bir dil değil.".to_string(),
422 Refusal::BadEmail => "Bu bir adres değil.".to_string(),426 Refusal::BadEmail => "Bu bir adres değil.".to_string(),
423 Refusal::BadFileType => {427 Refusal::BadFileType => {
@@ -463,6 +467,7 @@ impl Refusal {
463 "bad-limit" => Refusal::BadLimit,467 "bad-limit" => Refusal::BadLimit,
464 "bad-zone" => Refusal::BadZone,468 "bad-zone" => Refusal::BadZone,
465 "bad-theme" => Refusal::BadTheme,469 "bad-theme" => Refusal::BadTheme,
470+ "bad-ui" => Refusal::BadUi,
466 "bad-language" => Refusal::BadLanguage,471 "bad-language" => Refusal::BadLanguage,
467 "bad-email" => Refusal::BadEmail,472 "bad-email" => Refusal::BadEmail,
468 "bad-file-type" => Refusal::BadFileType,473 "bad-file-type" => Refusal::BadFileType,
@@ -515,6 +520,7 @@ impl Refusal {
515 Refusal::BadLimit => "bad-limit",520 Refusal::BadLimit => "bad-limit",
516 Refusal::BadZone => "bad-zone",521 Refusal::BadZone => "bad-zone",
517 Refusal::BadTheme => "bad-theme",522 Refusal::BadTheme => "bad-theme",
523+ Refusal::BadUi => "bad-ui",
518 Refusal::BadLanguage => "bad-language",524 Refusal::BadLanguage => "bad-language",
519 Refusal::BadEmail => "bad-email",525 Refusal::BadEmail => "bad-email",
520 Refusal::BadFileType => "bad-file-type",526 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>)> {
446 struct SaveProfileForm {446 struct SaveProfileForm {
447 display_name: String,447 display_name: String,
448 /// Absent on a form that never got the field — kept as it was, same as448 /// 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.
450 #[serde(default)]450 #[serde(default)]
451 email: Option<String>,451 email: Option<String>,
452 #[serde(default)]452 #[serde(default)]
@@ -455,11 +455,16 @@ struct SaveProfileForm {
455 theme: Option<String>,455 theme: Option<String>,
456 #[serde(default)]456 #[serde(default)]
457 language: Option<String>,457 language: Option<String>,
458+ #[serde(default)]
459+ ui: Option<String>,
458 }460 }
459 461
460 /// The values the theme field offers.462 /// The values the theme field offers.
461 const THEME_OPTIONS: [&str; 2] = ["light", "dark"];463 const THEME_OPTIONS: [&str; 2] = ["light", "dark"];
462 464
465+/// The values the ui field offers.
466+const UI_OPTIONS: [&str; 2] = ["instrument", "ledger"];
467+
463 /// The values the language field offers.468 /// The values the language field offers.
464 const LANGUAGE_OPTIONS: [&str; 2] = ["en", "tr"];469 const LANGUAGE_OPTIONS: [&str; 2] = ["en", "tr"];
465 470
@@ -502,6 +507,10 @@ async fn save_profile(cx: &Cx, Form(input): Form<SaveProfileForm>) -> Result<(St
502 if !THEME_OPTIONS.contains(&theme.as_str()) {507 if !THEME_OPTIONS.contains(&theme.as_str()) {
503 return Ok(saved_or_refused("save_profile", Some(Refusal::BadTheme)));508 return Ok(saved_or_refused("save_profile", Some(Refusal::BadTheme)));
504 }509 }
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+ }
505 let language = input.language.unwrap_or_else(|| user.language.clone());514 let language = input.language.unwrap_or_else(|| user.language.clone());
506 if !LANGUAGE_OPTIONS.contains(&language.as_str()) {515 if !LANGUAGE_OPTIONS.contains(&language.as_str()) {
507 return Ok(saved_or_refused("save_profile", Some(Refusal::BadLanguage)));516 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
521 let outcome = store530 let outcome = store
522 .set_profile(&user.id, &display_name, user.photo_path.as_deref())531 .set_profile(&user.id, &display_name, user.photo_path.as_deref())
523 .await532 .await
524- .and(store.set_preferences(&user.id, &timezone, &theme, &language).await)533+ .and(store.set_preferences(&user.id, &timezone, &theme, &language, &ui).await)
525 .and(store.set_email(&user.id, &user.workspace_id, &email).await);534 .and(store.set_email(&user.id, &user.workspace_id, &email).await);
526 let refusal = match outcome {535 let refusal = match outcome {
527 Ok(()) => None,536 Ok(()) => None,
@@ -832,6 +841,13 @@ async fn settings_page(cx: &Cx) -> Result {
832 <option value="dark" selected=(user.theme == "dark")>(t(lang, Key::DarkOption))</option>841 <option value="dark" selected=(user.theme == "dark")>(t(lang, Key::DarkOption))</option>
833 </select>842 </select>
834 </label>843 </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>
835 <label class="field">851 <label class="field">
836 <span class="field-label">(t(lang, Key::LanguageLabel))</span>852 <span class="field-label">(t(lang, Key::LanguageLabel))</span>
837 <select class="field-input" name="language">853 <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() {
2818 assert!(location.contains("refusal=bad-theme&on=save_profile"), "{location}");2818 assert!(location.contains("refusal=bad-theme&on=save_profile"), "{location}");
2819 }2819 }
2820 2820
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+
2821 /// Creating a task files its own Created activity, but the column it lands2864 /// Creating a task files its own Created activity, but the column it lands
2822 /// in also fires a `Transition` the way a drop does — a `StatusBecomes` rule2865 /// in also fires a `Transition` the way a drop does — a `StatusBecomes` rule
2823 /// armed on that column must owe mail on creation, not only on a later move.2866 /// armed on that column must owe mail on creation, not only on a later move.