-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDetailCountry.swift
90 lines (78 loc) · 3.87 KB
/
DetailCountry.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
// DetailCountry.swift
// SupHealth
//
// Created by Yahia Berrada on 6/18/20.
// Copyright © 2020 Supinfo. All rights reserved.
//
import SwiftUI
//struct for displaying the details data of a country
struct DetailCountry: View {
var country: DataModel
@State var textToUpdate1 = "Add to favorites"
@State var textToUpdate2 = "Remove from favorites"
@State var img1 = "star1"
@State var img2 = "star2"
var body: some View {
VStack{
HStack{
if favorites.contains(where: { $0.Country == self.country.Country }) { // if the country is not in the favorite
Button(action: {
//remove the country with the index
let index = favorites.firstIndex(where: { $0.Country == self.country.Country })
favorites.remove(at: index!)
// msg
self.textToUpdate1 = "Add to favorites"
self.img1 = "star1"
self.textToUpdate2 = "Add to favorites"
self.img2 = "star1"
}) {
Image(img2)
.renderingMode(.original)
.resizable()
.frame(width: 50.0, height: 50.0)
Text(textToUpdate2)
}
}else {
Button(action: {
//add the object to the array
let data = DataModel(Country: self.country.Country,
CountryCode: self.country.CountryCode,
NewConfirmed: self.country.NewConfirmed,
TotalConfirmed: self.country.TotalConfirmed,
NewDeaths: self.country.NewDeaths,
TotalDeaths: self.country.TotalDeaths,
NewRecovered: self.country.NewRecovered,
TotalRecovered: self.country.TotalRecovered)
favorites.append(data)
//msg
self.textToUpdate1 = "Remove from favorites"
self.img1 = "star2"
self.textToUpdate2 = "Remove from favorites"
self.img2 = "star2"
}) {
Image(img1)
.renderingMode(.original)
.resizable()
.frame(width: 50.0, height: 50.0)
Text(textToUpdate1)
}
}
}
HStack{
RemoteImage(url: "https://www.countryflags.io/\(country.CountryCode)/flat/64.png")
Text("\(country.Country)").font(Font.system(size:20, design: .default).bold())
}
VStack{
List{
Text("New confirmed: \(country.NewConfirmed)").font(Font.system(size:17, design: .default).bold()).foregroundColor(Color.red)
Text("Total confirmed: \(country.TotalConfirmed)")
Text("New deaths: \(country.NewDeaths)").font(Font.system(size:17, design: .default).bold()).foregroundColor(Color.red)
Text("Total deaths: \(country.TotalDeaths)")
Text("New recovered: \(country.NewRecovered)").font(Font.system(size:17, design: .default).bold()).foregroundColor(Color.green)
Text("Total recovered: \(country.TotalRecovered)")
}
}.padding()
}
}
}