diff --git a/spotify_player/src/state/model.rs b/spotify_player/src/state/model.rs index 94777792..f5596eb7 100644 --- a/spotify_player/src/state/model.rs +++ b/spotify_player/src/state/model.rs @@ -224,7 +224,7 @@ pub struct PlaylistFolderNode { pub children: Vec, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq)] /// A Spotify category pub struct Category { pub id: String, diff --git a/spotify_player/src/state/ui/mod.rs b/spotify_player/src/state/ui/mod.rs index 27f7b9f1..a29e39ea 100644 --- a/spotify_player/src/state/ui/mod.rs +++ b/spotify_player/src/state/ui/mod.rs @@ -61,8 +61,13 @@ impl UIState { } pub fn new_page(&mut self, page: PageState) { - self.history.push(page); self.popup = None; + if let Some(current_page) = self.history.last() { + if &page == current_page { + return; + } + } + self.history.push(page); } /// Return whether there exists a focused popup. diff --git a/spotify_player/src/state/ui/page.rs b/spotify_player/src/state/ui/page.rs index 6239d1b0..90a93928 100644 --- a/spotify_player/src/state/ui/page.rs +++ b/spotify_player/src/state/ui/page.rs @@ -4,7 +4,7 @@ use crate::{ }; use ratatui::widgets::{ListState, TableState}; -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq)] pub enum PageState { Library { state: LibraryPageUIState, @@ -50,7 +50,7 @@ pub enum PageType { Logs, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq)] pub struct LibraryPageUIState { pub playlist_list: ListState, pub saved_album_list: ListState, @@ -59,7 +59,7 @@ pub struct LibraryPageUIState { pub playlist_folder_id: usize, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq)] pub struct SearchPageUIState { pub track_list: ListState, pub album_list: ListState, @@ -70,13 +70,13 @@ pub struct SearchPageUIState { pub focus: SearchFocusState, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq)] pub enum ContextPageType { CurrentPlaying, Browsing(ContextId), } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq)] pub enum ContextPageUIState { Playlist { track_table: TableState, @@ -123,7 +123,7 @@ pub enum SearchFocusState { Episodes, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq)] pub enum BrowsePageUIState { CategoryList { state: ListState, diff --git a/spotify_player/src/ui/single_line_input.rs b/spotify_player/src/ui/single_line_input.rs index c3b9c504..987b382c 100644 --- a/spotify_player/src/ui/single_line_input.rs +++ b/spotify_player/src/ui/single_line_input.rs @@ -4,7 +4,7 @@ use ratatui::widgets::Widget; use super::{Line, Modifier, Paragraph, Span, Style}; use crate::key::Key; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub struct LineInput { // This is less space-efficient than String, but it's easier to work with text manipulation at the // cursor. Otherwise, you have to shuffle back and forth between String and String::chars().