mirror of
https://github.com/yattee/yattee.git
synced 2024-11-09 15:58:20 +00:00
Previews environment objects fixtures
This commit is contained in:
parent
29e042a8bf
commit
ef5c75a2bc
@ -47,4 +47,13 @@ extension Video {
|
||||
static var allFixtures: [Video] {
|
||||
[fixture, fixtureLiveWithoutPublishedOrViews, fixtureUpcomingWithoutPublishedOrViews]
|
||||
}
|
||||
|
||||
static func fixtures(_ count: Int) -> [Video] {
|
||||
var result = [Video]()
|
||||
while result.count < count {
|
||||
result.append(allFixtures.shuffled().first!)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
22
Fixtures/View+Fixtures.swift
Normal file
22
Fixtures/View+Fixtures.swift
Normal file
@ -0,0 +1,22 @@
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
struct FixtureEnvironmentObjectsModifier: ViewModifier {
|
||||
func body(content: Content) -> some View {
|
||||
content
|
||||
.environmentObject(InstancesModel())
|
||||
.environmentObject(InvidiousAPI())
|
||||
.environmentObject(NavigationModel())
|
||||
.environmentObject(PlaybackModel())
|
||||
.environmentObject(PlaylistsModel())
|
||||
.environmentObject(RecentsModel())
|
||||
.environmentObject(SearchModel())
|
||||
.environmentObject(SubscriptionsModel(api: InvidiousAPI()))
|
||||
}
|
||||
}
|
||||
|
||||
extension View {
|
||||
func injectFixtureEnvironmentObjects() -> some View {
|
||||
modifier(FixtureEnvironmentObjectsModifier())
|
||||
}
|
||||
}
|
@ -8,8 +8,8 @@ final class InvidiousAPI: Service, ObservableObject {
|
||||
|
||||
@Published var account: Instance.Account! = .empty
|
||||
|
||||
@Published var validInstance = true
|
||||
@Published var signedIn = true
|
||||
@Published var validInstance = false
|
||||
@Published var signedIn = false
|
||||
|
||||
func setAccount(_ account: Instance.Account) {
|
||||
self.account = account
|
||||
|
@ -265,6 +265,9 @@
|
||||
37FD43DE2704717F0073EE42 /* DefaultAccountHint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37FD43DD2704717F0073EE42 /* DefaultAccountHint.swift */; };
|
||||
37FD43DF2704717F0073EE42 /* DefaultAccountHint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37FD43DD2704717F0073EE42 /* DefaultAccountHint.swift */; };
|
||||
37FD43E02704717F0073EE42 /* DefaultAccountHint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37FD43DD2704717F0073EE42 /* DefaultAccountHint.swift */; };
|
||||
37FD43E32704847C0073EE42 /* View+Fixtures.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37FD43E22704847C0073EE42 /* View+Fixtures.swift */; };
|
||||
37FD43E42704847C0073EE42 /* View+Fixtures.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37FD43E22704847C0073EE42 /* View+Fixtures.swift */; };
|
||||
37FD43E52704847C0073EE42 /* View+Fixtures.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37FD43E22704847C0073EE42 /* View+Fixtures.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
@ -402,6 +405,7 @@
|
||||
37F64FE326FE70A60081B69E /* RedrawOnViewModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RedrawOnViewModifier.swift; sourceTree = "<group>"; };
|
||||
37FD43DB270470B70073EE42 /* InstancesSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstancesSettingsView.swift; sourceTree = "<group>"; };
|
||||
37FD43DD2704717F0073EE42 /* DefaultAccountHint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultAccountHint.swift; sourceTree = "<group>"; };
|
||||
37FD43E22704847C0073EE42 /* View+Fixtures.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+Fixtures.swift"; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@ -554,6 +558,7 @@
|
||||
37F49BA226CAA59B00304AC0 /* Playlist+Fixtures.swift */,
|
||||
3748186926A764FB0084E870 /* Thumbnail+Fixtures.swift */,
|
||||
3748186526A7627F0084E870 /* Video+Fixtures.swift */,
|
||||
37FD43E22704847C0073EE42 /* View+Fixtures.swift */,
|
||||
);
|
||||
path = Fixtures;
|
||||
sourceTree = "<group>";
|
||||
@ -1073,6 +1078,7 @@
|
||||
378E50FF26FE8EEE00F49626 /* AccountsMenuView.swift in Sources */,
|
||||
37C7A1DA267CACF50010EAD6 /* TrendingCountry.swift in Sources */,
|
||||
37977583268922F600DD52A8 /* InvidiousAPI.swift in Sources */,
|
||||
37FD43E32704847C0073EE42 /* View+Fixtures.swift in Sources */,
|
||||
37BE0BD626A1D4A90092E2DB /* PlayerViewController.swift in Sources */,
|
||||
37BA793F26DB8F97002A0235 /* ChannelVideosView.swift in Sources */,
|
||||
37C194C726F6A9C8005D3B96 /* RecentsModel.swift in Sources */,
|
||||
@ -1208,6 +1214,7 @@
|
||||
37B767DC2677C3CA0098BAA8 /* PlayerModel.swift in Sources */,
|
||||
3797758C2689345500DD52A8 /* Store.swift in Sources */,
|
||||
37141674267A8E10006CA35D /* Country.swift in Sources */,
|
||||
37FD43E42704847C0073EE42 /* View+Fixtures.swift in Sources */,
|
||||
37AAF2A126741C97007FC770 /* SubscriptionsView.swift in Sources */,
|
||||
37732FF12703A26300F04329 /* ValidationStatusView.swift in Sources */,
|
||||
37BA794C26DC30EC002A0235 /* AppSidebarPlaylists.swift in Sources */,
|
||||
@ -1310,6 +1317,7 @@
|
||||
379775952689365600DD52A8 /* Array+Next.swift in Sources */,
|
||||
3705B180267B4DFB00704544 /* TrendingCountry.swift in Sources */,
|
||||
373CFACD26966264003CB2C6 /* SearchQuery.swift in Sources */,
|
||||
37FD43E52704847C0073EE42 /* View+Fixtures.swift in Sources */,
|
||||
37141675267A8E10006CA35D /* Country.swift in Sources */,
|
||||
37152EEC26EFEB95004FB96D /* LazyView.swift in Sources */,
|
||||
37484C2726FC83E000287258 /* InstanceFormView.swift in Sources */,
|
||||
|
@ -61,5 +61,6 @@ struct ContentView: View {
|
||||
struct ContentView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ContentView()
|
||||
.injectFixtureEnvironmentObjects()
|
||||
}
|
||||
}
|
||||
|
@ -186,6 +186,6 @@ struct VideoDetails: View {
|
||||
struct VideoDetails_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
VideoDetails(video: Video.fixture)
|
||||
.environmentObject(SubscriptionsModel())
|
||||
.injectFixtureEnvironmentObjects()
|
||||
}
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ struct VideoPlayerView_Previews: PreviewProvider {
|
||||
}
|
||||
.sheet(isPresented: .constant(true)) {
|
||||
VideoPlayerView(Video.fixture)
|
||||
.environmentObject(NavigationModel())
|
||||
.injectFixtureEnvironmentObjects()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -171,8 +171,6 @@ struct AddToPlaylistView: View {
|
||||
struct AddToPlaylistView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
AddToPlaylistView(video: Video.fixture)
|
||||
.environmentObject(PlaylistsModel([Playlist.fixture]))
|
||||
.environmentObject(SubscriptionsModel())
|
||||
.environmentObject(NavigationModel())
|
||||
.injectFixtureEnvironmentObjects()
|
||||
}
|
||||
}
|
||||
|
@ -220,6 +220,6 @@ struct PlaylistsView: View {
|
||||
struct PlaylistsView_Provider: PreviewProvider {
|
||||
static var previews: some View {
|
||||
PlaylistsView()
|
||||
.environmentObject(NavigationModel())
|
||||
.injectFixtureEnvironmentObjects()
|
||||
}
|
||||
}
|
||||
|
@ -65,11 +65,7 @@ struct SettingsView: View {
|
||||
struct SettingsView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
SettingsView()
|
||||
.environmentObject(InstancesModel())
|
||||
.environmentObject(InvidiousAPI())
|
||||
.environmentObject(NavigationModel())
|
||||
.environmentObject(SearchModel())
|
||||
.environmentObject(SubscriptionsModel())
|
||||
.injectFixtureEnvironmentObjects()
|
||||
#if os(macOS)
|
||||
.frame(width: 600, height: 300)
|
||||
#endif
|
||||
|
@ -4,7 +4,7 @@ import SwiftUI
|
||||
|
||||
struct TrendingView: View {
|
||||
@StateObject private var store = Store<[Video]>()
|
||||
private var videos: [Video]
|
||||
private var videos = [Video]()
|
||||
|
||||
@Default(.trendingCategory) private var category
|
||||
@Default(.trendingCountry) private var country
|
||||
@ -149,9 +149,7 @@ struct TrendingView: View {
|
||||
|
||||
struct TrendingView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
TrendingView(Video.allFixtures + Video.allFixtures + Video.allFixtures)
|
||||
.environmentObject(InvidiousAPI())
|
||||
.environmentObject(NavigationModel())
|
||||
.environmentObject(SubscriptionsModel())
|
||||
TrendingView(Video.allFixtures)
|
||||
.injectFixtureEnvironmentObjects()
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,6 @@ struct VideosCellsHorizontal: View {
|
||||
struct VideoCellsHorizontal_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
VideosCellsHorizontal(videos: Video.allFixtures)
|
||||
.environmentObject(NavigationModel())
|
||||
.environmentObject(SubscriptionsModel())
|
||||
.injectFixtureEnvironmentObjects()
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +75,6 @@ struct VideosCellsVertical: View {
|
||||
struct VideoCellsVertical_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
VideosCellsVertical(videos: Video.allFixtures)
|
||||
.frame(minWidth: 1000)
|
||||
.environmentObject(NavigationModel())
|
||||
.injectFixtureEnvironmentObjects()
|
||||
}
|
||||
}
|
||||
|
@ -20,8 +20,11 @@ struct SearchView: View {
|
||||
@EnvironmentObject<RecentsModel> private var recents
|
||||
@EnvironmentObject<SearchModel> private var state
|
||||
|
||||
init(_ query: SearchQuery? = nil) {
|
||||
private var videos = [Video]()
|
||||
|
||||
init(_ query: SearchQuery? = nil, videos: [Video] = [Video]()) {
|
||||
self.query = query
|
||||
self.videos = videos
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
@ -82,6 +85,10 @@ struct SearchView: View {
|
||||
state.queryText = query!.query
|
||||
state.resetQuery(query!)
|
||||
}
|
||||
|
||||
if !videos.isEmpty {
|
||||
state.store.replace(videos)
|
||||
}
|
||||
}
|
||||
.searchable(text: $state.queryText, placement: searchFieldPlacement) {
|
||||
ForEach(state.querySuggestions.collection, id: \.self) { suggestion in
|
||||
@ -269,7 +276,7 @@ struct SearchView: View {
|
||||
|
||||
var searchDurationButton: some View {
|
||||
Button(action: { self.searchDuration = self.searchDuration.next() }) {
|
||||
Text(self.searchDate.name)
|
||||
Text(self.searchDuration.name)
|
||||
.font(.system(size: 30))
|
||||
.padding(.horizontal)
|
||||
.padding(.vertical, 2)
|
||||
@ -334,10 +341,8 @@ struct SearchView: View {
|
||||
struct SearchView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
NavigationView {
|
||||
SearchView(SearchQuery(query: "Is Google Evil"))
|
||||
.environmentObject(NavigationModel())
|
||||
.environmentObject(SearchModel())
|
||||
.environmentObject(SubscriptionsModel())
|
||||
SearchView(SearchQuery(query: "Is Google Evil"), videos: Video.fixtures(30))
|
||||
.injectFixtureEnvironmentObjects()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -44,9 +44,11 @@ struct SignInRequiredView<Content: View>: View {
|
||||
.font(.title3)
|
||||
.padding(.vertical)
|
||||
|
||||
if instances.isEmpty {
|
||||
openSettingsButton
|
||||
}
|
||||
#if !os(tvOS)
|
||||
if instances.isEmpty {
|
||||
openSettingsButton
|
||||
}
|
||||
#endif
|
||||
|
||||
#if os(tvOS)
|
||||
openSettingsButton
|
||||
@ -73,5 +75,6 @@ struct SignInRequiredView_Previews: PreviewProvider {
|
||||
SignInRequiredView(title: "Subscriptions") {
|
||||
Text("Only when signed in")
|
||||
}
|
||||
.environmentObject(InvidiousAPI())
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,6 @@ struct WatchNowView: View {
|
||||
struct WatchNowView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
WatchNowView()
|
||||
.environmentObject(SubscriptionsModel())
|
||||
.environmentObject(NavigationModel())
|
||||
.injectFixtureEnvironmentObjects()
|
||||
}
|
||||
}
|
||||
|
@ -122,6 +122,6 @@ struct InstancesSettingsView_Previews: PreviewProvider {
|
||||
InstancesSettingsView()
|
||||
}
|
||||
.frame(width: 400, height: 270)
|
||||
.environmentObject(InstancesModel())
|
||||
.injectFixtureEnvironmentObjects()
|
||||
}
|
||||
}
|
||||
|
@ -57,10 +57,6 @@ struct TVNavigationView: View {
|
||||
struct TVNavigationView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
TVNavigationView()
|
||||
.environmentObject(InvidiousAPI())
|
||||
.environmentObject(NavigationModel())
|
||||
.environmentObject(SearchModel())
|
||||
.environmentObject(InstancesModel())
|
||||
.environmentObject(SubscriptionsModel())
|
||||
.injectFixtureEnvironmentObjects()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user