Skip to content

Commit

Permalink
Rebase and fix crash from sidebar
Browse files Browse the repository at this point in the history
* API changed
* Even playlist button doesn't exist on sidebar, crash shouldn't
  happen
  • Loading branch information
sangwoo108 committed Jul 13, 2023
1 parent 2694f2a commit b3a6e33
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
5 changes: 2 additions & 3 deletions browser/ui/views/playlist/playlist_action_bubble_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,6 @@ ConfirmBubble::ConfirmBubble(Browser* browser,
}

void ConfirmBubble::OpenInPlaylist() {
auto* side_panel_coordinator =
PlaylistSidePanelCoordinator::FromBrowser(browser_);

// Technically, the saved items could belong to multiple playlists
// at the same time and their parent playlists could be different from each
// other's. But for simplicity, we just open the first one assuming that most
Expand All @@ -167,6 +164,8 @@ void ConfirmBubble::OpenInPlaylist() {
const std::string& playlist_id = saved_items.front()->parents.front();
const std::string& item_id = saved_items.front()->id;

auto* side_panel_coordinator =
PlaylistSidePanelCoordinator::FromBrowser(browser_);
CHECK(side_panel_coordinator);
side_panel_coordinator->ActivatePanel();
side_panel_coordinator->LoadPlaylist(playlist_id, item_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,8 @@ void PlaylistSidePanelCoordinator::CreateAndRegisterEntry(
void PlaylistSidePanelCoordinator::ActivatePanel() {
auto* sidebar_controller =
static_cast<BraveBrowser*>(browser_.get())->sidebar_controller();
auto* sidebar_model = sidebar_controller->model();
const auto& sidebar_items = sidebar_model->GetAllSidebarItems();
auto iter = base::ranges::find_if(sidebar_items, [](const auto& item) {
return item.built_in_item_type ==
sidebar::SidebarItem::BuiltInItemType::kPlaylist;
});
sidebar_controller->ActivateItemAt(
std::distance(sidebar_items.begin(), iter));
sidebar_controller->ActivatePanelItem(
sidebar::SidebarItem::BuiltInItemType::kPlaylist);
}

void PlaylistSidePanelCoordinator::LoadPlaylist(const std::string& playlist_id,
Expand Down
4 changes: 3 additions & 1 deletion browser/ui/views/sidebar/sidebar_container_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -662,9 +662,11 @@ void SidebarContainerView::OnEntryShown(SidePanelEntry* entry) {
auto side_bar_index = sidebar_model_->GetIndexOf(item);
auto* controller = browser_->sidebar_controller();
controller->ActivateItemAt(side_bar_index);
break;
return;
}
}

ShowSidebarAll();
}

void SidebarContainerView::OnEntryHidden(SidePanelEntry* entry) {
Expand Down

0 comments on commit b3a6e33

Please sign in to comment.