From 9a7cb74b067a016de191694878631915a510bbf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sat, 17 Oct 2026 09:24:08 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84=20feat(ui):=20light=20theme=20by?= =?UTF-8?q?=20default,=20profile=20links,=20wider=20layout?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - light theme is the default for everyone, including existing users (migration 0036) - add "Your profile" menu link; usernames link to profiles - widen layout to 1280px - code blocks in cards wrap instead of overflowing - dropdowns close on outside click and Escape - GitHub-style watch menu --- .../migrations/0036_default_light_theme.sql | 5 + crates/forge-core/src/store/account_tokens.rs | 4 +- crates/forge-core/src/store/migrate.rs | 4 + crates/forge-core/src/store/mod.rs | 12 +- crates/forge-core/src/store/ui_prefs.rs | 2 +- crates/forge-core/src/store/user_delete.rs | 6 +- crates/forge-web/src/pages/discussion_view.rs | 19 +- crates/forge-web/src/pages/discussions.rs | 4 +- crates/forge-web/src/pages/issue_parts.rs | 22 ++- crates/forge-web/src/pages/issue_view.rs | 5 +- crates/forge-web/src/pages/issues_list.rs | 6 +- crates/forge-web/src/pages/pull_view.rs | 16 +- crates/forge-web/src/pages/pulls_list.rs | 6 +- crates/forge-web/src/pages/releases.rs | 6 +- crates/forge-web/src/pages/repo.rs | 8 +- .../src/pages/settings_appearance.rs | 16 +- crates/forge-web/src/theme.rs | 67 +++++-- crates/forge-web/src/views/review_thread.rs | 10 +- crates/forge-web/tests/community_i18n_e2e.rs | 2 +- crates/forge-web/tests/i18n_e2e.rs | 10 +- crates/forge-web/tests/ui_prefs_e2e.rs | 69 +++++--- style/_repo.scss | 33 +--- style/_shell.scss | 2 +- style/main.scss | 163 ++++++++++++++++-- 24 files changed, 366 insertions(+), 131 deletions(-) create mode 100644 crates/forge-core/migrations/0036_default_light_theme.sql diff --git a/crates/forge-core/migrations/0036_default_light_theme.sql b/crates/forge-core/migrations/0036_default_light_theme.sql new file mode 100644 index 0000000..37025f0 --- /dev/null +++ b/crates/forge-core/migrations/0036_default_light_theme.sql @@ -0,0 +1,5 @@ +-- The product default theme is now 'light'. The deployment is new, so no user chose 'auto' +-- deliberately: move every stored 'auto' to 'light'. The column default stays in the 0030 shape +-- (SQLite cannot change a default without rebuilding `users`, which its foreign keys make +-- unsafe), so new rows get 'light' from the insert sites in store/. +UPDATE users SET theme = 'light' WHERE theme = 'auto'; diff --git a/crates/forge-core/src/store/account_tokens.rs b/crates/forge-core/src/store/account_tokens.rs index f0e56dd..606bd41 100644 --- a/crates/forge-core/src/store/account_tokens.rs +++ b/crates/forge-core/src/store/account_tokens.rs @@ -300,14 +300,14 @@ impl Store { about: String::new(), timezone: "UTC".to_owned(), avatar_hash: None, - theme: "auto".into(), + theme: "light".into(), language: "auto".into(), kind: AccountKind::User, email_notifications: true, }; tx.execute( "INSERT INTO users (id, username, username_folded, email, password_hash, is_admin, \ - created_at, email_verified_at) VALUES (?1, ?2, ?3, ?4, ?5, 0, ?6, ?6)", + created_at, email_verified_at, theme) VALUES (?1, ?2, ?3, ?4, ?5, 0, ?6, ?6, 'light')", ( user.id.clone(), user.username.clone(), diff --git a/crates/forge-core/src/store/migrate.rs b/crates/forge-core/src/store/migrate.rs index 48fdab8..3e87702 100644 --- a/crates/forge-core/src/store/migrate.rs +++ b/crates/forge-core/src/store/migrate.rs @@ -51,6 +51,10 @@ pub const MIGRATIONS: &[(u32, &str)] = &[ 35, include_str!("../../migrations/0035_email_notifications.sql"), ), + ( + 36, + include_str!("../../migrations/0036_default_light_theme.sql"), + ), ]; /// The highest migration version this binary knows about. diff --git a/crates/forge-core/src/store/mod.rs b/crates/forge-core/src/store/mod.rs index 69c81e4..a140daf 100644 --- a/crates/forge-core/src/store/mod.rs +++ b/crates/forge-core/src/store/mod.rs @@ -174,15 +174,15 @@ impl Store { about: String::new(), timezone: "UTC".to_string(), avatar_hash: None, - theme: "auto".into(), + theme: "light".into(), language: "auto".into(), kind: AccountKind::User, email_notifications: true, }; let conn = self.inner.conn.lock().await; conn.execute( - "INSERT INTO users (id, username, username_folded, email, password_hash, is_admin, created_at) \ - VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)", + "INSERT INTO users (id, username, username_folded, email, password_hash, is_admin, created_at, theme) \ + VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, 'light')", ( user.id.clone(), user.username.clone(), @@ -216,7 +216,7 @@ impl Store { about: String::new(), timezone: "UTC".to_string(), avatar_hash: None, - theme: "auto".into(), + theme: "light".into(), language: "auto".into(), kind: AccountKind::User, email_notifications: true, @@ -224,8 +224,8 @@ impl Store { let conn = self.inner.conn.lock().await; let inserted = conn .execute( - "INSERT INTO users (id, username, username_folded, email, password_hash, is_admin, created_at) \ - SELECT ?1, ?2, ?3, ?4, ?5, 1, ?6 WHERE NOT EXISTS (SELECT 1 FROM users)", + "INSERT INTO users (id, username, username_folded, email, password_hash, is_admin, created_at, theme) \ + SELECT ?1, ?2, ?3, ?4, ?5, 1, ?6, 'light' WHERE NOT EXISTS (SELECT 1 FROM users)", ( user.id.clone(), user.username.clone(), diff --git a/crates/forge-core/src/store/ui_prefs.rs b/crates/forge-core/src/store/ui_prefs.rs index f6db206..8c8ffb2 100644 --- a/crates/forge-core/src/store/ui_prefs.rs +++ b/crates/forge-core/src/store/ui_prefs.rs @@ -97,7 +97,7 @@ mod tests { .unwrap(); assert_eq!( store.user_by_id(&user.id).await.unwrap().unwrap().theme, - "auto" + "light" ); store.set_ui_prefs(&user.id, "dark", "tr").await.unwrap(); diff --git a/crates/forge-core/src/store/user_delete.rs b/crates/forge-core/src/store/user_delete.rs index 3082a4c..3592c79 100644 --- a/crates/forge-core/src/store/user_delete.rs +++ b/crates/forge-core/src/store/user_delete.rs @@ -162,14 +162,14 @@ impl Store { about: String::new(), timezone: "UTC".to_string(), avatar_hash: None, - theme: "auto".into(), + theme: "light".into(), language: "auto".into(), kind: AccountKind::User, email_notifications: true, }; conn.execute( - "INSERT INTO users (id, username, username_folded, email, password_hash, is_admin, created_at) \ - VALUES (?1, ?2, ?3, NULL, ?4, 0, ?5)", + "INSERT INTO users (id, username, username_folded, email, password_hash, is_admin, created_at, theme) \ + VALUES (?1, ?2, ?3, NULL, ?4, 0, ?5, 'light')", ( user.id.clone(), user.username.clone(), diff --git a/crates/forge-web/src/pages/discussion_view.rs b/crates/forge-web/src/pages/discussion_view.rs index f1cf892..6fb8f19 100644 --- a/crates/forge-web/src/pages/discussion_view.rs +++ b/crates/forge-web/src/pages/discussion_view.rs @@ -24,7 +24,7 @@ use crate::pages::repo_ctx::{RepoCtx, load_repo}; use crate::pages::tree::link_context; use crate::render::markdown::{LinkContext, render_markdown}; use crate::state::AppState; -use crate::views::{avatar_url, display_name, now_unix, shell}; +use crate::views::{avatar_url, display_name, now_unix, shell, user_href, user_link}; path_param!(owner); path_param!(repo); @@ -35,6 +35,8 @@ pub(crate) struct CommentView { lang: Lang, anchor: String, author: String, + /// The author's username, the link target of the name and avatar. + login: String, avatar: String, when: When, /// Rendered Markdown. Empty when the comment is deleted. @@ -116,6 +118,7 @@ fn comment_view( lang: frame.lang, anchor: format!("comment-{}", c.id), author: display_name(frame.lang, &username), + login: username.clone(), avatar: avatar_url(&username, hash.as_deref()), when: When::new(frame.lang, &c.created_at, &frame.tz, frame.now), html: if live { @@ -151,6 +154,7 @@ async fn comment_article(item: CommentView) -> Result { lang, anchor, author, + login, avatar, when, html, @@ -167,6 +171,7 @@ async fn comment_article(item: CommentView) -> Result { csrf, reactions, } = item; + let profile = user_href(&login); let class = if accepted { "issue-item discussion-accepted" } else { @@ -178,8 +183,8 @@ async fn comment_article(item: CommentView) -> Result { if deleted { (g::t(lang, K::CommentDeleted)) } else { - - (author.as_str()) + + user_link(shown: author.as_str(), login: login.as_str()) } if accepted { @@ -353,6 +358,8 @@ async fn discussion_page( .unwrap_or_else(|| ("ghost".to_owned(), None)); let author = display_name(lang, &author_name); let author_avatar = avatar_url(&author_name, author_hash.as_deref()); + let author_profile = user_href(&author_name); + let author_login = author_name.clone(); let opened = When::new(lang, &discussion.created_at, &tz, now); let body_source = if discussion.body.trim().is_empty() { g::t(lang, K::NoDescription) @@ -404,7 +411,7 @@ async fn discussion_page( if locked { " " (g::t(lang, K::Locked)) } - " " (author.as_str()) + " " user_link(shown: author.as_str(), login: author_login.as_str()) (g::t(lang, K::OpenedThis)) (g::t(lang, K::OpenedSeparator)) @@ -415,8 +422,8 @@ async fn discussion_page(
- - (author.as_str()) + + user_link(shown: author.as_str(), login: author_login.as_str())
(Unescaped::new_unchecked(body_html))
if let Some(bar) = body_bar { diff --git a/crates/forge-web/src/pages/discussions.rs b/crates/forge-web/src/pages/discussions.rs index 80c449f..2391ce4 100644 --- a/crates/forge-web/src/pages/discussions.rs +++ b/crates/forge-web/src/pages/discussions.rs @@ -26,7 +26,7 @@ use crate::pages::repo::repo_head; use crate::pages::repo_ctx::{RepoCtx, RepoHead, load_repo}; use crate::render::markdown::mentioned_usernames; use crate::state::AppState; -use crate::views::{alert, csrf_field, now_unix, repo_href, shell}; +use crate::views::{alert, csrf_field, now_unix, repo_href, shell, user_link}; path_param!(owner); path_param!(repo); @@ -327,7 +327,7 @@ async fn discussions_list_page(cx: &Cx) -> Result {
(by_before) - (row.author.as_str()) + user_link(shown: row.author.as_str(), login: row.author.as_str()) (by_middle) if !by_after.is_empty() { diff --git a/crates/forge-web/src/pages/issue_parts.rs b/crates/forge-web/src/pages/issue_parts.rs index f157300..94dd294 100644 --- a/crates/forge-web/src/pages/issue_parts.rs +++ b/crates/forge-web/src/pages/issue_parts.rs @@ -28,6 +28,7 @@ use crate::views::review_thread::{ThreadCtx, review_thread_in}; use crate::views::user_facing_message; use crate::views::{ alert, avatar_url, display_name, iso_time, now_unix, relative_time, repo_href, short_oid, + user_href, user_link, }; use crate::webhooks::emit::{Sender, emit_comment, emit_item_action}; @@ -220,6 +221,8 @@ pub(crate) fn is_hex_oid(s: &str) -> bool { pub(crate) struct CommentView { anchor: String, author: String, + /// The author's username, the link target of the name and avatar. + login: String, avatar: String, when: When, html: String, @@ -269,6 +272,7 @@ pub(crate) struct EventLine { pub(crate) struct ReviewView { anchor: String, author: String, + login: String, avatar: String, when: When, verb: &'static str, @@ -289,6 +293,8 @@ pub(crate) enum Entry { pub(crate) struct Discussion { /// The item's author, by display name, and when it was opened. pub(crate) author: String, + /// The author's username, for the profile link. + pub(crate) author_login: String, pub(crate) opened: When, pub(crate) body: CommentView, pub(crate) entries: Vec, @@ -380,6 +386,7 @@ pub(crate) async fn comment_item(lang: Lang, item: CommentView) -> Result Result
- - (author.as_str()) + + user_link(shown: author.as_str(), login: login.as_str()) if let Some(href) = history_href { (g::t(lang, K::Edited)) @@ -538,6 +546,7 @@ pub(crate) async fn review_item(lang: Lang, review: ReviewView) -> Result Result Result
- - (author.as_str()) + + user_link(shown: author.as_str(), login: login.as_str()) (verb)
@@ -679,6 +689,7 @@ pub(crate) async fn load_discussion( let body = CommentView { anchor: body_anchor, author: display_name(lang, &author), + login: author.clone(), avatar: avatar_url(&author, author_hash.as_deref()), when: opened.clone(), html: render_markdown(body_source, Some(&link)), @@ -712,6 +723,7 @@ pub(crate) async fn load_discussion( let item_view = CommentView { anchor: format!("comment-{}", comment.id), author: display_name(lang, &who_name), + login: who_name.clone(), avatar: avatar_url(&who_name, hash.as_deref()), when: When::new(lang, &comment.created_at, &tz, now), html: render_markdown(&comment.body, Some(&link)), @@ -751,6 +763,7 @@ pub(crate) async fn load_discussion( Ok(Discussion { author: display_name(lang, &author), + author_login: author, opened, body, entries, @@ -891,6 +904,7 @@ async fn review_entries( let view = ReviewView { anchor: format!("review-{}", review.id), author: display_name(lang, &review.author_name), + login: review.author_name.clone(), avatar: avatar_url(&review.author_name, None), when: When::new(lang, &stamp, tz, now), verb, diff --git a/crates/forge-web/src/pages/issue_view.rs b/crates/forge-web/src/pages/issue_view.rs index 689ddbd..d1c5387 100644 --- a/crates/forge-web/src/pages/issue_view.rs +++ b/crates/forge-web/src/pages/issue_view.rs @@ -29,7 +29,7 @@ use crate::pages::notifications::notify_box_for; use crate::pages::repo::repo_head; use crate::pages::repo_ctx::{RepoCtx, load_repo}; use crate::state::AppState; -use crate::views::{alert, repo_href, shell, user_facing_message}; +use crate::views::{alert, repo_href, shell, user_facing_message, user_link}; use crate::webhooks::emit::{Sender, emit_comment, emit_item_action}; path_param!(owner); @@ -59,6 +59,7 @@ async fn issue_page( let pin_action = format!("{issue_href}/pin"); let notify = notify_box_for(state, &ctx, lang, &issue.id, &issue_href).await?; let author = discussion.author.clone(); + let author_login = discussion.author_login.clone(); let opened = discussion.opened.clone(); let csrf = csrf_of(&ctx); @@ -94,7 +95,7 @@ async fn issue_page(

(issue.title.as_str()) " " (number_label.as_str())

(row.number_text.as_str()) if lang == Lang::Tr { - (row.author.as_str()) + user_link(shown: row.author.as_str(), login: row.author.as_str()) (g::t(lang, K::By)) (g::t(lang, K::Opened)) @@ -497,7 +497,7 @@ async fn issues_list_page(cx: &Cx) -> Result { (g::t(lang, K::Opened)) (g::t(lang, K::By)) - (row.author.as_str()) + user_link(shown: row.author.as_str(), login: row.author.as_str()) } if let Some(milestone) = row.milestone.clone() { (milestone.title.as_str()) diff --git a/crates/forge-web/src/pages/pull_view.rs b/crates/forge-web/src/pages/pull_view.rs index 4fed84f..65e30d3 100644 --- a/crates/forge-web/src/pages/pull_view.rs +++ b/crates/forge-web/src/pages/pull_view.rs @@ -41,7 +41,7 @@ use crate::pages::repo_ctx::{RepoCtx, load_repo}; use crate::state::AppState; use crate::views::commit_status::{StatusLang, StatusSummary, checks_summary, commit_status}; use crate::views::diff::LIMITS; -use crate::views::{alert, now_unix, repo_href, shell, short_oid}; +use crate::views::{alert, now_unix, repo_href, shell, short_oid, user_link}; path_param!(owner); path_param!(repo); @@ -108,6 +108,7 @@ pub(crate) struct Frame { pub(crate) page_title: String, pub(crate) href: String, author: String, + author_known: bool, opened: When, pub(crate) commit_count: usize, pub(crate) file_count: usize, @@ -135,6 +136,7 @@ pub(crate) async fn frame_in( .store .usernames_by_ids(std::slice::from_ref(&pr.issue.author_id)) .await?; + let author_known = users.contains_key(&pr.issue.author_id); let author = users .get(&pr.issue.author_id) .map(|(display, _)| display.clone()) @@ -165,6 +167,7 @@ pub(crate) async fn frame_in( page_title: format!("{} #{number} \u{b7} {owner}/{name}", pr.issue.title), href: repo_href(&owner, &name, "pulls", &number.to_string()), author, + author_known, opened: When::new(lang, &pr.issue.created_at, ctx.viewer_tz(), now_unix()), commit_count, file_count, @@ -183,6 +186,7 @@ pub(crate) async fn pull_header(frame: Frame) -> Result { state_class, state_text, author, + author_known, opened, commit_count, base_branch, @@ -203,7 +207,13 @@ pub(crate) async fn pull_header(frame: Frame) -> Result {

(title.as_str()) " " (number_label.as_str())

- (prefix) (who.as_str()) (middle) + (prefix) user_link(shown: who.as_str(), login: who.as_str()) (middle) if !commit.is_empty() { (as_sep) diff --git a/crates/forge-web/src/pages/pulls_list.rs b/crates/forge-web/src/pages/pulls_list.rs index 7a0dbf1..33ad732 100644 --- a/crates/forge-web/src/pages/pulls_list.rs +++ b/crates/forge-web/src/pages/pulls_list.rs @@ -21,7 +21,7 @@ use crate::pages::issues_list::{ use crate::pages::repo::repo_head; use crate::pages::repo_ctx::load_repo; use crate::state::AppState; -use crate::views::{avatar_url, iso_time, now_unix, relative_time, repo_href, shell}; +use crate::views::{avatar_url, iso_time, now_unix, relative_time, repo_href, shell, user_link}; path_param!(owner); path_param!(repo); @@ -279,14 +279,14 @@ async fn pulls_list_page(cx: &Cx) -> Result { (row.number_text.as_str()) if lang == Lang::Tr { (g::t(lang, K::MetaBeforeTime)) - (row.author.as_str()) + user_link(shown: row.author.as_str(), login: row.author.as_str()) (g::t(lang, K::MetaAfterTime)) } else { (g::t(lang, K::MetaBeforeTime)) (g::t(lang, K::MetaAfterTime)) - (row.author.as_str()) + user_link(shown: row.author.as_str(), login: row.author.as_str()) } if let Some(milestone) = row.milestone.clone() { (milestone.title.as_str()) diff --git a/crates/forge-web/src/pages/releases.rs b/crates/forge-web/src/pages/releases.rs index 098282a..74a180d 100644 --- a/crates/forge-web/src/pages/releases.rs +++ b/crates/forge-web/src/pages/releases.rs @@ -42,7 +42,7 @@ use crate::pages::repo_mirrors::stamp_in_tz; use crate::post_update::after_ref_update; use crate::render::markdown::render_markdown; use crate::state::AppState; -use crate::views::{alert, enc, shell, user_facing_message}; +use crate::views::{alert, enc, shell, user_facing_message, user_link}; use crate::webhooks::emit::{Sender, emit}; path_param!(owner); @@ -506,7 +506,7 @@ async fn list_body( (card.tag.as_str()) " \u{b7} " (card.when.as_str()) if !card.author.is_empty() { - " \u{b7} " (card.author.as_str()) + " \u{b7} " user_link(shown: card.author.as_str(), login: card.author.as_str()) }

if !card.body.is_empty() { @@ -838,7 +838,7 @@ async fn release_tag_page(cx: &Cx) -> Result { (card.tag.as_str()) " \u{b7} " (card.when.as_str()) if !card.author.is_empty() { - " \u{b7} " (card.author.as_str()) + " \u{b7} " user_link(shown: card.author.as_str(), login: card.author.as_str()) }

if !body_html.is_empty() { diff --git a/crates/forge-web/src/pages/repo.rs b/crates/forge-web/src/pages/repo.rs index 1c46d1c..d293de7 100644 --- a/crates/forge-web/src/pages/repo.rs +++ b/crates/forge-web/src/pages/repo.rs @@ -30,7 +30,7 @@ use crate::pages::tree::{ entry_rows, last_commits, load_readme, read_dir, readme_card, tree_table, }; use crate::state::AppState; -use crate::views::{now_unix, relative_time, repo_href, repo_tabs, shell}; +use crate::views::{now_unix, relative_time, repo_href, repo_tabs, shell, user_link}; path_param!(owner); path_param!(repo); @@ -84,7 +84,9 @@ pub async fn repo_head(head: RepoHead) -> Result { security, lang, } = head; - let title = format!("{owner}/{name}"); + // The title gets its own copies: the view below moves `owner` and `name` into `repo_tabs`. + let title_owner = owner.clone(); + let title_name = name.clone(); let badge = badge_class(visibility); let vis = i18n::visibility_label(lang, visibility); let active = active.to_owned(); @@ -136,7 +138,7 @@ pub async fn repo_head(head: RepoHead) -> Result {
-

(title.as_str())

+

user_link(shown: title_owner.as_str(), login: title_owner.as_str()) "/" (title_name.as_str())

(vis)
if let Some((href, label)) = fork_line { diff --git a/crates/forge-web/src/pages/settings_appearance.rs b/crates/forge-web/src/pages/settings_appearance.rs index 3da3f2c..de6ebc6 100644 --- a/crates/forge-web/src/pages/settings_appearance.rs +++ b/crates/forge-web/src/pages/settings_appearance.rs @@ -66,9 +66,14 @@ fn language_label(lang: Lang, code: &str) -> &'static str { } } +/// The label of a theme code. Light is the default for everyone who has not chosen, so it is +/// marked as the default. fn theme_label(lang: Lang, code: &str) -> &'static str { match code { - "light" => g::t(lang, K::Light), + "light" => match lang { + Lang::En => "Light (default)", + Lang::Tr => "A\u{e7}\u{131}k (varsay\u{131}lan)", + }, "dark" => g::t(lang, K::Dark), _ => g::t(lang, K::MatchSystem), } @@ -232,6 +237,15 @@ mod tests { fn labels_follow_the_page_language() { assert_eq!(theme_label(Lang::En, "dark"), "Dark"); assert_eq!(theme_label(Lang::Tr, "dark"), "Koyu"); + } + + #[test] + fn light_is_marked_as_the_default() { + assert_eq!(theme_label(Lang::En, "light"), "Light (default)"); + assert_eq!( + theme_label(Lang::Tr, "light"), + "A\u{e7}\u{131}k (varsay\u{131}lan)" + ); assert_eq!(language_label(Lang::Tr, "tr"), "T\u{fc}rk\u{e7}e"); } } diff --git a/crates/forge-web/src/theme.rs b/crates/forge-web/src/theme.rs index 7446ad4..1af081b 100644 --- a/crates/forge-web/src/theme.rs +++ b/crates/forge-web/src/theme.rs @@ -1,6 +1,7 @@ //! The colour theme for a request. A signed-in user's stored preference wins. Anonymous -//! visitors use the `forge_theme` cookie, which the footer form sets. `auto`, or no choice at -//! all, renders no `data-theme`, so the stylesheet follows the operating system. +//! visitors use the `forge_theme` cookie, which the footer form sets. The default is light: a +//! visitor with no explicit choice gets light whatever their operating system uses. Only an +//! explicit `auto` renders no `data-theme`, so the stylesheet follows the operating system. use std::time::Duration; @@ -15,8 +16,8 @@ pub const THEME_COOKIE: &str = "forge_theme"; pub const THEME_COOKIE_TTL: Duration = Duration::from_secs(365 * 24 * 60 * 60); /// The stored colour preference for this request: `"auto"`, `"light"` or `"dark"`. A signed-in -/// user's stored preference wins. Anonymous visitors use the cookie. Anything else reads as -/// `"auto"`. +/// user's stored preference wins. Anonymous visitors use the cookie. A missing, empty or +/// unknown value reads as `"light"`, the default. Only an explicit `"auto"` follows the system. pub fn preference(cx: &Cx, viewer: Option<&User>) -> &'static str { let stored = match viewer { Some(user) => user.theme.clone(), @@ -25,10 +26,16 @@ pub fn preference(cx: &Cx, viewer: Option<&User>) -> &'static str { .map(|cookie| cookie.value().to_owned()) .unwrap_or_default(), }; - match stored.as_str() { - "light" => "light", + resolve_preference(&stored) +} + +/// Maps a stored value to a preference. Only `"auto"` and `"dark"` are kept as they are. Every +/// other value, including the empty string, means the default, `"light"`. +pub fn resolve_preference(stored: &str) -> &'static str { + match stored { + "auto" => "auto", "dark" => "dark", - _ => "auto", + _ => "light", } } @@ -41,13 +48,14 @@ pub fn data_theme(cx: &Cx, viewer: Option<&User>) -> Option<&'static str> { } } -/// The preference the top-bar button switches to from `current`: auto, then light, then dark, -/// then back to auto. +/// The preference the top-bar button switches to from `current`: light, then dark, then auto, +/// then back to light. Anything that is not `"light"` or `"dark"` (including `"auto"`) moves on +/// to light, the first step of the cycle. pub fn next_preference(current: &str) -> &'static str { match current { - "auto" => "light", "light" => "dark", - _ => "auto", + "dark" => "auto", + _ => "light", } } @@ -68,18 +76,43 @@ pub fn set_theme_cookie(cx: &Cx, theme: &str) { #[cfg(test)] mod tests { - use super::next_preference; + use super::{next_preference, resolve_preference}; #[test] - fn the_toggle_cycles_auto_light_dark_auto() { - assert_eq!(next_preference("auto"), "light"); + fn the_toggle_cycles_light_dark_auto_light() { assert_eq!(next_preference("light"), "dark"); assert_eq!(next_preference("dark"), "auto"); + assert_eq!(next_preference("auto"), "light"); + } + + #[test] + fn unknown_preferences_move_on_to_light() { + assert_eq!(next_preference(""), "light"); + assert_eq!(next_preference("neon"), "light"); + } + + #[test] + fn no_choice_means_light() { + assert_eq!(resolve_preference(""), "light"); + assert_eq!(resolve_preference("neon"), "light"); + assert_eq!(resolve_preference("light"), "light"); + } + + #[test] + fn explicit_choices_are_kept() { + assert_eq!(resolve_preference("dark"), "dark"); + assert_eq!(resolve_preference("auto"), "auto"); } #[test] - fn unknown_preferences_start_the_cycle_at_auto() { - assert_eq!(next_preference(""), "auto"); - assert_eq!(next_preference("neon"), "auto"); + fn the_default_cycle_starts_on_light_and_reaches_every_choice() { + let start = resolve_preference(""); + assert_eq!(start, "light"); + assert_eq!(next_preference(start), "dark"); + assert_eq!(next_preference(next_preference(start)), "auto"); + assert_eq!( + next_preference(next_preference(next_preference(start))), + "light" + ); } } diff --git a/crates/forge-web/src/views/review_thread.rs b/crates/forge-web/src/views/review_thread.rs index eebeffd..c0255cd 100644 --- a/crates/forge-web/src/views/review_thread.rs +++ b/crates/forge-web/src/views/review_thread.rs @@ -14,7 +14,7 @@ use crate::i18n::Lang; use crate::i18n::pulls_review::{self as g, K}; use crate::pages::issue_parts::When; use crate::render::markdown::{LinkContext, render_markdown}; -use crate::views::{avatar_url, display_name, now_unix}; +use crate::views::{avatar_url, display_name, now_unix, user_href, user_link}; /// What a thread needs from its page: where the review POSTs go, the CSRF token, who is viewing /// and what they may do. Built once per page and cloned into each thread. @@ -45,6 +45,7 @@ pub struct ThreadCtx { #[derive(Clone)] struct CommentRow { author: String, + login: String, avatar: String, when: When, html: String, @@ -76,6 +77,7 @@ fn comment_row(comment: ReviewComment, ctx: &ThreadCtx, now: i64, lang: Lang) -> CommentRow { avatar: avatar_url(&comment.author_name, None), author: display_name(lang, &comment.author_name), + login: comment.author_name.clone(), when: When::new(lang, &comment.created_at, &ctx.tz, now), html: render_markdown(&comment.body, ctx.link.as_ref()), history_href: edited @@ -313,6 +315,7 @@ async fn thread_comment( ) -> Result { let CommentRow { author, + login, avatar, when, html, @@ -320,14 +323,15 @@ async fn thread_comment( edit_href, delete_href, } = comment; + let profile = user_href(&login); let edited = g::t(lang, K::Edited); let edit = g::t(lang, K::EditLink); let delete = g::t(lang, K::DeleteButton); Ok(view! {
- - (author.as_str()) + + user_link(shown: author.as_str(), login: login.as_str()) if let Some(href) = history_href { (edited) diff --git a/crates/forge-web/tests/community_i18n_e2e.rs b/crates/forge-web/tests/community_i18n_e2e.rs index 0189e23..3f30e1a 100644 --- a/crates/forge-web/tests/community_i18n_e2e.rs +++ b/crates/forge-web/tests/community_i18n_e2e.rs @@ -51,7 +51,7 @@ async fn snippets_page_follows_the_browser_language() { .expect("GET /snippets (tr)"); assert_eq!(turkish.status().as_u16(), 200); let body = turkish.text().await.expect("read body"); - assert!(body.contains(""), "html lang is tr"); + assert!(body.contains("Parçacıklar"), "Turkish heading"); assert!( body.contains("Gösterilecek parçacık yok."), diff --git a/crates/forge-web/tests/i18n_e2e.rs b/crates/forge-web/tests/i18n_e2e.rs index aee9a57..ed66f9f 100644 --- a/crates/forge-web/tests/i18n_e2e.rs +++ b/crates/forge-web/tests/i18n_e2e.rs @@ -179,7 +179,7 @@ async fn anonymous_pages_follow_the_browser_language() { .await; assert_eq!(turkish.status, 200); assert!( - turkish.body.contains(""), + turkish.body.contains(""), + english.body.contains("")); + assert!(plain.body.contains("")); + assert!(german.body.contains(""), "html lang is tr"); + assert!(page.body.contains(" .muted { font-size: 13px; @@ -262,7 +242,8 @@ } } -// Two columns at 1100px and up: the directory and README, then the repo-meta aside. +// Two columns at 900px and up: the directory and README take the remaining width, then a +// narrow repo-meta aside (about 230px). Below 900px the aside stacks under the main column. .repo-grid { display: grid; grid-template-columns: minmax(0, 1fr); @@ -303,9 +284,9 @@ } } -@media (min-width: 1100px) { +@media (min-width: 900px) { .repo-grid { - grid-template-columns: minmax(0, 1fr) 260px; + grid-template-columns: minmax(0, 1fr) 230px; gap: 40px; align-items: start; } @@ -554,7 +535,7 @@ display: flex; flex-direction: column; gap: 16px; - max-width: 880px; + max-width: 960px; width: 100%; min-width: 0; diff --git a/style/_shell.scss b/style/_shell.scss index 0749448..be1f944 100644 --- a/style/_shell.scss +++ b/style/_shell.scss @@ -344,7 +344,7 @@ box-sizing: border-box; width: 100%; min-width: 0; - max-width: 1100px; + max-width: 1280px; margin: 0 auto; padding: 24px 16px 48px; } diff --git a/style/main.scss b/style/main.scss index e80bae4..01048c5 100644 --- a/style/main.scss +++ b/style/main.scss @@ -283,7 +283,7 @@ pre { } .container { - max-width: 960px; + max-width: 1280px; margin: 0 auto; padding: 0 16px; } @@ -2110,7 +2110,7 @@ code { } .issue-new { - max-width: 48rem; + max-width: 60rem; textarea { min-height: 14rem; @@ -3166,23 +3166,135 @@ span.reaction { } } -.watch-form { +// Watch control: a dropdown whose summary shows the current level. Each level is a small POST form +// inside the menu; the current one carries a check mark. +.watch-control { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin: 0; +} - select { - padding: 0.3rem 0.5rem; - border: 1px solid var(--border); - border-radius: var(--radius); - background: var(--surface); +.watch-menu { + summary { + position: relative; + display: inline-flex; + align-items: center; + gap: 6px; + height: 28px; + padding: 0 26px 0 8px; + font-size: 13px; + font-weight: 500; color: var(--text); - font: inherit; + background: var(--surface); + border: 1px solid var(--border-strong); + white-space: nowrap; + + // The caret: a small rotated border, so no glyph is needed. + &::after { + content: ""; + position: absolute; + right: 11px; + top: 50%; + width: 5px; + height: 5px; + border-right: 1.5px solid currentColor; + border-bottom: 1.5px solid currentColor; + transform: translateY(-70%) rotate(45deg); + } + } + + &[open] summary { + border-color: var(--accent); + } +} + +.watch-eye { + flex: none; + width: 15px; + height: 15px; + fill: none; + stroke: currentColor; + stroke-width: 2; + stroke-linecap: round; + stroke-linejoin: round; +} + +.watch-list { + left: 0; + right: auto; + min-width: 280px; + max-width: calc(100vw - 24px); +} + +.watch-option-form { + margin: 0; +} + +.watch-list button.watch-option { + display: grid; + grid-template-columns: 18px 1fr; + gap: 2px 4px; + // The global button rule fixes the height at 34px and forbids wrapping, + // which made each description spill onto the next option. + height: auto; + white-space: normal; + width: 100%; + margin: 0; + padding: 8px 14px; + text-align: left; + font: inherit; + color: var(--text); + background: none; + border: 0; + border-radius: 0; + cursor: pointer; + + &:hover { + background: var(--surface-2); + } + + &:focus-visible { + outline: 2px solid var(--focus); + outline-offset: -2px; + } + + // The check mark, drawn with borders. Only the current level shows it. + &::before { + content: ""; + grid-column: 1; + grid-row: 1 / span 2; + justify-self: center; + align-self: start; + width: 5px; + height: 9px; + margin-top: 3px; + border: solid transparent; + border-width: 0 2px 2px 0; + transform: rotate(45deg); + } + + &.is-current::before { + border-color: var(--accent); } } +.watch-option-title { + grid-column: 2; + grid-row: 1; + font-weight: 500; +} + +.watch-option-desc { + grid-column: 2; + grid-row: 2; + font-size: 12px; + line-height: 1.4; + color: var(--muted); + white-space: normal; +} + @media (max-width: 40rem) { .notif-row { flex-direction: column; @@ -3246,7 +3358,7 @@ span.reaction { } .release-form { - max-width: 720px; + max-width: 960px; textarea { width: 100%; @@ -3891,3 +4003,34 @@ span.reaction { @import "repo"; @import "pull"; @import "dashboard"; + +// Code inside cards, notices and settings panels must stay inside the card. Long tokens and +// commands wrap instead of running past the right edge. The rendered README card (.readme) and +// file views, diffs and highlighted blobs are left alone so their code keeps horizontal scrolling. +.card:not(.readme), +.notice { + code { + overflow-wrap: anywhere; + word-break: normal; + } + + pre { + max-width: 100%; + margin: 0 0 12px; + padding: 12px; + overflow-x: auto; + white-space: pre-wrap; + overflow-wrap: anywhere; + background: var(--code-bg); + border: 1px solid var(--border); + border-radius: var(--radius); + color: var(--text); + + code { + padding: 0; + background: none; + white-space: inherit; + overflow-wrap: anywhere; + } + } +}