forge
Explore
Log in

Don't you dare go Hollow

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 commit

8e56ffc5ba761d68f2909dedfcd96dcedc76f102Ahmet Kaan GümüşParent: c812504
All checks have passed
Show checks
  • 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
Show full message
💄 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
crates/forge-web/assets/nav.jsmodified+60 -0
@@ -843,6 +843,66 @@
843843 window.addEventListener('resize', cornerApply);
844844 cornerApply();
845845
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+
846906 // The bell beside the profile corner opens a popover of the newest notifications instead of going
847907 // to the inbox. A plain click toggles it; with a modifier or a middle click the link's own
848908 // 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 {
121121 PinsTooMany,
122122 NoPinnableRepos,
123123 TabOverview,
124+ TabContributions,
124125 Overview,
125126 TabStars,
126127 FilterRepos,
@@ -375,6 +376,8 @@ pub fn t(lang: Lang, key: K) -> &'static str {
375376 (NoPinnableRepos, Tr) => "Henüz sabitlenecek depo yok.",
376377 (TabOverview, En) => "Overview",
377378 (TabOverview, Tr) => "Genel bakış",
379+ (TabContributions, En) => "Contributions",
380+ (TabContributions, Tr) => "Katkılar",
378381 (Overview, En) => "Overview",
379382 (Overview, Tr) => "Genel bakış",
380383 (TabStars, En) => "Stars",
@@ -618,6 +621,7 @@ mod tests {
618621 K::PinsTooMany,
619622 K::NoPinnableRepos,
620623 K::TabOverview,
624+ K::TabContributions,
621625 K::Overview,
622626 K::TabStars,
623627 K::FilterRepos,
crates/forge-web/src/pages/profile.rsmodified+41 -20
@@ -1,7 +1,8 @@
11 //! Page: public profile at `/{username}`. Avatar, about (rendered markdown) and local time, then
22 //! 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
56 //! repo tabs list what the viewer is allowed to read, 30 per page, with a name filter and three
67 //! sort orders; the filtering, sorting and paging run in the database. Fixed single-segment routes
78 //! are registered statically, so they win over this parameter route.
@@ -55,7 +56,7 @@ struct ProfileQuery {
5556 q: Option<String>,
5657 sort: Option<String>,
5758 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.
5960 day: Option<String>,
6061 }
6162
@@ -99,10 +100,14 @@ async fn profile_page(cx: &Cx) -> Result<impl View> {
99100 let lang = i18n::lang(cx, actor);
100101 // Whether the viewer is this person. Only the person sees their Organizations tab and edit links.
101102 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"))
106111 || (tab == "organizations" && !own)
107112 {
108113 "overview"
@@ -182,9 +187,9 @@ async fn profile_page(cx: &Cx) -> Result<impl View> {
182187 }
183188 });
184189
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
186191 // 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() {
188193 Some(load_calendar(state, &user, query.day.as_deref()).await?)
189194 } else {
190195 None
@@ -378,7 +383,7 @@ async fn profile_fingerprint(
378383 let teams = state.store.teams_for_org(&user.id).await?.len();
379384 lines.push(format!("org {members} {teams}"));
380385 } 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.
382387 let total: u64 = state
383388 .store
384389 .contribution_counts(&user.id, &calendar_since(), &user.timezone)
@@ -451,6 +456,7 @@ struct Listing {
451456 fn tab_key(raw: Option<&str>) -> &'static str {
452457 match raw {
453458 Some("repositories") => "repositories",
459+ Some("contributions") => "contributions",
454460 Some("snippets") => "snippets",
455461 Some("stars") => "stars",
456462 Some("packages") => "packages",
@@ -569,6 +575,8 @@ async fn profile_card(
569575 let is_org = user.is_org();
570576 let base = format!("/{}", enc(&user.username));
571577 let overview_on = tab == "overview";
578+ let contributions_on = tab == "contributions";
579+ let contributions_href = profile_href(&user.username, "contributions", "", SORTS[0].0, 1);
572580 let repos_on = tab == "repositories";
573581 let stars_on = tab == "stars";
574582 let list_on = repos_on || stars_on;
@@ -623,14 +631,9 @@ async fn profile_card(
623631 if edit_profile {
624632 <a class="button profile-edit" href="/settings/profile">(edit_label)</a>
625633 }
626- if is_org && (org_can_create || org_owner) {
634+ if is_org && org_can_create {
627635 <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>
634637 </div>
635638 }
636639 </div>
@@ -640,6 +643,9 @@ async fn profile_card(
640643 }
641644 <nav class="profile-tabs" aria-label=(user.username.as_str())>
642645 <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+ }
643649 <a class=(tab_class(repos_on)) href=(repositories_href.as_str())>
644650 (g::t(lang, K::Repositories)) " " <span class="tab-count">(repo_count_text.as_str())</span>
645651 </a>
@@ -696,9 +702,6 @@ async fn profile_card(
696702 empty_state(title: g::t(lang, K::NoVisibleRepos))
697703 }
698704 </section>
699- if let Some((calendar, selected)) = heat {
700- contribution_calendar(calendar: calendar, selected: selected, lang: lang, base: base.clone())
701- }
702705 if let Some(summary) = org {
703706 <section class="profile-org">
704707 <h2>(g::t(lang, K::Members))</h2>
@@ -715,6 +718,11 @@ async fn profile_card(
715718 </section>
716719 }
717720 }
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+ }
718726 if list_on {
719727 <section class="repo-listing">
720728 if own_profile && repos_on {
@@ -1210,6 +1218,19 @@ mod tests {
12101218 );
12111219 }
12121220
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+
12131234 fn count(body: &str, needle: &str) -> usize {
12141235 body.matches(needle).count()
12151236 }
crates/forge-web/src/views/heatmap.rsmodified+8 -8
@@ -4,8 +4,8 @@
44 //! `build` is pure date and streak maths over the counts from the store. `contribution_calendar`
55 //! draws it with classes only (CSP): the grid placement comes from CSS (`grid-auto-flow: column`
66 //! 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.
99
1010 use std::collections::HashMap;
1111
@@ -209,15 +209,15 @@ struct DayView {
209209 }
210210
211211 /// 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.
215215 fn day_href(base: &str, date: (i64, i64, i64), selected: bool) -> String {
216216 if selected {
217- format!("{base}#contributions-h")
217+ format!("{base}?tab=contributions#contributions-h")
218218 } else {
219219 format!(
220- "{base}?day={:04}-{:02}-{:02}#contributions-h",
220+ "{base}?tab=contributions&day={:04}-{:02}-{:02}#contributions-h",
221221 date.0, date.1, date.2
222222 )
223223 }
@@ -336,7 +336,7 @@ fn day_entries(lang: Lang, items: &[ContributionItem], now: i64) -> Vec<DayEntry
336336
337337 /// The contribution card: heading and date range, the four stats, the month labels and the
338338 /// 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.
340340 #[component]
341341 pub async fn contribution_calendar(
342342 calendar: Calendar,
style/_shell.scssmodified+15 -0
@@ -921,6 +921,17 @@ a.chip {
921921 cursor: grabbing;
922922 }
923923
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+
924935 // Placed in the top half of the window: the menu opens below the panel. In the right half it anchors
925936 // to the panel's right edge instead of the left one. The default corner keeps the upward menu.
926937 .corner-float[data-open="down"] .corner-menu {
@@ -1204,6 +1215,10 @@ html[aria-busy="true"] body::before {
12041215 opacity: 0.45;
12051216 }
12061217
1218+ .corner-float {
1219+ transition: none;
1220+ }
1221+
12071222 .pill.hot .pill-dot,
12081223 .strip-row.hot .pill-dot {
12091224 animation: none;