Properly select active queue item

This commit is contained in:
chmanie 2023-06-02 20:29:06 +02:00
parent 553f34a111
commit c19b025818
1 changed files with 15 additions and 15 deletions

View File

@ -157,7 +157,6 @@ enum UiItemKind {
} }
struct UiItem { struct UiItem {
active: bool,
uuid: String, uuid: String,
title: String, title: String,
kind: UiItemKind, kind: UiItemKind,
@ -185,10 +184,9 @@ impl ListView for QueueView {
} }
impl QueueView { impl QueueView {
// FIXME: implement skip on server
fn skip(&self, tx: &Sender<MessageFromUi>) { fn skip(&self, tx: &Sender<MessageFromUi>) {
if self.current_position < self.get_size() - 1 { if self.current_position < self.get_size() - 1 {
tx.send(MessageFromUi::SetCurrentTrack(self.current_position + 1)); tx.send(MessageFromUi::Next);
} }
} }
fn play_selected(&self, tx: &Sender<MessageFromUi>) { fn play_selected(&self, tx: &Sender<MessageFromUi>) {
@ -199,7 +197,7 @@ impl QueueView {
fn update_position(&mut self, pos: usize) { fn update_position(&mut self, pos: usize) {
self.current_position = pos; self.current_position = pos;
} }
fn update(&mut self, queue: Queue) { fn update_queue(&mut self, queue: Queue) {
self.current_position = queue.current_position as usize; self.current_position = queue.current_position as usize;
self.list = queue self.list = queue
.tracks .tracks
@ -209,7 +207,6 @@ impl QueueView {
uuid: t.uuid.clone(), uuid: t.uuid.clone(),
title: format!("{} - {}", t.artist, t.title), title: format!("{} - {}", t.artist, t.title),
kind: UiItemKind::Track, kind: UiItemKind::Track,
active: i == queue.current_position as usize,
}) })
.collect(); .collect();
@ -292,7 +289,6 @@ impl LibraryView {
uuid: t.uuid.clone(), uuid: t.uuid.clone(),
title: format!("{} - {}", t.artist, t.title), title: format!("{} - {}", t.artist, t.title),
kind: UiItemKind::Track, kind: UiItemKind::Track,
active: false,
}) })
.collect(); .collect();
} else { } else {
@ -304,7 +300,6 @@ impl LibraryView {
uuid: c.uuid.clone(), uuid: c.uuid.clone(),
title: c.title.clone(), title: c.title.clone(),
kind: UiItemKind::Node, kind: UiItemKind::Node,
active: false,
}) })
.collect(); .collect();
} }
@ -393,6 +388,7 @@ enum MessageToUi {
// FIXME: Rename this // FIXME: Rename this
enum MessageFromUi { enum MessageFromUi {
GetLibraryNode(String), GetLibraryNode(String),
Next,
ReplaceQueue(String), ReplaceQueue(String),
SetCurrentTrack(usize), SetCurrentTrack(usize),
TogglePlay, TogglePlay,
@ -420,6 +416,9 @@ async fn poll(
MessageFromUi::SetCurrentTrack(pos) => { MessageFromUi::SetCurrentTrack(pos) => {
rpc_client.set_current_track(pos).await? rpc_client.set_current_track(pos).await?
} }
MessageFromUi::Next => {
// FIXME:
}
} }
} }
@ -495,7 +494,7 @@ fn run_ui(tx: Sender<MessageFromUi>, rx: Receiver<MessageToUi>) {
} }
MessageToUi::Init(init_data) => { MessageToUi::Init(init_data) => {
if let Some(queue) = init_data.queue { if let Some(queue) = init_data.queue {
app.queue.update(queue); app.queue.update_queue(queue);
} }
if let Some(track) = init_data.queue_track { if let Some(track) = init_data.queue_track {
app.now_playing.update_track(track.track); app.now_playing.update_track(track.track);
@ -507,7 +506,7 @@ fn run_ui(tx: Sender<MessageFromUi>, rx: Receiver<MessageToUi>) {
} }
MessageToUi::Update(update) => match update { MessageToUi::Update(update) => match update {
StreamUpdate::Queue(queue) => { StreamUpdate::Queue(queue) => {
app.queue.update(queue); app.queue.update_queue(queue);
} }
StreamUpdate::QueueTrack(track) => { StreamUpdate::QueueTrack(track) => {
app.now_playing.update_track(track.track); app.now_playing.update_track(track.track);
@ -665,14 +664,15 @@ fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
.queue .queue
.list .list
.iter() .iter()
.map(|i| { .enumerate()
// let color = if i.active { COLOR_RED } else { Color::Reset }; .map(|(idx, item)| {
let title = if i.active { let active = idx == app.queue.current_position;
format!("> {}", i.title) let title = if active {
format!("> {}", item.title)
} else { } else {
i.title.to_string() item.title.to_string()
}; };
let style = if i.active { let style = if active {
Style::default().add_modifier(Modifier::BOLD) Style::default().add_modifier(Modifier::BOLD)
} else { } else {
Style::default() Style::default()