Home updates live
Browse files at this commitb995074fbc6f53766411f1477ce3efa0da7b90f8Parent: e2a1952- feat
- home updates live
- a push, a review request, a mention or a CI run changes its lists without a reload
2 changed files +37 -2
crates/forge-web-account/src/pages/home.rsmodified+36 -2
| @@ -4,7 +4,8 @@ use forge_core::store::RepoSort; | ||
| 4 | 4 | use forge_core::store::repo_listing::RepoScope; |
| 5 | 5 | use topcoat::Result; |
| 6 | 6 | use topcoat::context::{Cx, context}; |
| 7 | -use topcoat::router::page; | |
| 7 | +use topcoat::router::response::Response; | |
| 8 | +use topcoat::router::{Body, StatusCode, page, route}; | |
| 8 | 9 | use topcoat::view::{View, component, view}; |
| 9 | 10 | |
| 10 | 11 | use crate::auth::current_user; |
| @@ -13,6 +14,7 @@ use crate::i18n::needs::{self as ni, K as NK}; | ||
| 13 | 14 | use crate::i18n::orgs::{self as g, K}; |
| 14 | 15 | use crate::i18n::s; |
| 15 | 16 | use crate::i18n::{self, Lang}; |
| 17 | +use crate::live::{Topic, stream_changes_with}; | |
| 16 | 18 | use crate::pages::ci_runs::run_href; |
| 17 | 19 | use crate::pages::org_new::may_create_org; |
| 18 | 20 | use crate::pages::repo_settings::{notice_banner_for, take_notice}; |
| @@ -66,6 +68,38 @@ async fn home(cx: &Cx) -> Result<impl View> { | ||
| 66 | 68 | }) |
| 67 | 69 | } |
| 68 | 70 | |
| 71 | +#[route(GET "/-/home/events")] | |
| 72 | +async fn home_events(cx: &Cx) -> Result<Response> { | |
| 73 | + let Some((user, _)) = current_user(cx).await? else { | |
| 74 | + let mut res = Response::new(Body::empty()); | |
| 75 | + *res.status_mut() = StatusCode::UNAUTHORIZED; | |
| 76 | + return Ok(res); | |
| 77 | + }; | |
| 78 | + let state = context::<AppState>(cx).clone(); | |
| 79 | + let lang = i18n::lang(cx, Some(&user)); | |
| 80 | + let topics = [ | |
| 81 | + Topic::User(user.id.clone()), | |
| 82 | + Topic::Inbox(user.id.clone()), | |
| 83 | + Topic::ReviewRequests(user.id.clone()), | |
| 84 | + ]; | |
| 85 | + let runs = vec![state.ci_live.subscribe_any_run()]; | |
| 86 | + stream_changes_with(cx, &state.live.clone(), &topics, runs, move || { | |
| 87 | + let state = state.clone(); | |
| 88 | + let user = user.clone(); | |
| 89 | + async move { | |
| 90 | + let data = load_home(&state, &user, lang).await?; | |
| 91 | + Ok(data | |
| 92 | + .needs | |
| 93 | + .iter() | |
| 94 | + .chain(&data.repos) | |
| 95 | + .map(|row| format!("{}|{}|{}|{}", row.href, row.name, row.detail, row.stamp)) | |
| 96 | + .collect::<Vec<_>>() | |
| 97 | + .join("\n")) | |
| 98 | + } | |
| 99 | + }) | |
| 100 | + .await | |
| 101 | +} | |
| 102 | + | |
| 69 | 103 | async fn load_home(state: &AppState, user: &User, lang: Lang) -> Result<SignedHome> { |
| 70 | 104 | let mut needs: Vec<HomeRow> = Vec::new(); |
| 71 | 105 | for item in state.store.review_requests_for_user(&user.id).await? { |
| @@ -198,7 +232,7 @@ async fn signed_home(cx: &Cx, lang: Lang, data: SignedHome, may_org: bool) -> Re | ||
| 198 | 232 | <a class="button" href="/org/new">(g::t(lang, K::NewOrganization))</a> |
| 199 | 233 | } |
| 200 | 234 | ) |
| 201 | - <div class="sheet"> | |
| 235 | + <div class="sheet" data-live="/-/home/events"> | |
| 202 | 236 | <section class="sec"> |
| 203 | 237 | <h2>(needs_heading)</h2> |
| 204 | 238 | if needs.is_empty() { |
crates/forge-web/src/routes.snapmodified+1 -0
| @@ -155,6 +155,7 @@ route /-/activity Only([GET]) | ||
| 155 | 155 | route /-/activity/stream Only([GET]) |
| 156 | 156 | route /-/alive Only([GET]) |
| 157 | 157 | route /-/banner/dismiss Only([POST]) |
| 158 | +route /-/home/events Only([GET]) | |
| 158 | 159 | route /-/palette Only([GET]) |
| 159 | 160 | route /-/prefs Only([POST]) |
| 160 | 161 | route /-/shell/events Only([GET]) |