From 7b115ab6da6f7799ed489f5d7d097e1fbc4e6e71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sat, 24 Oct 2026 02:43:24 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20the=20signed-in=20sidebar?= =?UTF-8?q?'s=20repo=20list=20is=20live=20on=20every=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A new /-/side/events stream follows the viewer's user topic and fingerprints the five freshest repos and their total. The sidebar follows it, so a create, delete, rename, transfer, visibility change or push moves the list without a reload. A push also wakes the repo owner, not only the pusher. --- crates/forge-web/src/live.rs | 4 +-- crates/forge-web/src/pages/ci_tests.rs | 2 +- crates/forge-web/src/pages/dashboard.rs | 41 +++++++++++++++++++++++- crates/forge-web/src/post_update.rs | 6 ++++ crates/forge-web/src/views/mod.rs | 6 ++-- crates/forge-web/tests/e2e/browse_e2e.rs | 1 + 6 files changed, 53 insertions(+), 7 deletions(-) diff --git a/crates/forge-web/src/live.rs b/crates/forge-web/src/live.rs index 783d111..ea4a474 100644 --- a/crates/forge-web/src/live.rs +++ b/crates/forge-web/src/live.rs @@ -56,8 +56,8 @@ pub enum Topic { /// A repo's own state that its header shows: stars, watchers, forks, and its name and /// description. Keyed by repo id. Repo(String), - /// A user's repo listing, pins and contribution calendar. Keyed by user id (an organization - /// is a user too). + /// A user's repo listing, pins, contribution calendar and the signed-in sidebar's repo list. + /// Keyed by user id (an organization is a user too). User(String), /// A user's inbox: a notification was added, read or marked read. Keyed by user id. Inbox(String), diff --git a/crates/forge-web/src/pages/ci_tests.rs b/crates/forge-web/src/pages/ci_tests.rs index 2313a36..4e393b1 100644 --- a/crates/forge-web/src/pages/ci_tests.rs +++ b/crates/forge-web/src/pages/ci_tests.rs @@ -433,7 +433,7 @@ async fn live_pages_and_streams_follow_a_job_to_its_end() { finish_job(&fx).await; let done = get(&fx.app, &url, Some(&cookie_for("tahinli-token"))).await; assert!( - !done.text().contains("data-live="), + !done.text().contains(&job_marker), "job not live when finished" ); assert!( diff --git a/crates/forge-web/src/pages/dashboard.rs b/crates/forge-web/src/pages/dashboard.rs index 39bc641..cc5ea73 100644 --- a/crates/forge-web/src/pages/dashboard.rs +++ b/crates/forge-web/src/pages/dashboard.rs @@ -5,6 +5,8 @@ use std::time::Duration; +use forge_core::store::RepoSort; +use forge_core::store::repo_listing::RepoScope; use forge_core::{Notification, Repo, Visibility}; use time::OffsetDateTime; use topcoat::Result; @@ -22,7 +24,7 @@ use crate::pages::issue_parts::stamp_unix; use crate::pages::repo_settings::{notice_banner_for, take_notice}; use crate::state::AppState; use crate::views::heatmap::{self, Calendar, contribution_calendar}; -use crate::views::{display_name, now_unix, relative_time, shell}; +use crate::views::{SIDE_REPOS, display_name, now_unix, relative_time, shell}; /// How far back the calendar reads contributions: 53 weeks plus the days of the current week. const CALENDAR_DAYS: u64 = 371; @@ -97,6 +99,43 @@ async fn dashboard_events(cx: &Cx) -> Result { .await } +/// The signed-in sidebar's change stream: the viewer's freshest repos and their total. It follows +/// the viewer's user topic only, and the viewer comes from the session, never from the URL. +#[route(GET "/-/side/events")] +async fn side_events(cx: &Cx) -> Result { + let Some((user, _)) = current_user(cx).await? else { + let mut res = Response::new(Body::empty()); + *res.status_mut() = StatusCode::UNAUTHORIZED; + return Ok(res); + }; + let state = app_context::(cx).clone(); + let topics = [Topic::User(user.id.clone())]; + stream_changes(cx, &state.live.clone(), &topics, move || { + let state = state.clone(); + let user = user.clone(); + async move { side_fingerprint(&state, &user).await } + }) + .await +} + +/// The sidebar's repo list as it shows: the names in order, and the total. +async fn side_fingerprint(state: &AppState, user: &forge_core::User) -> Result { + let (listed, total) = state + .store + .list_visible_repos( + RepoScope::OwnedBy(&user.id), + Some(user), + None, + RepoSort::RecentlyUpdated, + 1, + SIDE_REPOS, + ) + .await?; + let mut lines = vec![format!("total {total}")]; + lines.extend(listed.iter().map(|(repo, _, _)| repo.name.clone())); + Ok(lines.join("\n")) +} + /// The state the dashboard shows: the repo list, the calendar counts and the attention rows. async fn dashboard_fingerprint(state: &AppState, user: &forge_core::User) -> Result { let mut lines = Vec::new(); diff --git a/crates/forge-web/src/post_update.rs b/crates/forge-web/src/post_update.rs index 5c846da..21b7295 100644 --- a/crates/forge-web/src/post_update.rs +++ b/crates/forge-web/src/post_update.rs @@ -51,6 +51,12 @@ pub async fn after_ref_update( .live .bump(&crate::live::Topic::User(actor_id.to_owned())); } + // The owner's sidebar lists its repos by last update, so a push by someone else moves it too. + if repo.owner_id != actor_id { + state + .live + .bump(&crate::live::Topic::User(repo.owner_id.clone())); + } crate::ci::on_ref_update(state, repo, actor_id, refname, new).await; if (refname.starts_with("refs/heads/") || refname.starts_with("refs/tags/")) && let Err(e) = crate::mirrors::enqueue_push_mirrors(state, &repo.id).await diff --git a/crates/forge-web/src/views/mod.rs b/crates/forge-web/src/views/mod.rs index 2788443..f00bd6f 100644 --- a/crates/forge-web/src/views/mod.rs +++ b/crates/forge-web/src/views/mod.rs @@ -92,8 +92,8 @@ fn csp_header(base_url: &str) -> HeaderValue { HeaderValue::from_str(&policy).unwrap_or_else(|_| HeaderValue::from_static(CSP)) } -/// How many repos the signed-in sidebar lists, freshest first. -const SIDE_REPOS: u64 = 5; +/// How many repos the signed-in sidebar lists, freshest first. The sidebar's change stream reads it too. +pub(crate) const SIDE_REPOS: u64 = 5; /// A repo link in the signed-in sidebar. #[derive(Clone)] @@ -495,7 +495,7 @@ async fn side_nav( (o::t(lang, OK::Settings)) -
+

(o::t(lang, OK::YourRepositories))

if empty {

(o::t(lang, OK::NoReposYet))

diff --git a/crates/forge-web/tests/e2e/browse_e2e.rs b/crates/forge-web/tests/e2e/browse_e2e.rs index 75d7865..ad2b156 100644 --- a/crates/forge-web/tests/e2e/browse_e2e.rs +++ b/crates/forge-web/tests/e2e/browse_e2e.rs @@ -949,6 +949,7 @@ async fn browsing_pages_stream_their_changes() { "/notifications/events", "/notifications/events?all=1&user=tahinli", "/dashboard/events", + "/-/side/events", ] { let anonymous = open_stream(&http, path, None).await; assert_eq!(anonymous.status().as_u16(), 401, "anonymous {path}");