forge
Explore
Log in

Don't you dare go Hollow

b995074fbc6f53766411f1477ce3efa0da7b90f8Ahmet Kaan GümüşParent: e2a1952
  • feat
    • home updates live
    • a push, a review request, a mention or a CI run changes its lists without a reload
Show full message
✨ feat: home updates live; a push, a review request, a mention or a CI run changes its lists without a reload
crates/forge-web-account/src/pages/home.rsmodified+36 -2
@@ -4,7 +4,8 @@ use forge_core::store::RepoSort;
44 use forge_core::store::repo_listing::RepoScope;
55 use topcoat::Result;
66 use topcoat::context::{Cx, context};
7-use topcoat::router::page;
7+use topcoat::router::response::Response;
8+use topcoat::router::{Body, StatusCode, page, route};
89 use topcoat::view::{View, component, view};
910
1011 use crate::auth::current_user;
@@ -13,6 +14,7 @@ use crate::i18n::needs::{self as ni, K as NK};
1314 use crate::i18n::orgs::{self as g, K};
1415 use crate::i18n::s;
1516 use crate::i18n::{self, Lang};
17+use crate::live::{Topic, stream_changes_with};
1618 use crate::pages::ci_runs::run_href;
1719 use crate::pages::org_new::may_create_org;
1820 use crate::pages::repo_settings::{notice_banner_for, take_notice};
@@ -66,6 +68,38 @@ async fn home(cx: &Cx) -> Result<impl View> {
6668 })
6769 }
6870
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+
69103 async fn load_home(state: &AppState, user: &User, lang: Lang) -> Result<SignedHome> {
70104 let mut needs: Vec<HomeRow> = Vec::new();
71105 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
198232 <a class="button" href="/org/new">(g::t(lang, K::NewOrganization))</a>
199233 }
200234 )
201- <div class="sheet">
235+ <div class="sheet" data-live="/-/home/events">
202236 <section class="sec">
203237 <h2>(needs_heading)</h2>
204238 if needs.is_empty() {
crates/forge-web/src/routes.snapmodified+1 -0
@@ -155,6 +155,7 @@ route /-/activity Only([GET])
155155 route /-/activity/stream Only([GET])
156156 route /-/alive Only([GET])
157157 route /-/banner/dismiss Only([POST])
158+route /-/home/events Only([GET])
158159 route /-/palette Only([GET])
159160 route /-/prefs Only([POST])
160161 route /-/shell/events Only([GET])