diff --git a/crates/forge-web/assets/nav.js b/crates/forge-web/assets/nav.js index dac1a43..2a0f978 100644 --- a/crates/forge-web/assets/nav.js +++ b/crates/forge-web/assets/nav.js @@ -843,6 +843,66 @@ window.addEventListener('resize', cornerApply); cornerApply(); + // Below 900px the profile corner covers the page the reader is reading, so it steps aside + // (corner-away) while they scroll down and comes back when they scroll up, near the top or at the + // end. It stays put while its menu, the bell popover or a drag is open. The scroll listener is on + // the document in the capture phase, so it survives a swap that replaces the body. Inner lists and + // log tails scroll on their own: their events are skipped, as the window's scroll targets the document. + var cornerNarrow = window.matchMedia ? window.matchMedia('(max-width: 899px)') : null; + var cornerY = window.scrollY; // the scroll position last seen + var cornerRun = 0; // the distance scrolled since the direction last turned + var cornerWant = false; // whether the corner should step aside + var CORNER_STEP = 8; // the run that hides the corner, or brings it back + var CORNER_TOP = 40; // within this of the top the corner always shows + + // True while the corner must stay in view: its menu is open, a bell popover is open, or it is dragged. + function cornerBusy(el) { + if (el.classList.contains('dragging')) { return true; } + if (document.querySelector('details.corner[open]')) { return true; } + return Array.prototype.some.call(document.querySelectorAll('.bell-pop'), isPeekOpen); + } + + // Applies the wanted state to the corner as it is now (a swap replaces it). Only below 900px. + function cornerAway() { + var el = cornerEl(); + if (!el) { return; } + var on = cornerWant && cornerNarrow && cornerNarrow.matches && !cornerBusy(el); + el.classList.toggle('corner-away', !!on); + } + + function cornerScrolled(e) { + if (e.target !== document) { return; } + var y = window.scrollY; + var dy = y - cornerY; + cornerY = y; + if (y <= CORNER_TOP || y >= document.documentElement.scrollHeight - window.innerHeight - 2) { + cornerRun = 0; + cornerWant = false; + } else { + // A run keeps its direction; a turn starts a new one. + cornerRun = (dy > 0 && cornerRun >= 0) || (dy < 0 && cornerRun <= 0) ? cornerRun + dy : dy; + if (cornerRun > CORNER_STEP) { cornerWant = true; } + else if (cornerRun < -CORNER_STEP) { cornerWant = false; } + } + cornerAway(); + } + + // A page swap moves the scroll (to the top on a link) before this runs, so the anchor is taken now. + // The corner keeps its state across a live refresh, and shows again at the top. + document.addEventListener('forge:swapped', function () { + cornerY = window.scrollY; + cornerRun = 0; + if (cornerY <= CORNER_TOP) { cornerWant = false; } + cornerAway(); + }); + // A menu, popover or details opened or closed may make the corner busy: it is checked again. + document.addEventListener('toggle', cornerAway, true); + window.addEventListener('resize', function () { + if (!cornerNarrow || !cornerNarrow.matches) { cornerWant = false; } + cornerAway(); + }); + document.addEventListener('scroll', cornerScrolled, { capture: true, passive: true }); + // The bell beside the profile corner opens a popover of the newest notifications instead of going // to the inbox. A plain click toggles it; with a modifier or a middle click the link's own // behaviour stays. The Popover API light-dismisses it and Escape closes it. Its list is fetched diff --git a/crates/forge-web/src/i18n/orgs.rs b/crates/forge-web/src/i18n/orgs.rs index 0a9cd1f..9e0335f 100644 --- a/crates/forge-web/src/i18n/orgs.rs +++ b/crates/forge-web/src/i18n/orgs.rs @@ -121,6 +121,7 @@ pub enum K { PinsTooMany, NoPinnableRepos, TabOverview, + TabContributions, Overview, TabStars, FilterRepos, @@ -375,6 +376,8 @@ pub fn t(lang: Lang, key: K) -> &'static str { (NoPinnableRepos, Tr) => "Henüz sabitlenecek depo yok.", (TabOverview, En) => "Overview", (TabOverview, Tr) => "Genel bakış", + (TabContributions, En) => "Contributions", + (TabContributions, Tr) => "Katkılar", (Overview, En) => "Overview", (Overview, Tr) => "Genel bakış", (TabStars, En) => "Stars", @@ -618,6 +621,7 @@ mod tests { K::PinsTooMany, K::NoPinnableRepos, K::TabOverview, + K::TabContributions, K::Overview, K::TabStars, K::FilterRepos, diff --git a/crates/forge-web/src/pages/profile.rs b/crates/forge-web/src/pages/profile.rs index 8487ee2..71c5342 100644 --- a/crates/forge-web/src/pages/profile.rs +++ b/crates/forge-web/src/pages/profile.rs @@ -1,7 +1,8 @@ //! Page: public profile at `/{username}`. Avatar, about (rendered markdown) and local time, then //! the tabs: `overview` (pinned repos, or the most recently active ones when nothing is pinned, -//! plus an organization's members and teams, or a person's contribution calendar), `repositories`, -//! `snippets` (people only), `stars`, `packages` and `organizations` (the viewer's own only). The +//! plus an organization's members and teams), `contributions` (people only: the contribution +//! calendar and the selected day's list), `repositories`, `snippets` (people only), `stars`, +//! `packages` and `organizations` (the viewer's own only). The //! repo tabs list what the viewer is allowed to read, 30 per page, with a name filter and three //! sort orders; the filtering, sorting and paging run in the database. Fixed single-segment routes //! are registered statically, so they win over this parameter route. @@ -55,7 +56,7 @@ struct ProfileQuery { q: Option, sort: Option, page: Option, - /// A calendar day whose contributions to list under the calendar on the overview. + /// A calendar day whose contributions to list under the calendar on the contributions tab. day: Option, } @@ -99,10 +100,14 @@ async fn profile_page(cx: &Cx) -> Result { let lang = i18n::lang(cx, actor); // Whether the viewer is this person. Only the person sees their Organizations tab and edit links. let own =!user.is_org() && actor.is_some_and(|u| u.id == user.id); - // An organization cannot be starred or keep snippets, so those tabs show the overview instead. - // The Organizations tab is the viewer's own, so anyone else gets the overview. - let tab = tab_key(query.tab.as_deref()); - let tab = if (user.is_org() && matches!(tab, "stars" | "snippets")) + // A `?day=` link with no tab predates the Contributions tab, so it opens that tab. + let tab = match query.tab.as_deref() { + None if query.day.is_some() => "contributions", + raw => tab_key(raw), + }; + // An organization cannot be starred, keep snippets or have a calendar, so those tabs show the + // overview instead. The Organizations tab is the viewer's own, so anyone else gets the overview. + let tab = if (user.is_org() && matches!(tab, "stars" | "snippets" | "contributions")) || (tab == "organizations" && !own) { "overview" @@ -182,9 +187,9 @@ async fn profile_page(cx: &Cx) -> Result { } }); - // The overview's contribution calendar, for a person only. Its counts and day links use public + // The contribution calendar on its tab, for a person only. Its counts and day links use public // repos alone, so anyone may see it. - let heat = if tab == "overview" && !user.is_org() { + let heat = if tab == "contributions" && !user.is_org() { Some(load_calendar(state, &user, query.day.as_deref()).await?) } else { None @@ -378,7 +383,7 @@ async fn profile_fingerprint( let teams = state.store.teams_for_org(&user.id).await?.len(); lines.push(format!("org {members} {teams}")); } else { - // A person's overview shows the contribution calendar, so its total moves with each one. + // The Contributions tab shows a person's calendar, so its total moves with each one. let total: u64 = state .store .contribution_counts(&user.id, &calendar_since(), &user.timezone) @@ -451,6 +456,7 @@ struct Listing { fn tab_key(raw: Option<&str>) -> &'static str { match raw { Some("repositories") => "repositories", + Some("contributions") => "contributions", Some("snippets") => "snippets", Some("stars") => "stars", Some("packages") => "packages", @@ -569,6 +575,8 @@ async fn profile_card( let is_org = user.is_org(); let base = format!("/{}", enc(&user.username)); let overview_on = tab == "overview"; + let contributions_on = tab == "contributions"; + let contributions_href = profile_href(&user.username, "contributions", "", SORTS[0].0, 1); let repos_on = tab == "repositories"; let stars_on = tab == "stars"; let list_on = repos_on || stars_on; @@ -623,14 +631,9 @@ async fn profile_card( if edit_profile { (edit_label) } - if is_org && (org_can_create || org_owner) { + if is_org && org_can_create {
- if org_can_create { - (g::t(lang, K::NewRepository)) - } - if org_owner { - (g::t(lang, K::Settings)) - } + (g::t(lang, K::NewRepository))
} @@ -640,6 +643,9 @@ async fn profile_card( }