Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix confirmation dialog handling on playlist delete. #910

Merged
merged 2 commits into from
Nov 17, 2021
Merged

Fix confirmation dialog handling on playlist delete. #910

merged 2 commits into from
Nov 17, 2021

Conversation

majabojarska
Copy link
Contributor

Resolves #884.

Observations

I might not know the architecture of this application very well, but I believe I've narrowed down the root cause and drafted a quick solution. As of commit ecddb5e, the push_navigation_stack method of the App class does not actually push any element to the navigation stack if the next route's id is the same as last route's id:

// app.rs
pub fn push_navigation_stack(&mut self, next_route_id: RouteId, next_active_block: ActiveBlock) {
    if !self
      .navigation_stack
      .last()
      .map(|last_route| last_route.id == next_route_id)
      .unwrap_or(false)
    { // Enter branch only if the last route's id is different from the next route's id.
      // Push to stack...
    }
  }

That's the case when the uppercase D character is entered, when a playlist is selected - the last route's id is the same as the next route's id (RouteId::Home):

// playlist.rs
Key::Char('D') => {
      if let (Some(playlists), Some(selected_index)) = (&app.playlists, app.selected_playlist_index)
      {
        let selected_playlist = &playlists.items[selected_index].name;
        app.dialog = Some(selected_playlist.clone());
        app.confirm = false;

        let route = app.get_current_route().id.clone(); // Pass current route's id as the next route's id
        app.push_navigation_stack(route, ActiveBlock::Dialog(DialogContext::PlaylistWindow));
      }
    }

As a result, no new element is pushed to the navigation stack, hence the confirmation dialog window does not appear, and the playlist cannot be deleted.

Solution

My solution is to add a RouteId::Dialog, which is specific to confirmation dialog windows. When a dialog is to be opened (e.g. when deleting a playlist), a new route (different than the current one) is pushed onto the navigation stack. Then, the logic responsible for drawing and handling user input in the confirmation dialog gets executed and works just fine.

@Rigellute
Copy link
Owner

Excellent write up and excellent solution. Thank you!

@Rigellute
Copy link
Owner

@majabojarska looks like there is a clippy error, are you able to fix that please?

@majabojarska
Copy link
Contributor Author

Fixed 😉

@Rigellute
Copy link
Owner

Great work @majabojarska, thanks again.

@Rigellute Rigellute merged commit 7550d6e into Rigellute:master Nov 17, 2021
@Rigellute
Copy link
Owner

@allcontributors please add @majabojarska for code

@allcontributors
Copy link
Contributor

@Rigellute

I've put up a pull request to add @majabojarska! 🎉

@majabojarska majabojarska deleted the fix_playlist_delete branch November 17, 2021 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"D" to delete playlist does not work
2 participants