// // FeedView.swift // tst // // Created by Vitaly Takmazov on 10.12.2019. // Copyright © 2019 com.juick. All rights reserved. // import SwiftUI enum FeedType { case messages case thread } struct FeedView: View { @ObservedObject var messageFetcher : MessageFetcher let feedType : FeedType init(url: String, type: FeedType) { feedType = type messageFetcher = MessageFetcher(url: url) } private var stateContent: AnyView { switch messageFetcher.state { case .loading: return AnyView( ActivityIndicator(style: .medium) ) case .fetched(let result): switch result { case .failure(let error): return AnyView( Text(error.localizedDescription) ) case .success(let root): return AnyView( List(root) { (message: MessageFetcher.MessageData) in let destination = feedType == .thread ? AnyView(Text("YO")) : AnyView(FeedView(url: "https://api.juick.com/thread?mid=\(message.message.mid.stringValue)", type: .thread)) ZStack { MessageView(message: message.message).listRowInsets(.none) NavigationLink( destination: destination) { EmptyView() } } } .listRowInsets(.none) ) } } } var body: some View { stateContent .navigationBarTitle(Text("Messages"), displayMode: .inline) } } struct FeedView_Previews: PreviewProvider { static var previews: some View { FeedView(url: "https://api.juick.com/messages", type: .messages) } }