The signed-in sidebar's repo list is live on every page
Browse files at this commit7b115ab6da6f7799ed489f5d7d097e1fbc4e6e71Parent: a39364b- fix
- the signed-in sidebar's repo list is live on every page
6 changed files +53 -7
- crates/forge-web/src/live.rs +2 -2
- crates/forge-web/src/pages/ci_tests.rs +1 -1
- crates/forge-web/src/pages/dashboard.rs +40 -1
- crates/forge-web/src/post_update.rs +6 -0
- crates/forge-web/src/views/mod.rs +3 -3
- crates/forge-web/tests/e2e/browse_e2e.rs +1 -0
crates/forge-web/src/live.rsmodified+2 -2
| @@ -56,8 +56,8 @@ pub enum Topic { | ||
| 56 | 56 | /// A repo's own state that its header shows: stars, watchers, forks, and its name and |
| 57 | 57 | /// description. Keyed by repo id. |
| 58 | 58 | 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). | |
| 61 | 61 | User(String), |
| 62 | 62 | /// A user's inbox: a notification was added, read or marked read. Keyed by user id. |
| 63 | 63 | 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() { | ||
| 433 | 433 | finish_job(&fx).await; |
| 434 | 434 | let done = get(&fx.app, &url, Some(&cookie_for("tahinli-token"))).await; |
| 435 | 435 | assert!( |
| 436 | - !done.text().contains("data-live="), | |
| 436 | + !done.text().contains(&job_marker), | |
| 437 | 437 | "job not live when finished" |
| 438 | 438 | ); |
| 439 | 439 | assert!( |
crates/forge-web/src/pages/dashboard.rsmodified+40 -1
| @@ -5,6 +5,8 @@ | ||
| 5 | 5 | |
| 6 | 6 | use std::time::Duration; |
| 7 | 7 | |
| 8 | +use forge_core::store::RepoSort; | |
| 9 | +use forge_core::store::repo_listing::RepoScope; | |
| 8 | 10 | use forge_core::{Notification, Repo, Visibility}; |
| 9 | 11 | use time::OffsetDateTime; |
| 10 | 12 | use topcoat::Result; |
| @@ -22,7 +24,7 @@ use crate::pages::issue_parts::stamp_unix; | ||
| 22 | 24 | use crate::pages::repo_settings::{notice_banner_for, take_notice}; |
| 23 | 25 | use crate::state::AppState; |
| 24 | 26 | 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}; | |
| 26 | 28 | |
| 27 | 29 | /// How far back the calendar reads contributions: 53 weeks plus the days of the current week. |
| 28 | 30 | const CALENDAR_DAYS: u64 = 371; |
| @@ -97,6 +99,43 @@ async fn dashboard_events(cx: &Cx) -> Result<Response> { | ||
| 97 | 99 | .await |
| 98 | 100 | } |
| 99 | 101 | |
| 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 | + | |
| 100 | 139 | /// The state the dashboard shows: the repo list, the calendar counts and the attention rows. |
| 101 | 140 | async fn dashboard_fingerprint(state: &AppState, user: &forge_core::User) -> Result<String> { |
| 102 | 141 | let mut lines = Vec::new(); |
crates/forge-web/src/post_update.rsmodified+6 -0
| @@ -51,6 +51,12 @@ pub async fn after_ref_update( | ||
| 51 | 51 | .live |
| 52 | 52 | .bump(&crate::live::Topic::User(actor_id.to_owned())); |
| 53 | 53 | } |
| 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 | + } | |
| 54 | 60 | crate::ci::on_ref_update(state, repo, actor_id, refname, new).await; |
| 55 | 61 | if (refname.starts_with("refs/heads/") || refname.starts_with("refs/tags/")) |
| 56 | 62 | && 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 { | ||
| 92 | 92 | HeaderValue::from_str(&policy).unwrap_or_else(|_| HeaderValue::from_static(CSP)) |
| 93 | 93 | } |
| 94 | 94 | |
| 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; | |
| 97 | 97 | |
| 98 | 98 | /// A repo link in the signed-in sidebar. |
| 99 | 99 | #[derive(Clone)] |
| @@ -495,7 +495,7 @@ async fn side_nav( | ||
| 495 | 495 | (o::t(lang, OK::Settings)) |
| 496 | 496 | </a> |
| 497 | 497 | </nav> |
| 498 | - <div class="side-group"> | |
| 498 | + <div class="side-group" data-live="/-/side/events"> | |
| 499 | 499 | <h2 class="side-h">(o::t(lang, OK::YourRepositories))</h2> |
| 500 | 500 | if empty { |
| 501 | 501 | <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() { | ||
| 949 | 949 | "/notifications/events", |
| 950 | 950 | "/notifications/events?all=1&user=tahinli", |
| 951 | 951 | "/dashboard/events", |
| 952 | + "/-/side/events", | |
| 952 | 953 | ] { |
| 953 | 954 | let anonymous = open_stream(&http, path, None).await; |
| 954 | 955 | assert_eq!(anonymous.status().as_u16(), 401, "anonymous {path}"); |