45 lines
1.1 KiB
Swift
45 lines
1.1 KiB
Swift
//
|
|
// AlloVictorApp.swift
|
|
// AlloVictor
|
|
//
|
|
// Created by Bodinaud Victor on 13/04/2024.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
@main
|
|
struct AlloVictorApp: App {
|
|
|
|
@StateObject private var viewModel = AlloVictorViewModel()
|
|
@StateObject private var appState = AppState()
|
|
|
|
private func fetchOffers() async {
|
|
do {
|
|
try await viewModel.getDatas()
|
|
} catch {
|
|
print(error.localizedDescription)
|
|
}
|
|
}
|
|
|
|
var body: some Scene {
|
|
WindowGroup {
|
|
NavigationStack(path: $appState.routes) {
|
|
OffersListScreen()
|
|
.navigationDestination(for: Route.self) { route in
|
|
switch route {
|
|
case .offers:
|
|
OffersListScreen()
|
|
case .detail(let offer):
|
|
OfferDetailsScreen(offerDetails: offer)
|
|
}
|
|
}
|
|
}
|
|
.task {
|
|
await fetchOffers()
|
|
}
|
|
.environmentObject(viewModel)
|
|
.environmentObject(appState)
|
|
}
|
|
}
|
|
}
|