From 3974c0493b9ddb6d5e57675b3460a53b36dc360a Mon Sep 17 00:00:00 2001 From: Roman Sirokov Date: Tue, 1 Dec 2026 23:04:44 +0100 Subject: [PATCH 1/3] Virtualize the Skills catalog list --- src/conversation/skills.rs | 122 +++++++++++++++++++++++-------------- 1 file changed, 76 insertions(+), 46 deletions(-) diff --git a/src/conversation/skills.rs b/src/conversation/skills.rs index 2b13ea7..29f57de 100644 --- a/src/conversation/skills.rs +++ b/src/conversation/skills.rs @@ -65,8 +65,8 @@ impl Skill { let action = format!("Open {} on skills.sh", self.name); h_flex() .min_w_0() + .h_full() .gap_3() - .py_2() .border_t_1() .border_color(cx.theme().border) .child( @@ -148,7 +148,7 @@ pub(super) struct Skills { next_page: Option, failed: Option, pending: Option>, - scroll: ScrollHandle, + scroll: UniformListScrollHandle, detail: Option, } @@ -169,7 +169,11 @@ impl Skills { view.next_page = None; view.failed = None; view.pending = None; - view.scroll.set_offset(Point::default()); + view.scroll + .0 + .borrow() + .base_handle + .set_offset(Point::default()); if query.is_empty() { view.load(Request::Browse(0), cx); } else if query.chars().count() >= 2 { @@ -188,7 +192,7 @@ impl Skills { next_page: None, failed: None, pending: None, - scroll: ScrollHandle::new(), + scroll: UniformListScrollHandle::new(), detail: None, } } @@ -218,6 +222,41 @@ impl Skills { })); cx.notify(); } + + fn catalog_footer( + &self, + status: Option<&'static str>, + more: Option, + cx: &Context, + ) -> Div { + h_flex() + .gap_2() + .when_some(status, |row, message| { + row.child(control!(message, hint(message, cx))) + }) + .when_some(self.failed.clone(), |row, request| { + row.child(control!( + "Retry", + Button::new("retry-skills") + .small() + .label("Retry") + .on_click(cx.listener(move |view, _, _, cx| { + view.load(request.clone(), cx); + })) + )) + }) + .when_some(more, |row, page| { + row.child(control!( + "Load more", + Button::new("more-skills") + .small() + .label("Load more") + .on_click(cx.listener(move |view, _, _, cx| { + view.load(Request::Browse(page), cx); + })) + )) + }) + } } impl Render for Skills { @@ -242,6 +281,37 @@ impl Render for Skills { None }; + let more = self + .next_page + .filter(|_| self.pending.is_none() && self.failed.is_none()); + let has_footer = status.is_some() || more.is_some(); + let list = uniform_list( + "skills-results", + self.rows.len() + usize::from(has_footer), + cx.processor(move |view, range: std::ops::Range, _, cx| { + range + .map(|index| { + let row = match view.rows.get(index) { + Some(skill) => skill.row(index, cx), + None => view.catalog_footer(status, more, cx), + }; + h_flex().w_full().h(rems(3.5)).justify_center().child( + v_flex() + .size_full() + .max_w(px(720.)) + .px_4() + .justify_center() + .child(row), + ) + }) + .collect::>() + }), + ) + .size_full() + .pb_5() + .with_sizing_behavior(ListSizingBehavior::Auto) + .track_scroll(self.scroll.clone()); + v_flex() .flex_1() .min_h_0() @@ -267,51 +337,11 @@ impl Render for Skills { })), ) .child( - crate::ui::keyboard_scroll_area("skills-list", &self.scroll, window, cx) + crate::ui::keyboard_scroll_viewport("skills-list", &self.scroll, window, cx) .w_full() .flex_1() .min_h_0() - .overflow_y_scroll() - .child( - v_flex().items_center().w_full().child( - v_flex() - .w_full() - .max_w(px(720.)) - .px_4() - .pb_5() - .children( - self.rows - .iter() - .enumerate() - .map(|(index, skill)| skill.row(index, cx)), - ) - .when_some(status, |list, message| { - list.child(control!(message, hint(message, cx).py_3())) - }) - .when_some(self.failed.clone(), |list, request| { - list.child( - Button::new("retry-skills") - .small() - .label("Retry") - .on_click(cx.listener(move |view, _, _, cx| { - view.load(request.clone(), cx) - })), - ) - }) - .when(self.pending.is_none() && self.failed.is_none(), |list| { - list.when_some(self.next_page, |list, page| { - list.child( - Button::new("more-skills") - .small() - .label("Load more") - .on_click(cx.listener(move |view, _, _, cx| { - view.load(Request::Browse(page), cx) - })), - ) - }) - }), - ), - ), + .child(list), ) } } From 75b8aadd23c64c01384388b574cd98957ce7304c Mon Sep 17 00:00:00 2001 From: Roman Sirokov Date: Tue, 1 Dec 2026 23:06:54 +0100 Subject: [PATCH 2/3] Add ranking tabs to the Skills catalog --- src/conversation/skills.rs | 91 +++++++++++++++++++++++++++++--------- 1 file changed, 71 insertions(+), 20 deletions(-) diff --git a/src/conversation/skills.rs b/src/conversation/skills.rs index 29f57de..2864776 100644 --- a/src/conversation/skills.rs +++ b/src/conversation/skills.rs @@ -117,9 +117,33 @@ struct CatalogPage { has_more: bool, } +#[derive(Clone, Copy, Default, PartialEq, Eq)] +enum Ranking { + #[default] + AllTime, + Trending, + Hot, +} + +impl Ranking { + const TABS: [(Self, &'static str); 3] = [ + (Self::AllTime, "All time"), + (Self::Trending, "Trending"), + (Self::Hot, "Hot"), + ]; + + fn path(self) -> &'static str { + match self { + Self::AllTime => "all-time", + Self::Trending => "trending", + Self::Hot => "hot", + } + } +} + #[derive(Clone)] enum Request { - Browse(usize), + Browse(Ranking, usize), Search(String), } @@ -128,7 +152,9 @@ impl Request { // Use the public directory endpoints used by the skills.sh website. // The documented v1 endpoints require a Vercel project token. let mut url = match &self { - Self::Browse(page) => Url::parse(&format!("{CATALOG}/api/skills/all-time/{page}"))?, + Self::Browse(ranking, page) => { + Url::parse(&format!("{CATALOG}/api/skills/{}/{page}", ranking.path()))? + } Self::Search(_) => Url::parse(&format!("{CATALOG}/api/search"))?, }; if let Self::Search(query) = &self { @@ -144,6 +170,7 @@ pub(super) struct Skills { input: Entity, executor: tokio::runtime::Handle, query: String, + ranking: Ranking, rows: Vec, next_page: Option, failed: Option, @@ -165,17 +192,9 @@ impl Skills { let query = value.trim(); if view.query != query { view.query = query.to_owned(); - view.rows.clear(); - view.next_page = None; - view.failed = None; - view.pending = None; - view.scroll - .0 - .borrow() - .base_handle - .set_offset(Point::default()); + view.reset_results(); if query.is_empty() { - view.load(Request::Browse(0), cx); + view.load(Request::Browse(view.ranking, 0), cx); } else if query.chars().count() >= 2 { view.load(Request::Search(query.to_owned()), cx); } @@ -188,6 +207,7 @@ impl Skills { input, executor, query: String::new(), + ranking: Ranking::default(), rows: Vec::new(), next_page: None, failed: None, @@ -197,6 +217,18 @@ impl Skills { } } + fn reset_results(&mut self) { + self.rows.clear(); + self.next_page = None; + self.failed = None; + self.pending = None; + self.scroll + .0 + .borrow() + .base_handle + .set_offset(Point::default()); + } + fn load(&mut self, request: Request, cx: &mut Context) { self.failed = None; let executor = self.executor.clone(); @@ -209,7 +241,7 @@ impl Skills { match page { Ok(Ok(page)) => { view.next_page = match request { - Request::Browse(index) if page.has_more => Some(index + 1), + Request::Browse(_, index) if page.has_more => Some(index + 1), _ => None, }; view.rows.extend(page.skills); @@ -252,7 +284,7 @@ impl Skills { .small() .label("Load more") .on_click(cx.listener(move |view, _, _, cx| { - view.load(Request::Browse(page), cx); + view.load(Request::Browse(view.ranking, page), cx); })) )) }) @@ -330,11 +362,30 @@ impl Render for Skills { .prefix(Icon::new(IconName::Search)) .cleanable(true) )) - .child(label(if browse { - "Popular skills" - } else { - "Search results" - })), + .when(browse, |header| { + header.child(h_flex().gap_1().children(Ranking::TABS.map( + |(ranking, title)| { + control!( + title, + crate::ui::choice( + ranking.path(), + title, + self.ranking == ranking + ) + .on_click(cx.listener( + move |view, _, _, cx| { + if view.ranking != ranking { + view.ranking = ranking; + view.reset_results(); + view.load(Request::Browse(ranking, 0), cx); + } + } + )) + ) + }, + ))) + }) + .when(!browse, |header| header.child(label("Search results"))), ) .child( crate::ui::keyboard_scroll_viewport("skills-list", &self.scroll, window, cx) @@ -373,7 +424,7 @@ impl Desktop { let skills = self.skills.get_or_insert_with(|| { cx.new(|cx| { let mut skills = Skills::new(self.executor.clone(), window, cx); - skills.load(Request::Browse(0), cx); + skills.load(Request::Browse(skills.ranking, 0), cx); skills }) }); From 884eb21124a70f6741924aa58cbf7c6103069120 Mon Sep 17 00:00:00 2001 From: Roman Sirokov Date: Tue, 1 Dec 2026 23:11:34 +0100 Subject: [PATCH 3/3] Load more Skills automatically while scrolling --- src/conversation/skills.rs | 55 +++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/src/conversation/skills.rs b/src/conversation/skills.rs index 2864776..e5cc599 100644 --- a/src/conversation/skills.rs +++ b/src/conversation/skills.rs @@ -7,6 +7,7 @@ use std::time::Duration; use url::Url; const CATALOG: &str = "https://skills.sh"; +const PREFETCH_ROWS: usize = 5; const MAX_RESPONSE_BYTES: usize = 2 * 1024 * 1024; async fn fetch_catalog_response(url: Url) -> anyhow::Result> { @@ -255,12 +256,30 @@ impl Skills { cx.notify(); } - fn catalog_footer( - &self, - status: Option<&'static str>, - more: Option, - cx: &Context, - ) -> Div { + fn prefetch_next_page(&self, window: &Window, cx: &mut Context) { + let Some(page) = self.next_page else { + return; + }; + if self.pending.is_some() || self.failed.is_some() { + return; + } + + let ranking = self.ranking; + // Start the request after layout and recheck in case another pass queued it. + cx.defer_in(window, move |view, _, cx| { + if view.ranking == ranking + && view.query.is_empty() + && view.detail.is_none() + && view.next_page == Some(page) + && view.pending.is_none() + && view.failed.is_none() + { + view.load(Request::Browse(ranking, page), cx); + } + }); + } + + fn catalog_footer(&self, status: Option<&'static str>, cx: &Context) -> Div { h_flex() .gap_2() .when_some(status, |row, message| { @@ -277,17 +296,6 @@ impl Skills { })) )) }) - .when_some(more, |row, page| { - row.child(control!( - "Load more", - Button::new("more-skills") - .small() - .label("Load more") - .on_click(cx.listener(move |view, _, _, cx| { - view.load(Request::Browse(view.ranking, page), cx); - })) - )) - }) } } @@ -313,19 +321,18 @@ impl Render for Skills { None }; - let more = self - .next_page - .filter(|_| self.pending.is_none() && self.failed.is_none()); - let has_footer = status.is_some() || more.is_some(); let list = uniform_list( "skills-results", - self.rows.len() + usize::from(has_footer), - cx.processor(move |view, range: std::ops::Range, _, cx| { + self.rows.len() + usize::from(status.is_some()), + cx.processor(move |view, range: std::ops::Range, window, cx| { + if !range.is_empty() && range.end.saturating_add(PREFETCH_ROWS) >= view.rows.len() { + view.prefetch_next_page(window, cx); + } range .map(|index| { let row = match view.rows.get(index) { Some(skill) => skill.row(index, cx), - None => view.catalog_footer(status, more, cx), + None => view.catalog_footer(status, cx), }; h_flex().w_full().h(rems(3.5)).justify_center().child( v_flex()