-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContentView.swift
54 lines (44 loc) · 1.48 KB
/
ContentView.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
//
// ContentView.swift
// TopWeather
//
// Created by MD FARID on 25/11/23.
//
import SwiftUI
struct ContentView: View {
@StateObject var locationManager = LocationManager()
var weatherManager = WeatherManager()
@State var weather: ResponseBody?
var body: some View {
VStack {
if let location = locationManager.location {
if let weather = weather {
WeatherView(weather: weather)
} else {
LoadingView()
.task {
do {
weather = try await weatherManager .getCurrentWeather(latitude: location.latitude, longitude: location.longitude)
} catch {
print ("error getting weather: \(error)")
}
}
}
} else {
if locationManager.isLoading {
LoadingView()
} else {
WelcomeView()
.environmentObject(locationManager)
}
}
}
.background(Color(hue: 0.664, saturation: 0.953, brightness: 0.718))
.preferredColorScheme(.dark)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}