@@ -26,6 +26,10 @@ struct HomeScreen: View {
2626
2727 private var connector = DataConnect . friendlyFlixConnector
2828
29+ private var isSignedIn : Bool {
30+ authenticationService. user != nil
31+ }
32+
2933 private func mapMovie( _ listMovie: ListMoviesQuery . Data . Movie ) -> Movie {
3034 . init(
3135 title: listMovie. title,
@@ -59,16 +63,6 @@ struct HomeScreen: View {
5963 watchListRef. data? . user? . favoriteMovies. map ( Movie . init) ?? [ ]
6064 }
6165
62- private var featuredMovies : [ Movie ] {
63- /// TODO: build query that retrieves movies that are marked as "featured"
64- connector. listMoviesQuery
65- . ref ( { optionalVars in
66- optionalVars. limit = 5
67- optionalVars. orderByRating = . DESC
68- } )
69- . data? . movies. map ( Movie . init) ?? [ ]
70- }
71-
7266 init ( ) {
7367 watchListRef = connector. getUserFavoriteMoviesQuery. ref ( )
7468 }
@@ -96,13 +90,14 @@ extension HomeScreen {
9690
9791 Group {
9892 MovieListSection ( namespace: namespace, title: " Top Movies " , movies: topMovies)
99- MovieListSection ( namespace: namespace, title: " Watch List " , movies: watchList)
100- . onAppear {
101- Task {
102- try await watchListRef. execute ( )
93+ if isSignedIn {
94+ MovieListSection ( namespace: namespace, title: " Watch List " , movies: watchList)
95+ . onAppear {
96+ Task {
97+ try await watchListRef. execute ( )
98+ }
10399 }
104- }
105- MovieListSection ( namespace: namespace, title: " Featured " , movies: featuredMovies)
100+ }
106101 }
107102 . navigationDestination ( for: [ Movie ] . self) { movies in
108103 MovieListScreen ( namespace: namespace, movies: movies)
0 commit comments