Sidebar shows your 5 freshest repositories and links to the rest
Browse files at this commit2c147015f429f886786b21fa2f5323cd606a54e9Parent: 6c7efce- perf
- sidebar shows your 5 freshest repositories and links to the rest
2 changed files +40 -11
crates/forge-web/src/i18n/orgs.rsmodified+4 -0
| @@ -128,6 +128,7 @@ pub enum K { | |||
| 128 | SetUpForge, | 128 | SetUpForge, |
| 129 | YourRepositories, | 129 | YourRepositories, |
| 130 | NoReposYet, | 130 | NoReposYet, |
| 131 | + ViewAllRepositories, | ||
| 131 | } | 132 | } |
| 132 | 133 | ||
| 133 | pub fn t(lang: Lang, key: K) -> &'static str { | 134 | pub fn t(lang: Lang, key: K) -> &'static str { |
| @@ -382,6 +383,8 @@ pub fn t(lang: Lang, key: K) -> &'static str { | |||
| 382 | (YourRepositories, Tr) => "Depolarınız", | 383 | (YourRepositories, Tr) => "Depolarınız", |
| 383 | (NoReposYet, En) => "You have no repositories yet.", | 384 | (NoReposYet, En) => "You have no repositories yet.", |
| 384 | (NoReposYet, Tr) => "Henüz deponuz yok.", | 385 | (NoReposYet, Tr) => "Henüz deponuz yok.", |
| 386 | + (ViewAllRepositories, En) => "View all repositories", | ||
| 387 | + (ViewAllRepositories, Tr) => "Tüm depoları gör", | ||
| 385 | } | 388 | } |
| 386 | } | 389 | } |
| 387 | 390 | ||
| @@ -611,6 +614,7 @@ mod tests { | |||
| 611 | K::SetUpForge, | 614 | K::SetUpForge, |
| 612 | K::YourRepositories, | 615 | K::YourRepositories, |
| 613 | K::NoReposYet, | 616 | K::NoReposYet, |
| 617 | + K::ViewAllRepositories, | ||
| 614 | ]; | 618 | ]; |
| 615 | 619 | ||
| 616 | #[test] | 620 | #[test] |
crates/forge-web/src/views/mod.rsmodified+36 -11
| @@ -9,6 +9,8 @@ pub mod review_thread; | |||
| 9 | 9 | ||
| 10 | use std::sync::OnceLock; | 10 | use std::sync::OnceLock; |
| 11 | 11 | ||
| 12 | +use forge_core::store::RepoSort; | ||
| 13 | +use forge_core::store::repo_listing::RepoScope; | ||
| 12 | use forge_core::{Error as CoreError, Session, User}; | 14 | use forge_core::{Error as CoreError, Session, User}; |
| 13 | use hex::encode; | 15 | use hex::encode; |
| 14 | use http::header::{ | 16 | use http::header::{ |
| @@ -90,6 +92,9 @@ fn csp_header(base_url: &str) -> HeaderValue { | |||
| 90 | HeaderValue::from_str(&policy).unwrap_or_else(|_| HeaderValue::from_static(CSP)) | 92 | HeaderValue::from_str(&policy).unwrap_or_else(|_| HeaderValue::from_static(CSP)) |
| 91 | } | 93 | } |
| 92 | 94 | ||
| 95 | +/// How many repos the signed-in sidebar lists, freshest first. | ||
| 96 | +const SIDE_REPOS: u64 = 5; | ||
| 97 | + | ||
| 93 | /// A repo link in the signed-in sidebar. | 98 | /// A repo link in the signed-in sidebar. |
| 94 | #[derive(Clone)] | 99 | #[derive(Clone)] |
| 95 | struct SideRepo { | 100 | struct SideRepo { |
| @@ -128,22 +133,32 @@ pub async fn shell( | |||
| 128 | #[default] child: Child<'_>, | 133 | #[default] child: Child<'_>, |
| 129 | ) -> Result<impl View> { | 134 | ) -> Result<impl View> { |
| 130 | let full_title = format!("{title} \u{b7} forge"); | 135 | let full_title = format!("{title} \u{b7} forge"); |
| 131 | - // The bell count and the viewer's repos for the sidebar: two queries, signed-in only. | 136 | + // The bell count and the viewer's freshest repos for the sidebar, with the total: two queries, |
| 132 | - let (unread, repos) = match viewer { | 137 | + // signed-in only. |
| 138 | + let (unread, (listed, repo_total)) = match viewer { | ||
| 133 | Some((user, _)) => match try_app_context::<AppState>(__cx) { | 139 | Some((user, _)) => match try_app_context::<AppState>(__cx) { |
| 134 | Some(state) => ( | 140 | Some(state) => ( |
| 135 | state.store.unread_count(&user.id).await?, | 141 | state.store.unread_count(&user.id).await?, |
| 136 | - state.store.list_repos_by_owner(&user.id).await?, | 142 | + state |
| 143 | + .store | ||
| 144 | + .list_visible_repos( | ||
| 145 | + RepoScope::OwnedBy(&user.id), | ||
| 146 | + Some(user), | ||
| 147 | + None, | ||
| 148 | + RepoSort::RecentlyUpdated, | ||
| 149 | + 1, | ||
| 150 | + SIDE_REPOS, | ||
| 151 | + ) | ||
| 152 | + .await?, | ||
| 137 | ), | 153 | ), |
| 138 | - None => (0, Vec::new()), | 154 | + None => (0, (Vec::new(), 0)), |
| 139 | }, | 155 | }, |
| 140 | - None => (0, Vec::new()), | 156 | + None => (0, (Vec::new(), 0)), |
| 141 | }; | 157 | }; |
| 142 | let unread_badge = (unread > 0).then(|| unread.to_string()); | 158 | let unread_badge = (unread > 0).then(|| unread.to_string()); |
| 143 | - let side_repos: Vec<SideRepo> = repos | 159 | + let side_repos: Vec<SideRepo> = listed |
| 144 | .iter() | 160 | .iter() |
| 145 | - .take(8) | 161 | + .map(|(repo, _, _)| SideRepo { |
| 146 | - .map(|repo| SideRepo { | ||
| 147 | name: repo.name.clone(), | 162 | name: repo.name.clone(), |
| 148 | href: repo_href(&repo.owner_name, &repo.name, "", ""), | 163 | href: repo_href(&repo.owner_name, &repo.name, "", ""), |
| 149 | }) | 164 | }) |
| @@ -151,7 +166,9 @@ pub async fn shell( | |||
| 151 | // The viewer's own profile Repositories tab has its own sidebar key, so the pinned link lights up there. | 166 | // The viewer's own profile Repositories tab has its own sidebar key, so the pinned link lights up there. |
| 152 | let own_repos_tab = viewer.is_some_and(|(user, _)| { | 167 | let own_repos_tab = viewer.is_some_and(|(user, _)| { |
| 153 | uri(__cx).path().trim_matches('/') == user.username | 168 | uri(__cx).path().trim_matches('/') == user.username |
| 154 | - && uri(__cx).query().is_some_and(|q| q.split('&').any(|p| p == "tab=repositories")) | 169 | + && uri(__cx) |
| 170 | + .query() | ||
| 171 | + .is_some_and(|q| q.split('&').any(|p| p == "tab=repositories")) | ||
| 155 | }); | 172 | }); |
| 156 | let current = if own_repos_tab { | 173 | let current = if own_repos_tab { |
| 157 | "repositories" | 174 | "repositories" |
| @@ -176,6 +193,8 @@ pub async fn shell( | |||
| 176 | let theme_csrf = viewer.map(|(_, session)| session.csrf_token.clone()); | 193 | let theme_csrf = viewer.map(|(_, session)| session.csrf_token.clone()); |
| 177 | let back = uri(__cx).path_and_query().map(|p| p.as_str().to_owned()); | 194 | let back = uri(__cx).path_and_query().map(|p| p.as_str().to_owned()); |
| 178 | let lang = i18n::lang(__cx, viewer.map(|(user, _)| user)); | 195 | let lang = i18n::lang(__cx, viewer.map(|(user, _)| user)); |
| 196 | + let side_more = (repo_total > SIDE_REPOS) | ||
| 197 | + .then(|| format!("{} ({repo_total})", o::t(lang, OK::ViewAllRepositories))); | ||
| 179 | let banner = crate::pages::banner::current(__cx); | 198 | let banner = crate::pages::banner::current(__cx); |
| 180 | let banner_back = back.clone().unwrap_or_else(|| "/".to_owned()); | 199 | let banner_back = back.clone().unwrap_or_else(|| "/".to_owned()); |
| 181 | let dismiss_label = crate::i18n::accounts::t(lang, crate::i18n::accounts::A::Dismiss); | 200 | let dismiss_label = crate::i18n::accounts::t(lang, crate::i18n::accounts::A::Dismiss); |
| @@ -268,6 +287,8 @@ pub async fn shell( | |||
| 268 | let notif_label = t(lang, Key::Notifications); | 287 | let notif_label = t(lang, Key::Notifications); |
| 269 | let menu_label = t(lang, Key::SiteMenu); | 288 | let menu_label = t(lang, Key::SiteMenu); |
| 270 | let side_repos_menu = side_repos.clone(); | 289 | let side_repos_menu = side_repos.clone(); |
| 290 | + let side_more_menu = side_more.clone(); | ||
| 291 | + let side_more_aside = side_more; | ||
| 271 | let unread_menu = unread_badge.clone(); | 292 | let unread_menu = unread_badge.clone(); |
| 272 | let unread_aside = unread_badge.clone(); | 293 | let unread_aside = unread_badge.clone(); |
| 273 | Ok(view! { | 294 | Ok(view! { |
| @@ -304,7 +325,7 @@ pub async fn shell( | |||
| 304 | if let Some(section) = section_menu { | 325 | if let Some(section) = section_menu { |
| 305 | section_nav(title: section.title.as_str(), back: section.back, items: section.items, current: section.current, live: section.live) | 326 | section_nav(title: section.title.as_str(), back: section.back, items: section.items, current: section.current, live: section.live) |
| 306 | } else { | 327 | } else { |
| 307 | - side_nav(lang: lang, current: current, profile_repos_href: profile_repos_href.as_str(), unread: unread_menu, repos: side_repos_menu) | 328 | + side_nav(lang: lang, current: current, profile_repos_href: profile_repos_href.as_str(), unread: unread_menu, more: side_more_menu, repos: side_repos_menu) |
| 308 | } | 329 | } |
| 309 | </div> | 330 | </div> |
| 310 | </details> | 331 | </details> |
| @@ -391,7 +412,7 @@ pub async fn shell( | |||
| 391 | if let Some(section) = section { | 412 | if let Some(section) = section { |
| 392 | section_nav(title: section.title.as_str(), back: section.back, items: section.items, current: section.current, live: section.live) | 413 | section_nav(title: section.title.as_str(), back: section.back, items: section.items, current: section.current, live: section.live) |
| 393 | } else { | 414 | } else { |
| 394 | - side_nav(lang: lang, current: current, profile_repos_href: profile_repos_href.as_str(), unread: unread_aside, repos: side_repos) | 415 | + side_nav(lang: lang, current: current, profile_repos_href: profile_repos_href.as_str(), unread: unread_aside, more: side_more_aside, repos: side_repos) |
| 395 | } | 416 | } |
| 396 | </aside> | 417 | </aside> |
| 397 | } | 418 | } |
| @@ -429,6 +450,7 @@ async fn side_nav( | |||
| 429 | current: &str, | 450 | current: &str, |
| 430 | profile_repos_href: &str, | 451 | profile_repos_href: &str, |
| 431 | unread: Option<String>, | 452 | unread: Option<String>, |
| 453 | + more: Option<String>, | ||
| 432 | repos: Vec<SideRepo>, | 454 | repos: Vec<SideRepo>, |
| 433 | ) -> Result<impl View> { | 455 | ) -> Result<impl View> { |
| 434 | let dashboard = current == "dashboard"; | 456 | let dashboard = current == "dashboard"; |
| @@ -482,6 +504,9 @@ async fn side_nav( | |||
| 482 | for repo in repos.into_iter() { | 504 | for repo in repos.into_iter() { |
| 483 | <a href=(repo.href.as_str())>(repo.name.as_str())</a> | 505 | <a href=(repo.href.as_str())>(repo.name.as_str())</a> |
| 484 | } | 506 | } |
| 507 | + if let Some(label) = more { | ||
| 508 | + <a href=(profile_repos_href)>(label.as_str())</a> | ||
| 509 | + } | ||
| 485 | </nav> | 510 | </nav> |
| 486 | } | 511 | } |
| 487 | </div> | 512 | </div> |