mirror of
https://github.com/tareqimbasher/cargo-seek.git
synced 2026-01-09 07:52:41 +08:00
Show crate categories in details pane
This commit is contained in:
parent
899f87109b
commit
89af14ef73
@ -369,7 +369,10 @@ fn handle_search_action(home: &mut Home, action: SearchAction) -> AppResult<Opti
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn load_metadata_if_needed(results: &mut SearchResults, crate_search_manager: &mut CrateSearchManager) {
|
||||
fn load_metadata_if_needed(
|
||||
results: &mut SearchResults,
|
||||
crate_search_manager: &mut CrateSearchManager,
|
||||
) {
|
||||
if let Some(cr) = results.selected()
|
||||
&& !cr.is_metadata_loaded()
|
||||
{
|
||||
|
||||
@ -486,6 +486,14 @@ fn render_crate_details(home: &Home, cr: &Crate, frame: &mut Frame, area: Rect)
|
||||
.unwrap_or("Loading...".into())
|
||||
.into(),
|
||||
]),
|
||||
Line::from(vec![
|
||||
format!("{:<left_column_width$}", "Categories:").set_style(prop_style),
|
||||
cr.categories
|
||||
.as_ref()
|
||||
.map(|v| v.join(", "))
|
||||
.unwrap_or("Loading...".into())
|
||||
.into(),
|
||||
]),
|
||||
Line::from(vec![
|
||||
format!("{:<left_column_width$}", "Created:").set_style(prop_style),
|
||||
match cr.created_at.as_ref() {
|
||||
@ -519,11 +527,11 @@ fn render_crate_details(home: &Home, cr: &Crate, frame: &mut Frame, area: Rect)
|
||||
frame.render_widget(&main_block, area);
|
||||
|
||||
let [details_area, _, buttons_row1_area, _, buttons_row2_area] = Layout::vertical([
|
||||
Constraint::Max(25),
|
||||
Constraint::Length(1),
|
||||
Constraint::Length(1),
|
||||
Constraint::Length(1),
|
||||
Constraint::Length(1),
|
||||
Constraint::Max(20), // details
|
||||
Constraint::Length(1), // empty line
|
||||
Constraint::Length(1), // buttons row 1
|
||||
Constraint::Length(1), // empty line
|
||||
Constraint::Length(1), // buttons row 2
|
||||
])
|
||||
.areas(main_block.inner(area));
|
||||
|
||||
|
||||
@ -15,6 +15,7 @@ pub struct Crate {
|
||||
pub downloads: Option<u64>,
|
||||
pub recent_downloads: Option<u64>,
|
||||
pub features: Option<Vec<String>>,
|
||||
pub categories: Option<Vec<String>>,
|
||||
pub created_at: Option<DateTime<Utc>>,
|
||||
pub updated_at: Option<DateTime<Utc>>,
|
||||
|
||||
|
||||
@ -182,6 +182,7 @@ impl CrateSearchManager {
|
||||
created_at: None,
|
||||
updated_at: None,
|
||||
features: None,
|
||||
categories: None,
|
||||
exact_match: name_lower == term,
|
||||
project_version: None,
|
||||
installed_version: Some(bin.version.clone()),
|
||||
@ -214,6 +215,7 @@ impl CrateSearchManager {
|
||||
created_at: None,
|
||||
updated_at: None,
|
||||
features: None,
|
||||
categories: None,
|
||||
exact_match: name_lower == term,
|
||||
project_version: Some(dep.req.clone()),
|
||||
installed_version: None,
|
||||
@ -273,6 +275,7 @@ impl CrateSearchManager {
|
||||
created_at: Some(c.created_at),
|
||||
updated_at: Some(c.updated_at),
|
||||
features: None,
|
||||
categories: c.categories,
|
||||
exact_match: c.exact_match.unwrap_or(false),
|
||||
project_version: None,
|
||||
installed_version: None,
|
||||
@ -373,6 +376,15 @@ impl CrateSearchManager {
|
||||
let latest = &crate_response.versions[0];
|
||||
cr.features = Some(latest.features.iter().map(|x| x.0.clone()).collect())
|
||||
}
|
||||
if cr.categories.is_none() {
|
||||
cr.categories = Some(
|
||||
crate_response
|
||||
.categories
|
||||
.iter()
|
||||
.map(|c| c.category.clone())
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
cr.created_at = Some(data.created_at);
|
||||
cr.updated_at = Some(data.updated_at);
|
||||
cr.exact_match = data.exact_match.unwrap_or_default();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user