diff options
Diffstat (limited to 'JuickNext')
-rw-r--r-- | JuickNext/Helpers/Errors.swift (renamed from JuickNext/LoadableState.swift) | 9 | ||||
-rw-r--r-- | JuickNext/MessageFetcher.swift | 12 | ||||
-rw-r--r-- | JuickNext/View/FeedView.swift (renamed from JuickNext/FeedView.swift) | 25 | ||||
-rw-r--r-- | JuickNext/View/LoadableImageView.swift (renamed from JuickNext/LoadableImageView.swift) | 0 | ||||
-rw-r--r-- | JuickNext/View/MessageView.swift (renamed from JuickNext/MessageView.swift) | 0 |
5 files changed, 19 insertions, 27 deletions
diff --git a/JuickNext/LoadableState.swift b/JuickNext/Helpers/Errors.swift index a45edb2..5c47a70 100644 --- a/JuickNext/LoadableState.swift +++ b/JuickNext/Helpers/Errors.swift @@ -1,6 +1,6 @@ // -// LoadableState.swift -// tst +// Errors.swift +// JuickNext // // Created by Vitaly Takmazov on 10.12.2019. // Copyright © 2019 com.juick. All rights reserved. @@ -8,11 +8,6 @@ import Foundation -enum LoadableState<T> { - case loading - case fetched(Result<T, FetchError>) -} - enum FetchError: Error { case error(String) diff --git a/JuickNext/MessageFetcher.swift b/JuickNext/MessageFetcher.swift index 565cca0..8a150b8 100644 --- a/JuickNext/MessageFetcher.swift +++ b/JuickNext/MessageFetcher.swift @@ -1,6 +1,6 @@ // // MessageFetcher.swift -// tst +// JuickNext // // Created by Vitaly Takmazov on 10.12.2019. // Copyright © 2019 com.juick. All rights reserved. @@ -11,28 +11,28 @@ import Combine class MessageFetcher: ObservableObject { - @Published var state: LoadableState<Root> = .loading + @Published var state: Result<Root, FetchError>? = nil init(url: String) { guard let apiUrl = URL(string: url) else { - state = .fetched(.failure(.error("Malformed API URL."))) + state = .failure(.error("Malformed API URL.")) return } URLSession.shared.dataTask(with: apiUrl) { [weak self] (data, _, error) in if let error = error { - self?.state = .fetched(.failure(.error(error.localizedDescription))) + self?.state = .failure(.error(error.localizedDescription)) return } guard let data = data else { - self?.state = .fetched(.failure(.error("Malformed response data"))) + self?.state = .failure(.error("Malformed response data")) return } let root = try! JSONDecoder().decode(Root.self, from: data) DispatchQueue.main.async { [weak self] in - self?.state = .fetched(.success(root)) + self?.state = .success(root) } }.resume() } diff --git a/JuickNext/FeedView.swift b/JuickNext/View/FeedView.swift index 7e293bd..3a612e8 100644 --- a/JuickNext/FeedView.swift +++ b/JuickNext/View/FeedView.swift @@ -20,23 +20,20 @@ struct FeedView: View { private var stateContent: AnyView { switch messageFetcher.state { - case .loading: + case nil: return AnyView( ProgressView() ) - case .fetched(let result): - switch result { - case .failure(let error): - return AnyView( - Text(error.localizedDescription) - ) - case .success(let root): - return AnyView( - List(root) { (message: Message) in - MessageView(message: message) - } - ) - } + case .failure(let error): + return AnyView( + Text(error.localizedDescription) + ) + case .success(let root): + return AnyView( + List(root) { (message: Message) in + MessageView(message: message) + } + ) } } diff --git a/JuickNext/LoadableImageView.swift b/JuickNext/View/LoadableImageView.swift index 6a41dc2..6a41dc2 100644 --- a/JuickNext/LoadableImageView.swift +++ b/JuickNext/View/LoadableImageView.swift diff --git a/JuickNext/MessageView.swift b/JuickNext/View/MessageView.swift index 398978b..398978b 100644 --- a/JuickNext/MessageView.swift +++ b/JuickNext/View/MessageView.swift |