forge
Explore
Log in

Don't you dare go Hollow

The signed-in sidebar's repo list is live on every page

Browse files at this commit

7b115ab6da6f7799ed489f5d7d097e1fbc4e6e71Ahmet Kaan GümüşParent: a39364b
  • fix
    • the signed-in sidebar's repo list is live on every page
Show full message
🐛 fix: the signed-in sidebar's repo list is live on every page

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.rsmodified+2 -2
@@ -56,8 +56,8 @@ pub enum Topic {
5656 /// A repo's own state that its header shows: stars, watchers, forks, and its name and
5757 /// description. Keyed by repo id.
5858 Repo(String),
59- /// A user's repo listing, pins and contribution calendar. Keyed by user id (an organization
60- /// is a user too).
59+ /// A user's repo listing, pins, contribution calendar and the signed-in sidebar's repo list.
60+ /// Keyed by user id (an organization is a user too).
6161 User(String),
6262 /// A user's inbox: a notification was added, read or marked read. Keyed by user id.
6363 Inbox(String),
crates/forge-web/src/pages/ci_tests.rsmodified+1 -1
@@ -433,7 +433,7 @@ async fn live_pages_and_streams_follow_a_job_to_its_end() {
433433 finish_job(&fx).await;
434434 let done = get(&fx.app, &url, Some(&cookie_for("tahinli-token"))).await;
435435 assert!(
436- !done.text().contains("data-live="),
436+ !done.text().contains(&job_marker),
437437 "job not live when finished"
438438 );
439439 assert!(
crates/forge-web/src/pages/dashboard.rsmodified+40 -1
@@ -5,6 +5,8 @@
55
66 use std::time::Duration;
77
8+use forge_core::store::RepoSort;
9+use forge_core::store::repo_listing::RepoScope;
810 use forge_core::{Notification, Repo, Visibility};
911 use time::OffsetDateTime;
1012 use topcoat::Result;
@@ -22,7 +24,7 @@ use crate::pages::issue_parts::stamp_unix;
2224 use crate::pages::repo_settings::{notice_banner_for, take_notice};
2325 use crate::state::AppState;
2426 use crate::views::heatmap::{self, Calendar, contribution_calendar};
25-use crate::views::{display_name, now_unix, relative_time, shell};
27+use crate::views::{SIDE_REPOS, display_name, now_unix, relative_time, shell};
2628
2729 /// How far back the calendar reads contributions: 53 weeks plus the days of the current week.
2830 const CALENDAR_DAYS: u64 = 371;
@@ -97,6 +99,43 @@ async fn dashboard_events(cx: &Cx) -> Result<Response> {
9799 .await
98100 }
99101
102+/// The signed-in sidebar's change stream: the viewer's freshest repos and their total. It follows
103+/// the viewer's user topic only, and the viewer comes from the session, never from the URL.
104+#[route(GET "/-/side/events")]
105+async fn side_events(cx: &Cx) -> Result<Response> {
106+ let Some((user, _)) = current_user(cx).await? else {
107+ let mut res = Response::new(Body::empty());
108+ *res.status_mut() = StatusCode::UNAUTHORIZED;
109+ return Ok(res);
110+ };
111+ let state = app_context::<AppState>(cx).clone();
112+ let topics = [Topic::User(user.id.clone())];
113+ stream_changes(cx, &state.live.clone(), &topics, move || {
114+ let state = state.clone();
115+ let user = user.clone();
116+ async move { side_fingerprint(&state, &user).await }
117+ })
118+ .await
119+}
120+
121+/// The sidebar's repo list as it shows: the names in order, and the total.
122+async fn side_fingerprint(state: &AppState, user: &forge_core::User) -> Result<String> {
123+ let (listed, total) = state
124+ .store
125+ .list_visible_repos(
126+ RepoScope::OwnedBy(&user.id),
127+ Some(user),
128+ None,
129+ RepoSort::RecentlyUpdated,
130+ 1,
131+ SIDE_REPOS,
132+ )
133+ .await?;
134+ let mut lines = vec![format!("total {total}")];
135+ lines.extend(listed.iter().map(|(repo, _, _)| repo.name.clone()));
136+ Ok(lines.join("\n"))
137+}
138+
100139 /// The state the dashboard shows: the repo list, the calendar counts and the attention rows.
101140 async fn dashboard_fingerprint(state: &AppState, user: &forge_core::User) -> Result<String> {
102141 let mut lines = Vec::new();
crates/forge-web/src/post_update.rsmodified+6 -0
@@ -51,6 +51,12 @@ pub async fn after_ref_update(
5151 .live
5252 .bump(&crate::live::Topic::User(actor_id.to_owned()));
5353 }
54+ // The owner's sidebar lists its repos by last update, so a push by someone else moves it too.
55+ if repo.owner_id != actor_id {
56+ state
57+ .live
58+ .bump(&crate::live::Topic::User(repo.owner_id.clone()));
59+ }
5460 crate::ci::on_ref_update(state, repo, actor_id, refname, new).await;
5561 if (refname.starts_with("refs/heads/") || refname.starts_with("refs/tags/"))
5662 && let Err(e) = crate::mirrors::enqueue_push_mirrors(state, &repo.id).await
crates/forge-web/src/views/mod.rsmodified+3 -3
@@ -92,8 +92,8 @@ fn csp_header(base_url: &str) -> HeaderValue {
9292 HeaderValue::from_str(&policy).unwrap_or_else(|_| HeaderValue::from_static(CSP))
9393 }
9494
95-/// How many repos the signed-in sidebar lists, freshest first.
96-const SIDE_REPOS: u64 = 5;
95+/// How many repos the signed-in sidebar lists, freshest first. The sidebar's change stream reads it too.
96+pub(crate) const SIDE_REPOS: u64 = 5;
9797
9898 /// A repo link in the signed-in sidebar.
9999 #[derive(Clone)]
@@ -495,7 +495,7 @@ async fn side_nav(
495495 (o::t(lang, OK::Settings))
496496 </a>
497497 </nav>
498- <div class="side-group">
498+ <div class="side-group" data-live="/-/side/events">
499499 <h2 class="side-h">(o::t(lang, OK::YourRepositories))</h2>
500500 if empty {
501501 <p class="side-empty">(o::t(lang, OK::NoReposYet))</p>
crates/forge-web/tests/e2e/browse_e2e.rsmodified+1 -0
@@ -949,6 +949,7 @@ async fn browsing_pages_stream_their_changes() {
949949 "/notifications/events",
950950 "/notifications/events?all=1&user=tahinli",
951951 "/dashboard/events",
952+ "/-/side/events",
952953 ] {
953954 let anonymous = open_stream(&http, path, None).await;
954955 assert_eq!(anonymous.status().as_u16(), 401, "anonymous {path}");