Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
A236929E27E2719700D7CE27 /* NewDS+CornerRadius.swift in Sources */ = {isa = PBXBuildFile; fileRef = A236929927E2719700D7CE27 /* NewDS+CornerRadius.swift */; };
A236929F27E2719700D7CE27 /* NewDSNamespace.swift in Sources */ = {isa = PBXBuildFile; fileRef = A236929A27E2719700D7CE27 /* NewDSNamespace.swift */; };
A23692A027E2719700D7CE27 /* NewDS+Colors.swift in Sources */ = {isa = PBXBuildFile; fileRef = A236929B27E2719700D7CE27 /* NewDS+Colors.swift */; };
B4FBCC2B27E3C7520050C6A0 /* ErrorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4FBCC2A27E3C7520050C6A0 /* ErrorView.swift */; };
E58D8FDF27DFF8B0006F16EC /* SpaceAppApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = E58D8FDE27DFF8B0006F16EC /* SpaceAppApp.swift */; };
E58D8FED27DFF96C006F16EC /* HomeViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = E58D8FEB27DFF96C006F16EC /* HomeViewModel.swift */; };
E58D8FEE27DFF96C006F16EC /* HomeScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = E58D8FEC27DFF96C006F16EC /* HomeScene.swift */; };
Expand Down Expand Up @@ -81,6 +82,7 @@
A236929927E2719700D7CE27 /* NewDS+CornerRadius.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NewDS+CornerRadius.swift"; sourceTree = "<group>"; };
A236929A27E2719700D7CE27 /* NewDSNamespace.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NewDSNamespace.swift; sourceTree = "<group>"; };
A236929B27E2719700D7CE27 /* NewDS+Colors.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NewDS+Colors.swift"; sourceTree = "<group>"; };
B4FBCC2A27E3C7520050C6A0 /* ErrorView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ErrorView.swift; sourceTree = "<group>"; };
E58D8FDE27DFF8B0006F16EC /* SpaceAppApp.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpaceAppApp.swift; sourceTree = "<group>"; };
E58D8FEB27DFF96C006F16EC /* HomeViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HomeViewModel.swift; sourceTree = "<group>"; };
E58D8FEC27DFF96C006F16EC /* HomeScene.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HomeScene.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -429,6 +431,7 @@
E58D902B27DFFB65006F16EC /* EmptyView.swift */,
94E94FF727E0DED5003CA84B /* LoadingView.swift */,
E58D902C27DFFB65006F16EC /* NavigationSceneView.swift */,
B4FBCC2A27E3C7520050C6A0 /* ErrorView.swift */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -591,6 +594,7 @@
E58D902E27DFFB65006F16EC /* EmptyView.swift in Sources */,
E58D902727DFFB42006F16EC /* SpaceButtonStyle.swift in Sources */,
94E94FF827E0DED5003CA84B /* LoadingView.swift in Sources */,
B4FBCC2B27E3C7520050C6A0 /* ErrorView.swift in Sources */,
E58D8FFD27DFFA27006F16EC /* SpaceXAPIClient.swift in Sources */,
A236929E27E2719700D7CE27 /* NewDS+CornerRadius.swift in Sources */,
94E94FFF27E0E19B003CA84B /* View+PreviewSquare.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//
// ErrorView.swift
// SpaceApp
//
// Created by Elena Diniz on 3/10/22.
//

import SwiftUI

struct ErrorView: View {
private let title: String
private let subtitle: String
private let dismissAction: (() -> Void)?

init(title: String,
subtitle: String,
dismissAction: (() -> Void)? = nil) {
self.title = title
self.subtitle = subtitle
self.dismissAction = dismissAction
}

var body: some View {
VStack(alignment: .center) {
Image(systemName: "exclamationmark.circle.fill")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 200, height: 200, alignment: .center)
.clipShape(Circle())

Text(title)
.font(.title)
.multilineTextAlignment(.center)

Text(subtitle)
.font(.subheadline)
.multilineTextAlignment(.center)

// Button(action: {
// guard let dismissAction = dismissAction else {
// return
// }
// dismissAction()
// },
// label: {
// Text("OK")
// .bold()
// .frame(width: 200, height: 48)
// .foregroundColor(Color.white)
// .background(Color.gray)
// .cornerRadius(5)
// })
}
.padding()
}
}

#if DEBUG
struct ErrorView_Previews: PreviewProvider {
static var previews: some View {
ErrorView(title: "Title",
subtitle: "Put your substitle here!",
dismissAction: {})
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,41 @@ struct HomeScene: View {

private func launchesTab() -> some View {
NavigationSceneView(title: L10n.Common.appTitle) {
List(viewModel.launches) { launch in
NavigationLink(
destination: LaunchDetailsScene(
viewModel: DetailsViewModel(
initialState: .init(details: launch),
environment: .init(someDetailsAPI: SomeDetailsAPI())
if let errorMessage = viewModel.errorMessage {
ErrorView(title: "Ops, something went wrong!", subtitle: "Check your internet connection and try again.") {
.navigationBarItems(
leading:
Button(action: {
List(viewModel.loadLaunches())
}, label: {
Text("OK")
.bold()
.foregroundColor(Color.black)
}))
}
} else {
List(viewModel.launches) { launch in
NavigationLink(
destination: LaunchDetailsScene(
viewModel: DetailsViewModel(
initialState: .init(details: launch),
environment: .init(someDetailsAPI: SomeDetailsAPI())
)
)
)
) {
Text("\(launch.name)")
) {
Text("\(launch.name)")
}
}
.onAppear { viewModel.loadLaunches() }
}
.onAppear { viewModel.loadLaunches() }
}
.tabItem {
Label(
L10n.HomeScene.launchesTitle,
systemImage: "location.north.fill"
)
.tabItem {
Label(
L10n.HomeScene.launchesTitle,
systemImage: "location.north.fill"
)
}
.tag(HomeTabs.launches)
}
.tag(HomeTabs.launches)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import SwiftUI
struct HomeState: Equatable {
var launches: [Launch] = []
var selectedTabIndex: HomeTabs = .home
var errorMessage: String?
}

// MARK: - Environment
Expand Down Expand Up @@ -40,7 +41,12 @@ final class HomeViewModel: ObservableObject {

func loadLaunches() {
environment.spaceXAPI.fetchAllLaunches { launches in
self.state.launches = launches ?? []
guard let launches = launches else {
self.state.errorMessage = ""
return
}

self.state.launches = launches
}
}
}
Expand Down