Skip to content

Commit 0b1e11b

Browse files
committed
✨ Improve empty state
Signed-off-by: Peter Friese <[email protected]>
1 parent 62d75b1 commit 0b1e11b

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

Examples/FriendlyFlix/app/FriendlyFlix/FriendlyFlix/Features/Library/LibraryScreen.swift

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@ import FriendlyFlixSDK
2222

2323
struct LibraryScreen: View {
2424
@Namespace var namespace
25-
@Environment(AuthenticationService.self) var authenticationViewModel
25+
@Environment(AuthenticationService.self) var authenticationService
2626

2727
private var connector = DataConnect.friendlyFlixConnector
2828

29+
private var isSignedIn: Bool {
30+
authenticationService.user != nil
31+
}
32+
2933
init() {
3034
watchListRef = connector.getUserFavoriteMoviesQuery.ref()
3135
}
@@ -34,21 +38,24 @@ struct LibraryScreen: View {
3438
private var watchList: [Movie] {
3539
watchListRef.data?.user?.favoriteMovies.map(Movie.init) ?? []
3640
}
41+
42+
private func presentSignInDialog() {
43+
authenticationService.presentingAuthenticationDialog.toggle()
44+
}
3745
}
3846

3947
extension LibraryScreen {
4048
var body: some View {
4149
NavigationStack {
4250
ScrollView {
43-
if authenticationViewModel.authenticationState == .authenticated {
51+
if isSignedIn {
4452
Group {
4553
MovieListSection(namespace: namespace, title: "Watch List", movies: watchList)
4654
.onAppear {
4755
Task {
4856
try await watchListRef.execute()
4957
}
5058
}
51-
5259
// TODO: insert section with list of all movies the user has rated
5360
}
5461
.padding()
@@ -73,11 +80,16 @@ extension LibraryScreen {
7380
}
7481
}
7582
.overlay {
76-
if authenticationViewModel.authenticationState == .unauthenticated {
83+
if !isSignedIn {
7784
ContentUnavailableView {
7885
Label("Your library is empty", systemImage: "rectangle.on.rectangle.slash")
7986
} description: {
80-
Text("Your watch list and favourites will appear here.")
87+
VStack {
88+
Text("Your watch list and favourites will appear here once you sign in.")
89+
Button(action: presentSignInDialog) {
90+
Text("Sign in")
91+
}
92+
}
8193
}
8294
}
8395
}

0 commit comments

Comments
 (0)