From 5b0f6397d6db0448b1c5046dfcea55c5b0572268 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Tue, 14 Jun 2022 18:12:06 +0200 Subject: [PATCH] Minor style change --- Shared/Search/SearchView.swift | 96 ++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 46 deletions(-) diff --git a/Shared/Search/SearchView.swift b/Shared/Search/SearchView.swift index f59b534f..b87628bd 100644 --- a/Shared/Search/SearchView.swift +++ b/Shared/Search/SearchView.swift @@ -286,52 +286,7 @@ struct SearchView: View { .foregroundColor(.secondary) } ForEach(recentItems) { item in - Button { - switch item.type { - case .query: - state.queryText = item.title - state.changeQuery { query in query.query = item.title } - - updateFavoriteItem() - recents.add(item) - case .channel: - guard let channel = item.channel else { - return - } - - NavigationModel.openChannel( - channel, - player: player, - recents: recents, - navigation: navigation, - navigationStyle: navigationStyle, - delay: false - ) - case .playlist: - guard let playlist = item.playlist else { - return - } - - NavigationModel.openChannelPlaylist( - playlist, - player: player, - recents: recents, - navigation: navigation, - navigationStyle: navigationStyle, - delay: false - ) - } - } label: { - let systemImage = item.type == .query ? "magnifyingglass" : - item.type == .channel ? RecentsModel.symbolSystemImage(item.title) : - "list.and.film" - Label(item.title, systemImage: systemImage) - .lineLimit(1) - } - .contextMenu { - removeButton(item) - removeAllButton - } + recentItemButton(item) } } .redrawOn(change: recentsChanged) @@ -342,6 +297,55 @@ struct SearchView: View { #endif } + private func recentItemButton(_ item: RecentItem) -> some View { + Button { + switch item.type { + case .query: + state.queryText = item.title + state.changeQuery { query in query.query = item.title } + + updateFavoriteItem() + recents.add(item) + case .channel: + guard let channel = item.channel else { + return + } + + NavigationModel.openChannel( + channel, + player: player, + recents: recents, + navigation: navigation, + navigationStyle: navigationStyle, + delay: false + ) + case .playlist: + guard let playlist = item.playlist else { + return + } + + NavigationModel.openChannelPlaylist( + playlist, + player: player, + recents: recents, + navigation: navigation, + navigationStyle: navigationStyle, + delay: false + ) + } + } label: { + let systemImage = item.type == .query ? "magnifyingglass" : + item.type == .channel ? RecentsModel.symbolSystemImage(item.title) : + "list.and.film" + Label(item.title, systemImage: systemImage) + .lineLimit(1) + } + .contextMenu { + removeButton(item) + removeAllButton + } + } + private func removeButton(_ item: RecentItem) -> some View { Button { recents.close(item)