From 2481045a9c75a81420c42f89b0cff991f7345147 Mon Sep 17 00:00:00 2001 From: Selim Mustafaev Date: Fri, 20 Dec 2024 21:56:45 +0300 Subject: [PATCH] Sharing event --- AutoCat/Screens/EventsScreen/EventsScreen.swift | 4 ++++ AutoCat/Screens/EventsScreen/EventsViewModel.swift | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/AutoCat/Screens/EventsScreen/EventsScreen.swift b/AutoCat/Screens/EventsScreen/EventsScreen.swift index 163fe66..fd15fae 100644 --- a/AutoCat/Screens/EventsScreen/EventsScreen.swift +++ b/AutoCat/Screens/EventsScreen/EventsScreen.swift @@ -129,6 +129,10 @@ struct EventsScreen: View { } label: { Label("Open in Maps", systemImage: "map") } + + if let link = viewModel.getMapLink(for: event) { + ShareLink(item: link) + } } } } diff --git a/AutoCat/Screens/EventsScreen/EventsViewModel.swift b/AutoCat/Screens/EventsScreen/EventsViewModel.swift index 138b1a8..9b2c928 100644 --- a/AutoCat/Screens/EventsScreen/EventsViewModel.swift +++ b/AutoCat/Screens/EventsScreen/EventsViewModel.swift @@ -132,9 +132,9 @@ class EventsViewModel: ACHudContainer { } } - func getMapLink(for event: VehicleEventDto) -> URL? { - var urlString = "http://maps.apple.com/?sll=\(event.latitude),\(event.longitude)" - if let address = event.address?.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) { + func getMapLink(for event: EventModel) -> URL? { + var urlString = "http://maps.apple.com/?sll=\(event.coordinate.latitude),\(event.coordinate.longitude)" + if let address = event.address.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) { urlString = urlString + "&address=" + address } return URL(string: urlString) @@ -146,7 +146,7 @@ class EventsViewModel: ACHudContainer { } let sharedData: [String: Any?] = [ - UTType.url.identifier: getMapLink(for: eventDto), + UTType.url.identifier: getMapLink(for: event), UTType.vehicleEvent.identifier: try? JSONEncoder().encode(eventDto) ]