// // launchesView.swift // spacex // // Created by Charlie Kingsland on 23/01/2021. // import SwiftUI import SDWebImage import HalfModal import Foundation struct launchView: View { @State var launches: [Launch] = [] // @State private var showingAlert = false @State private var show_modal: Bool = false @State private var mName: String = "" @State private var mDate: String = "" @State private var rID: String = "" @State private var mImg: String = "" @State private var mDesc: String = "" @State private var mYT: String = "" @State private var ytBool: Bool = false @State private var rName: String = "" @State private var showingHalfModal: Bool = false var body: some View { ZStack { NavigationView { VStack { // Spacer() // .frame(height: 10) // Text("SpaceX launch list") // .font(.largeTitle) Spacer() .frame(height: 1) .navigationBarTitle("Launches") List { ForEach(launches, id: \.id) { launch in // Text("image") // Image("imagenotfound") Button(action: { self.mName = launch.name self.mDate = Date(timeIntervalSince1970: launch.date_unix).getFormattedDate(format: "dd/MM/yyyy HH:mm:ss") self.rID = launch.rocket self.mImg = launch.links.patch.missionPatch ?? "null" self.mDesc = launch.details ?? "No description" self.mYT = launch.links.youtube_id ?? "none" if self.mYT == "none" { self.ytBool = false } else { self.ytBool = true } // sleep(1) self.show_modal.toggle() withAnimation { self.showingHalfModal = true } }) { HStack { // Image("imagenotfound") // .resizable() // .frame(width: 50, height: 50) URLimageView(urlString: launch.links.patch.missionPatch) // .frame(width: 50, height: 50) Group { Text(launch.name) .font(.system(size: 23)) .frame(maxWidth: .infinity, alignment: .leading) .fixedSize(horizontal: false, vertical: true) Text(Date(timeIntervalSince1970: launch.date_unix).getFormattedDate(format: "dd/MM/yyyy HH:mm:ss")) .font(.system(size: 11.5)) .foregroundColor(Color.gray) .frame(maxWidth: .infinity, alignment: .leading) .fixedSize(horizontal: false, vertical: true) Spacer() } } } .buttonStyle(PlainButtonStyle()) } } }.onAppear { apiCall().getUsers{ (launches) in self.launches = launches} }.listStyle(SidebarListStyle()) .frame(alignment: .center) } } if showingHalfModal { HalfModalView(content: AnyView(HStack { VStack { Text(mDesc) .padding() Link("Watch webcast", destination: URL(string: "https://www.youtube.com/watch?v=" + mYT)!) .disabled(!ytBool) } }), header: AnyView(HStack { URLimageView(urlString: self.mImg) VStack(alignment: .leading) { Text(self.mName) Text(self.mDate) .font(.system(size: 10)) .foregroundColor(Color.gray) }}), isPresented: $showingHalfModal) } } } struct launchesView_Previews: PreviewProvider { static var previews: some View { launchView() } }