added new sorting and higher limit
This commit is contained in:
+37
-7
@@ -4,7 +4,7 @@ use color_eyre::{
|
||||
eyre::{WrapErr, eyre},
|
||||
};
|
||||
use crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers};
|
||||
use radiobrowser::RadioBrowserAPI;
|
||||
use radiobrowser::{RadioBrowserAPI, StationOrder};
|
||||
use ratatui::{
|
||||
DefaultTerminal, Frame,
|
||||
layout::{Constraint, Layout},
|
||||
@@ -204,10 +204,20 @@ impl App {
|
||||
Style::default()
|
||||
};
|
||||
|
||||
ListItem::new(Line::from(vec![
|
||||
let name_line = Line::from(vec![
|
||||
Span::styled(name, name_style),
|
||||
Span::styled(meta, Style::default().add_modifier(Modifier::DIM)),
|
||||
]))
|
||||
]);
|
||||
|
||||
let mut lines = vec![name_line];
|
||||
if !s.tags.is_empty() {
|
||||
let tag_str: String = s.tags.chars().take(available_width).collect();
|
||||
lines.push(Line::from(Span::styled(
|
||||
tag_str,
|
||||
Style::default().fg(Color::DarkGray),
|
||||
)));
|
||||
}
|
||||
ListItem::new(ratatui::text::Text::from(lines))
|
||||
})
|
||||
.collect();
|
||||
|
||||
@@ -395,9 +405,9 @@ impl App {
|
||||
.map_err(|e| eyre!("Failed to create RadioBrowserAPI: {e}"))?;
|
||||
|
||||
let (de, us, at) = tokio::try_join!(
|
||||
async { api.get_stations().country("Germany").send().await.map_err(|e| eyre!("Failed to fetch DE stations: {e}")) },
|
||||
async { api.get_stations().country("United States").send().await.map_err(|e| eyre!("Failed to fetch US stations: {e}")) },
|
||||
async { api.get_stations().country("Austria").send().await.map_err(|e| eyre!("Failed to fetch AT stations: {e}")) },
|
||||
async { api.get_stations().country("Germany").order(StationOrder::Clickcount).reverse(true).limit("5000").send().await.map_err(|e| eyre!("Failed to fetch DE stations: {e}")) },
|
||||
async { api.get_stations().country("United States").order(StationOrder::Clickcount).reverse(true).limit("5000").send().await.map_err(|e| eyre!("Failed to fetch US stations: {e}")) },
|
||||
async { api.get_stations().country("Austria").order(StationOrder::Clickcount).reverse(true).limit("5000").send().await.map_err(|e| eyre!("Failed to fetch AT stations: {e}")) },
|
||||
)?;
|
||||
|
||||
let mut seen_urls = std::collections::HashSet::new();
|
||||
@@ -415,7 +425,9 @@ impl App {
|
||||
country_code: s.countrycode,
|
||||
bitrate: s.bitrate,
|
||||
codec: s.codec,
|
||||
tags: s.tags,
|
||||
})
|
||||
|
||||
})
|
||||
.collect();
|
||||
|
||||
@@ -434,7 +446,10 @@ impl App {
|
||||
self.filtered_stations = self
|
||||
.stations
|
||||
.iter()
|
||||
.filter(|s| s.name.to_lowercase().contains(&query))
|
||||
.filter(|s| {
|
||||
s.name.to_lowercase().contains(&query)
|
||||
|| s.tags.to_lowercase().contains(&query)
|
||||
})
|
||||
.cloned()
|
||||
.collect();
|
||||
}
|
||||
@@ -508,6 +523,7 @@ mod tests {
|
||||
country_code: "DE".to_string(),
|
||||
bitrate: 128,
|
||||
codec: "MP3".to_string(),
|
||||
tags: String::new(),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
@@ -683,6 +699,20 @@ mod tests {
|
||||
assert_eq!(app.filtered_stations[0].name, "Jazz Radio");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn search_matches_tags() {
|
||||
let mut app = app_with(&["Station A", "Station B"]);
|
||||
app.stations[0].tags = "jazz,blues".to_string();
|
||||
app.stations[1].tags = "pop,rock".to_string();
|
||||
app.filtered_stations = app.stations.clone();
|
||||
app.input_mode = InputMode::Search;
|
||||
for c in "jazz".chars() {
|
||||
app.handle_key_event(key(KeyCode::Char(c))).await;
|
||||
}
|
||||
assert_eq!(app.filtered_stations.len(), 1);
|
||||
assert_eq!(app.filtered_stations[0].name, "Station A");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn search_is_case_insensitive() {
|
||||
let mut app = app_with(&["Rock FM", "Jazz Radio"]);
|
||||
|
||||
@@ -5,4 +5,5 @@ pub struct StationInfo {
|
||||
pub country_code: String,
|
||||
pub bitrate: u32,
|
||||
pub codec: String,
|
||||
pub tags: String,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user