Last active
December 20, 2021 17:15
-
-
Save hmlongco/e12acaa6799eeee5ea750f05b4e3fc6d to your computer and use it in GitHub Desktop.
LoadingView state dispatch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct LoadingView: View { | |
@StateObject var viewModel = ViewModel() | |
var body: some View { | |
switch viewModel.state { | |
case .initial, .loading: | |
ProgressView() | |
.onAppear(perform: viewModel.load) | |
case .empty(let message): | |
Text(message) | |
.foregroundColor(.secondaryBrand) | |
case .error(let error): | |
Text(error) | |
.foregroundColor(.error) | |
case .loaded(let items): | |
ContentItemList(items: items) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment