The contribution calendar moves from the profile overview to its own Contributions tab, so the overview fits one screen, and an old ?day= link opens that tab
Browse files at this commit8e56ffc5ba761d68f2909dedfcd96dcedc76f102Parent: c812504- style
- the contribution calendar moves from the profile overview to its own Contributions tab, so the overview fits one screen, and an old ?day= link opens that tab
- an organization's header drops its Settings button, which repeated the Settings tab
- below 900px the floating profile panel fades away while the reader scrolls down and comes back on scrolling up, near the top or at the end of the page, and stays while its menu, the bell popover or a drag is open
5 changed files +128 -28
- crates/forge-web/assets/nav.js +60 -0
- crates/forge-web/src/i18n/orgs.rs +4 -0
- crates/forge-web/src/pages/profile.rs +41 -20
- crates/forge-web/src/views/heatmap.rs +8 -8
- style/_shell.scss +15 -0
crates/forge-web/assets/nav.jsmodified+60 -0
| @@ -843,6 +843,66 @@ | ||
| 843 | 843 | window.addEventListener('resize', cornerApply); |
| 844 | 844 | cornerApply(); |
| 845 | 845 | |
| 846 | + // Below 900px the profile corner covers the page the reader is reading, so it steps aside | |
| 847 | + // (corner-away) while they scroll down and comes back when they scroll up, near the top or at the | |
| 848 | + // end. It stays put while its menu, the bell popover or a drag is open. The scroll listener is on | |
| 849 | + // the document in the capture phase, so it survives a swap that replaces the body. Inner lists and | |
| 850 | + // log tails scroll on their own: their events are skipped, as the window's scroll targets the document. | |
| 851 | + var cornerNarrow = window.matchMedia ? window.matchMedia('(max-width: 899px)') : null; | |
| 852 | + var cornerY = window.scrollY; // the scroll position last seen | |
| 853 | + var cornerRun = 0; // the distance scrolled since the direction last turned | |
| 854 | + var cornerWant = false; // whether the corner should step aside | |
| 855 | + var CORNER_STEP = 8; // the run that hides the corner, or brings it back | |
| 856 | + var CORNER_TOP = 40; // within this of the top the corner always shows | |
| 857 | + | |
| 858 | + // True while the corner must stay in view: its menu is open, a bell popover is open, or it is dragged. | |
| 859 | + function cornerBusy(el) { | |
| 860 | + if (el.classList.contains('dragging')) { return true; } | |
| 861 | + if (document.querySelector('details.corner[open]')) { return true; } | |
| 862 | + return Array.prototype.some.call(document.querySelectorAll('.bell-pop'), isPeekOpen); | |
| 863 | + } | |
| 864 | + | |
| 865 | + // Applies the wanted state to the corner as it is now (a swap replaces it). Only below 900px. | |
| 866 | + function cornerAway() { | |
| 867 | + var el = cornerEl(); | |
| 868 | + if (!el) { return; } | |
| 869 | + var on = cornerWant && cornerNarrow && cornerNarrow.matches && !cornerBusy(el); | |
| 870 | + el.classList.toggle('corner-away', !!on); | |
| 871 | + } | |
| 872 | + | |
| 873 | + function cornerScrolled(e) { | |
| 874 | + if (e.target !== document) { return; } | |
| 875 | + var y = window.scrollY; | |
| 876 | + var dy = y - cornerY; | |
| 877 | + cornerY = y; | |
| 878 | + if (y <= CORNER_TOP || y >= document.documentElement.scrollHeight - window.innerHeight - 2) { | |
| 879 | + cornerRun = 0; | |
| 880 | + cornerWant = false; | |
| 881 | + } else { | |
| 882 | + // A run keeps its direction; a turn starts a new one. | |
| 883 | + cornerRun = (dy > 0 && cornerRun >= 0) || (dy < 0 && cornerRun <= 0) ? cornerRun + dy : dy; | |
| 884 | + if (cornerRun > CORNER_STEP) { cornerWant = true; } | |
| 885 | + else if (cornerRun < -CORNER_STEP) { cornerWant = false; } | |
| 886 | + } | |
| 887 | + cornerAway(); | |
| 888 | + } | |
| 889 | + | |
| 890 | + // A page swap moves the scroll (to the top on a link) before this runs, so the anchor is taken now. | |
| 891 | + // The corner keeps its state across a live refresh, and shows again at the top. | |
| 892 | + document.addEventListener('forge:swapped', function () { | |
| 893 | + cornerY = window.scrollY; | |
| 894 | + cornerRun = 0; | |
| 895 | + if (cornerY <= CORNER_TOP) { cornerWant = false; } | |
| 896 | + cornerAway(); | |
| 897 | + }); | |
| 898 | + // A menu, popover or details opened or closed may make the corner busy: it is checked again. | |
| 899 | + document.addEventListener('toggle', cornerAway, true); | |
| 900 | + window.addEventListener('resize', function () { | |
| 901 | + if (!cornerNarrow || !cornerNarrow.matches) { cornerWant = false; } | |
| 902 | + cornerAway(); | |
| 903 | + }); | |
| 904 | + document.addEventListener('scroll', cornerScrolled, { capture: true, passive: true }); | |
| 905 | + | |
| 846 | 906 | // The bell beside the profile corner opens a popover of the newest notifications instead of going |
| 847 | 907 | // to the inbox. A plain click toggles it; with a modifier or a middle click the link's own |
| 848 | 908 | // behaviour stays. The Popover API light-dismisses it and Escape closes it. Its list is fetched |
crates/forge-web/src/i18n/orgs.rsmodified+4 -0
| @@ -121,6 +121,7 @@ pub enum K { | ||
| 121 | 121 | PinsTooMany, |
| 122 | 122 | NoPinnableRepos, |
| 123 | 123 | TabOverview, |
| 124 | + TabContributions, | |
| 124 | 125 | Overview, |
| 125 | 126 | TabStars, |
| 126 | 127 | FilterRepos, |
| @@ -375,6 +376,8 @@ pub fn t(lang: Lang, key: K) -> &'static str { | ||
| 375 | 376 | (NoPinnableRepos, Tr) => "Henüz sabitlenecek depo yok.", |
| 376 | 377 | (TabOverview, En) => "Overview", |
| 377 | 378 | (TabOverview, Tr) => "Genel bakış", |
| 379 | + (TabContributions, En) => "Contributions", | |
| 380 | + (TabContributions, Tr) => "Katkılar", | |
| 378 | 381 | (Overview, En) => "Overview", |
| 379 | 382 | (Overview, Tr) => "Genel bakış", |
| 380 | 383 | (TabStars, En) => "Stars", |
| @@ -618,6 +621,7 @@ mod tests { | ||
| 618 | 621 | K::PinsTooMany, |
| 619 | 622 | K::NoPinnableRepos, |
| 620 | 623 | K::TabOverview, |
| 624 | + K::TabContributions, | |
| 621 | 625 | K::Overview, |
| 622 | 626 | K::TabStars, |
| 623 | 627 | K::FilterRepos, |
crates/forge-web/src/pages/profile.rsmodified+41 -20
| @@ -1,7 +1,8 @@ | ||
| 1 | 1 | //! Page: public profile at `/{username}`. Avatar, about (rendered markdown) and local time, then |
| 2 | 2 | //! the tabs: `overview` (pinned repos, or the most recently active ones when nothing is pinned, |
| 3 | -//! plus an organization's members and teams, or a person's contribution calendar), `repositories`, | |
| 4 | -//! `snippets` (people only), `stars`, `packages` and `organizations` (the viewer's own only). The | |
| 3 | +//! plus an organization's members and teams), `contributions` (people only: the contribution | |
| 4 | +//! calendar and the selected day's list), `repositories`, `snippets` (people only), `stars`, | |
| 5 | +//! `packages` and `organizations` (the viewer's own only). The | |
| 5 | 6 | //! repo tabs list what the viewer is allowed to read, 30 per page, with a name filter and three |
| 6 | 7 | //! sort orders; the filtering, sorting and paging run in the database. Fixed single-segment routes |
| 7 | 8 | //! are registered statically, so they win over this parameter route. |
| @@ -55,7 +56,7 @@ struct ProfileQuery { | ||
| 55 | 56 | q: Option<String>, |
| 56 | 57 | sort: Option<String>, |
| 57 | 58 | page: Option<String>, |
| 58 | - /// A calendar day whose contributions to list under the calendar on the overview. | |
| 59 | + /// A calendar day whose contributions to list under the calendar on the contributions tab. | |
| 59 | 60 | day: Option<String>, |
| 60 | 61 | } |
| 61 | 62 | |
| @@ -99,10 +100,14 @@ async fn profile_page(cx: &Cx) -> Result<impl View> { | ||
| 99 | 100 | let lang = i18n::lang(cx, actor); |
| 100 | 101 | // Whether the viewer is this person. Only the person sees their Organizations tab and edit links. |
| 101 | 102 | let own =!user.is_org() && actor.is_some_and(|u| u.id == user.id); |
| 102 | - // An organization cannot be starred or keep snippets, so those tabs show the overview instead. | |
| 103 | - // The Organizations tab is the viewer's own, so anyone else gets the overview. | |
| 104 | - let tab = tab_key(query.tab.as_deref()); | |
| 105 | - let tab = if (user.is_org() && matches!(tab, "stars" | "snippets")) | |
| 103 | + // A `?day=` link with no tab predates the Contributions tab, so it opens that tab. | |
| 104 | + let tab = match query.tab.as_deref() { | |
| 105 | + None if query.day.is_some() => "contributions", | |
| 106 | + raw => tab_key(raw), | |
| 107 | + }; | |
| 108 | + // An organization cannot be starred, keep snippets or have a calendar, so those tabs show the | |
| 109 | + // overview instead. The Organizations tab is the viewer's own, so anyone else gets the overview. | |
| 110 | + let tab = if (user.is_org() && matches!(tab, "stars" | "snippets" | "contributions")) | |
| 106 | 111 | || (tab == "organizations" && !own) |
| 107 | 112 | { |
| 108 | 113 | "overview" |
| @@ -182,9 +187,9 @@ async fn profile_page(cx: &Cx) -> Result<impl View> { | ||
| 182 | 187 | } |
| 183 | 188 | }); |
| 184 | 189 | |
| 185 | - // The overview's contribution calendar, for a person only. Its counts and day links use public | |
| 190 | + // The contribution calendar on its tab, for a person only. Its counts and day links use public | |
| 186 | 191 | // repos alone, so anyone may see it. |
| 187 | - let heat = if tab == "overview" && !user.is_org() { | |
| 192 | + let heat = if tab == "contributions" && !user.is_org() { | |
| 188 | 193 | Some(load_calendar(state, &user, query.day.as_deref()).await?) |
| 189 | 194 | } else { |
| 190 | 195 | None |
| @@ -378,7 +383,7 @@ async fn profile_fingerprint( | ||
| 378 | 383 | let teams = state.store.teams_for_org(&user.id).await?.len(); |
| 379 | 384 | lines.push(format!("org {members} {teams}")); |
| 380 | 385 | } else { |
| 381 | - // A person's overview shows the contribution calendar, so its total moves with each one. | |
| 386 | + // The Contributions tab shows a person's calendar, so its total moves with each one. | |
| 382 | 387 | let total: u64 = state |
| 383 | 388 | .store |
| 384 | 389 | .contribution_counts(&user.id, &calendar_since(), &user.timezone) |
| @@ -451,6 +456,7 @@ struct Listing { | ||
| 451 | 456 | fn tab_key(raw: Option<&str>) -> &'static str { |
| 452 | 457 | match raw { |
| 453 | 458 | Some("repositories") => "repositories", |
| 459 | + Some("contributions") => "contributions", | |
| 454 | 460 | Some("snippets") => "snippets", |
| 455 | 461 | Some("stars") => "stars", |
| 456 | 462 | Some("packages") => "packages", |
| @@ -569,6 +575,8 @@ async fn profile_card( | ||
| 569 | 575 | let is_org = user.is_org(); |
| 570 | 576 | let base = format!("/{}", enc(&user.username)); |
| 571 | 577 | let overview_on = tab == "overview"; |
| 578 | + let contributions_on = tab == "contributions"; | |
| 579 | + let contributions_href = profile_href(&user.username, "contributions", "", SORTS[0].0, 1); | |
| 572 | 580 | let repos_on = tab == "repositories"; |
| 573 | 581 | let stars_on = tab == "stars"; |
| 574 | 582 | let list_on = repos_on || stars_on; |
| @@ -623,14 +631,9 @@ async fn profile_card( | ||
| 623 | 631 | if edit_profile { |
| 624 | 632 | <a class="button profile-edit" href="/settings/profile">(edit_label)</a> |
| 625 | 633 | } |
| 626 | - if is_org && (org_can_create || org_owner) { | |
| 634 | + if is_org && org_can_create { | |
| 627 | 635 | <div class="profile-org-actions"> |
| 628 | - if org_can_create { | |
| 629 | - <a class="button primary" href=(new_repo_href.as_str())>(g::t(lang, K::NewRepository))</a> | |
| 630 | - } | |
| 631 | - if org_owner { | |
| 632 | - <a class="button" href=(settings_href.as_str())>(g::t(lang, K::Settings))</a> | |
| 633 | - } | |
| 636 | + <a class="button primary" href=(new_repo_href.as_str())>(g::t(lang, K::NewRepository))</a> | |
| 634 | 637 | </div> |
| 635 | 638 | } |
| 636 | 639 | </div> |
| @@ -640,6 +643,9 @@ async fn profile_card( | ||
| 640 | 643 | } |
| 641 | 644 | <nav class="profile-tabs" aria-label=(user.username.as_str())> |
| 642 | 645 | <a class=(tab_class(overview_on)) href=(overview_href.as_str())>(g::t(lang, K::TabOverview))</a> |
| 646 | + if !is_org { | |
| 647 | + <a class=(tab_class(contributions_on)) href=(contributions_href.as_str())>(g::t(lang, K::TabContributions))</a> | |
| 648 | + } | |
| 643 | 649 | <a class=(tab_class(repos_on)) href=(repositories_href.as_str())> |
| 644 | 650 | (g::t(lang, K::Repositories)) " " <span class="tab-count">(repo_count_text.as_str())</span> |
| 645 | 651 | </a> |
| @@ -696,9 +702,6 @@ async fn profile_card( | ||
| 696 | 702 | empty_state(title: g::t(lang, K::NoVisibleRepos)) |
| 697 | 703 | } |
| 698 | 704 | </section> |
| 699 | - if let Some((calendar, selected)) = heat { | |
| 700 | - contribution_calendar(calendar: calendar, selected: selected, lang: lang, base: base.clone()) | |
| 701 | - } | |
| 702 | 705 | if let Some(summary) = org { |
| 703 | 706 | <section class="profile-org"> |
| 704 | 707 | <h2>(g::t(lang, K::Members))</h2> |
| @@ -715,6 +718,11 @@ async fn profile_card( | ||
| 715 | 718 | </section> |
| 716 | 719 | } |
| 717 | 720 | } |
| 721 | + if contributions_on { | |
| 722 | + if let Some((calendar, selected)) = heat { | |
| 723 | + contribution_calendar(calendar: calendar, selected: selected, lang: lang, base: base.clone()) | |
| 724 | + } | |
| 725 | + } | |
| 718 | 726 | if list_on { |
| 719 | 727 | <section class="repo-listing"> |
| 720 | 728 | if own_profile && repos_on { |
| @@ -1210,6 +1218,19 @@ mod tests { | ||
| 1210 | 1218 | ); |
| 1211 | 1219 | } |
| 1212 | 1220 | |
| 1221 | + /// The calendar sits on the Contributions tab, not the overview, and an old `?day=` link with no | |
| 1222 | + /// tab opens that tab. | |
| 1223 | + #[tokio::test] | |
| 1224 | + async fn contributions_tab_holds_the_calendar() { | |
| 1225 | + let site = seeded().await; | |
| 1226 | + let (_, overview) = get(&site.router, "/tahinli", None).await; | |
| 1227 | + assert!(!overview.contains("class=\"heat\""), "overview: no calendar"); | |
| 1228 | + let (_, tab) = get(&site.router, "/tahinli?tab=contributions", None).await; | |
| 1229 | + assert!(tab.contains("class=\"heat\""), "contributions: calendar"); | |
| 1230 | + let (_, old) = get(&site.router, "/tahinli?day=2020-01-01", None).await; | |
| 1231 | + assert!(old.contains("class=\"heat\""), "old day link: calendar"); | |
| 1232 | + } | |
| 1233 | + | |
| 1213 | 1234 | fn count(body: &str, needle: &str) -> usize { |
| 1214 | 1235 | body.matches(needle).count() |
| 1215 | 1236 | } |
crates/forge-web/src/views/heatmap.rsmodified+8 -8
| @@ -4,8 +4,8 @@ | ||
| 4 | 4 | //! `build` is pure date and streak maths over the counts from the store. `contribution_calendar` |
| 5 | 5 | //! draws it with classes only (CSP): the grid placement comes from CSS (`grid-auto-flow: column` |
| 6 | 6 | //! with seven rows), so every cell is an element and the blank slots keep the columns aligned. |
| 7 | -//! Each day is a link to `?day=` (a plain link, no script): the page then lists that day's | |
| 8 | -//! contributions under the calendar, and clicking the selected day again clears it. | |
| 7 | +//! Each day is a link to `?tab=contributions&day=` (a plain link, no script): the page then lists | |
| 8 | +//! that day's contributions under the calendar, and clicking the selected day again clears it. | |
| 9 | 9 | |
| 10 | 10 | use std::collections::HashMap; |
| 11 | 11 | |
| @@ -209,15 +209,15 @@ struct DayView { | ||
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | /// The link for a calendar day: the day's contributions below the calendar, or back to the |
| 212 | -/// plain calendar when the day is the selected one. `base` is the page the calendar sits on. The | |
| 213 | -/// anchor brings a full page load back to the calendar; nav.js swaps in place and keeps the scroll | |
| 214 | -/// (`data-keep-scroll`), so it is not used there. | |
| 212 | +/// plain calendar when the day is the selected one. `base` is the profile's path, without a query. | |
| 213 | +/// Both links stay on the Contributions tab. The anchor brings a full page load back to the | |
| 214 | +/// calendar; nav.js swaps in place and keeps the scroll (`data-keep-scroll`), so it is not used there. | |
| 215 | 215 | fn day_href(base: &str, date: (i64, i64, i64), selected: bool) -> String { |
| 216 | 216 | if selected { |
| 217 | - format!("{base}#contributions-h") | |
| 217 | + format!("{base}?tab=contributions#contributions-h") | |
| 218 | 218 | } else { |
| 219 | 219 | format!( |
| 220 | - "{base}?day={:04}-{:02}-{:02}#contributions-h", | |
| 220 | + "{base}?tab=contributions&day={:04}-{:02}-{:02}#contributions-h", | |
| 221 | 221 | date.0, date.1, date.2 |
| 222 | 222 | ) |
| 223 | 223 | } |
| @@ -336,7 +336,7 @@ fn day_entries(lang: Lang, items: &[ContributionItem], now: i64) -> Vec<DayEntry | ||
| 336 | 336 | |
| 337 | 337 | /// The contribution card: heading and date range, the four stats, the month labels and the |
| 338 | 338 | /// 53-week grid, then the motivating line and the Less/More legend, then the selected day's |
| 339 | -/// contributions when a day is picked. `base` is the URL the day links point at. | |
| 339 | +/// contributions when a day is picked. `base` is the profile's path the day links point at. | |
| 340 | 340 | #[component] |
| 341 | 341 | pub async fn contribution_calendar( |
| 342 | 342 | calendar: Calendar, |
style/_shell.scssmodified+15 -0
| @@ -921,6 +921,17 @@ a.chip { | ||
| 921 | 921 | cursor: grabbing; |
| 922 | 922 | } |
| 923 | 923 | |
| 924 | +// Below 900px the panel steps aside while the reader scrolls down (nav.js sets corner-away): it fades | |
| 925 | +// out and takes no pointer, so the page under it can be read and tapped. Reduced motion skips the fade. | |
| 926 | +.corner-float { | |
| 927 | + transition: opacity 0.2s ease; | |
| 928 | +} | |
| 929 | + | |
| 930 | +.corner-float.corner-away { | |
| 931 | + opacity: 0; | |
| 932 | + pointer-events: none; | |
| 933 | +} | |
| 934 | + | |
| 924 | 935 | // Placed in the top half of the window: the menu opens below the panel. In the right half it anchors |
| 925 | 936 | // to the panel's right edge instead of the left one. The default corner keeps the upward menu. |
| 926 | 937 | .corner-float[data-open="down"] .corner-menu { |
| @@ -1204,6 +1215,10 @@ html[aria-busy="true"] body::before { | ||
| 1204 | 1215 | opacity: 0.45; |
| 1205 | 1216 | } |
| 1206 | 1217 | |
| 1218 | + .corner-float { | |
| 1219 | + transition: none; | |
| 1220 | + } | |
| 1221 | + | |
| 1207 | 1222 | .pill.hot .pill-dot, |
| 1208 | 1223 | .strip-row.hot .pill-dot { |
| 1209 | 1224 | animation: none; |