From 4af395d78867d6acc81d7b8519d61ce713126449 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Fri, 11 Jun 2021 23:54:00 +0200 Subject: [PATCH] Fix navigation tabs --- Apple TV/ChannelView.swift | 5 ----- Apple TV/PopularVideosView.swift | 2 +- Apple TV/SearchView.swift | 2 +- Apple TV/VideosView.swift | 20 ++++++++++---------- Model/Video.swift | 11 ++++++++++- Pearvidious.xcodeproj/project.pbxproj | 4 ++-- 6 files changed, 24 insertions(+), 20 deletions(-) diff --git a/Apple TV/ChannelView.swift b/Apple TV/ChannelView.swift index c3d962e8..a462a8ae 100644 --- a/Apple TV/ChannelView.swift +++ b/Apple TV/ChannelView.swift @@ -8,11 +8,6 @@ struct ChannelView: View { var body: some View { VideosView(state: state, tabSelection: $tabSelection, videos: videos) - .task { - async { - provider.load() - } - } } var listRowInsets: EdgeInsets { diff --git a/Apple TV/PopularVideosView.swift b/Apple TV/PopularVideosView.swift index 4d865fa6..9d9a6b95 100644 --- a/Apple TV/PopularVideosView.swift +++ b/Apple TV/PopularVideosView.swift @@ -3,7 +3,7 @@ import SwiftUI struct PopularVideosView: View { @ObservedObject private var provider = PopularVideosProvider() @ObservedObject var state: AppState - + @Binding var tabSelection: TabSelection var body: some View { diff --git a/Apple TV/SearchView.swift b/Apple TV/SearchView.swift index f80dc2a2..40ea0e33 100644 --- a/Apple TV/SearchView.swift +++ b/Apple TV/SearchView.swift @@ -12,7 +12,7 @@ struct SearchView: View { VideosView(state: state, tabSelection: $tabSelection, videos: videos) .searchable(text: $query) } - + var videos: [Video] { var newQuery = query diff --git a/Apple TV/VideosView.swift b/Apple TV/VideosView.swift index 9cf6f71e..8832d16d 100644 --- a/Apple TV/VideosView.swift +++ b/Apple TV/VideosView.swift @@ -2,7 +2,7 @@ import SwiftUI struct VideosView: View { @ObservedObject var state: AppState - + @Binding var tabSelection: TabSelection var videos: [Video] @@ -13,7 +13,7 @@ struct VideosView: View { ForEach(videos) { video in VideoThumbnailView(video: video) .contextMenu { - if state.showingChannel { + if tabSelection == .channel { closeChannelButton(name: video.author) } else { openChannelButton(from: video) @@ -25,14 +25,7 @@ struct VideosView: View { .listStyle(GroupedListStyle()) } } - - func closeChannelButton(name: String) -> some View { - Button("Close \(name) Channel", action: { - state.closeChannel() - tabSelection = .popular - }) - } - + func openChannelButton(from video: Video) -> some View { Button("\(video.author) Channel", action: { state.openChannel(from: video) @@ -40,6 +33,13 @@ struct VideosView: View { }) } + func closeChannelButton(name: String) -> some View { + Button("Close \(name) Channel", action: { + tabSelection = .popular + state.closeChannel() + }) + } + var listRowInsets: EdgeInsets { EdgeInsets(top: .zero, leading: .zero, bottom: .zero, trailing: 30) } diff --git a/Model/Video.swift b/Model/Video.swift index fa10cbe9..1656deda 100644 --- a/Model/Video.swift +++ b/Model/Video.swift @@ -16,7 +16,16 @@ final class Video: Identifiable, ObservableObject { @Published var url: URL? @Published var error: Bool = false - init(id: String, title: String, thumbnailURL: URL?, author: String, length: TimeInterval, published: String, channelID: String, views: Int = 0) { + init( + id: String, + title: String, + thumbnailURL: URL?, + author: String, + length: TimeInterval, + published: String, + channelID: String, + views: Int = 0 + ) { self.id = id self.title = title self.thumbnailURL = thumbnailURL diff --git a/Pearvidious.xcodeproj/project.pbxproj b/Pearvidious.xcodeproj/project.pbxproj index 3f94a91e..37ef1511 100644 --- a/Pearvidious.xcodeproj/project.pbxproj +++ b/Pearvidious.xcodeproj/project.pbxproj @@ -243,10 +243,10 @@ 37AAF28F26740715007FC770 /* AppState.swift */, 37D4B19626717E1500C925CA /* Video.swift */, 37D4B19226717CE100C925CA /* PopularVideosProvider.swift */, + 37AAF28B2673ABD3007FC770 /* ChannelVideosProvider.swift */, + 37AAF2812673791F007FC770 /* SearchedVideosProvider.swift */, 37D4B1B32672A30700C925CA /* VideoDetailsProvider.swift */, 37D4B1AF2672A01000C925CA /* DataProvider.swift */, - 37AAF2812673791F007FC770 /* SearchedVideosProvider.swift */, - 37AAF28B2673ABD3007FC770 /* ChannelVideosProvider.swift */, ); path = Model; sourceTree = "";