SPB Git

Repository Public BSD-3-Clause

ExplorerScreen.swift 8.3 KB 188 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : ORIX Maps9// File             : Apps/ORIXMaps/Sources/Explore/ExplorerScreen.swift10// Module           : Explore11// Repository       : https://git.spboucher.ai/orix-maps12// Created          : 2026-11-2513// Last Modified    : 2026-11-2514//15// =============================================================================16// AUTHOR & PROFESSIONAL AFFILIATION17// =============================================================================18//19// Author           : Simon-Pierre Boucher20// Position         : Professor of Finance21// Institution      : Université du Québec en Outaouais (UQO)22// Department       : Département des sciences administratives23// Organization     : SP Boucher24//25// Website          : https://spboucher.ai26// Git              : https://git.spboucher.ai27//28// =============================================================================29// OFFICIAL CONTACT DIRECTORY30// =============================================================================31//32// General          : info@spboucher.ai33// Professional     : contact@spboucher.ai34// Direct           : simon@spboucher.ai35// Research         : research@spboucher.ai36// Development      : dev@spboucher.ai37// Support          : support@spboucher.ai38// Security/Admin   : admin@spboucher.ai39// Notifications    : notifications@spboucher.ai40//41// Preferred Contact: support@spboucher.ai42//43// =============================================================================44// COPYRIGHT & INTELLECTUAL PROPERTY45// =============================================================================46//47// Copyright (c) 202648// Simon-Pierre Boucher49//50// All rights reserved where applicable.51//52// This file is governed by the applicable project license,53// copyright notices, institutional agreements and relevant law.54//55// Unless expressly authorized by the applicable license or56// rights holder, copying, redistribution, sublicensing,57// publication and commercial exploitation are not permitted.58//59// Existing third-party rights and notices remain unaffected.60//61// =============================================================================62// CONFIDENTIALITY & SECURITY63// =============================================================================64//65// Classification   : Public66// Distribution     : Public repository; use is governed by the project license67// Security Contact : admin@spboucher.ai68//69// Access to this source does not independently grant permission70// to redistribute or disclose confidential materials.71//72// Do not embed credentials, private keys, access tokens,73// certificates or confidential personal information.74//75// =============================================================================76// LICENSE & MAINTENANCE77// =============================================================================78//79// License          : Proprietary, all rights reserved (see license file)80// License File     : LICENSE81// Maintainer       : Simon-Pierre Boucher82// Technical Contact: dev@spboucher.ai83//84// =============================================================================85// END OF SP BOUCHER SOURCE HEADER86// =============================================================================8788import ORIXDesignSystem89import ORIXGeoCore90import ORIXSearch91import SwiftUI9293/// ORIX Explorer: places worth a visit around the centre of the map, from the installed regions' data only.94struct ExplorerScreen: View {95    @Environment(AppModel.self) private var app96    @State private var theme = Theme.sights97    @State private var results: [SearchResult] = []98    @State private var loading = false99100    enum Theme: String, CaseIterable, Identifiable {101        case sights, viewpoints, nature, culture, food, family102        var id: String { rawValue }103        var title: LocalizedStringKey {104            switch self {105            case .sights: "Sights"106            case .viewpoints: "Viewpoints"107            case .nature: "Nature"108            case .culture: "Culture"109            case .food: "Food and drink"110            case .family: "Family"111            }112        }113        var symbol: String {114            switch self {115            case .sights: "star"116            case .viewpoints: "binoculars"117            case .nature: "leaf"118            case .culture: "building.columns"119            case .food: "fork.knife"120            case .family: "figure.2.and.child.holdinghands"121            }122        }123        var categories: Set<PlaceCategory> {124            switch self {125            case .sights: [.attraction, .viewpoint, .museum]126            case .viewpoints: [.viewpoint, .peak]127            case .nature: [.park, .beach, .waterfall, .peak, .picnicSite]128            case .culture: [.museum, .theatre, .cinema, .library]129            case .food: [.restaurant, .cafe, .bakery, .bar]130            case .family: [.playground, .park, .museum, .picnicSite]131            }132        }133    }134135    private var language: String { app.settings.interfaceLanguageCode }136137    var body: some View {138        List {139            Section {140                ScrollView(.horizontal, showsIndicators: false) {141                    HStack(spacing: ORIX.Spacing.s) {142                        ForEach(Theme.allCases) { t in Chip(t.title, systemImage: t.symbol, isSelected: t == theme) { theme = t } }143                    }144                }145                .listRowInsets(EdgeInsets(top: 8, leading: 16, bottom: 8, trailing: 0))146            }147            if !app.search.hasIndex {148                EmptyStateView("Nothing to explore yet", message: "Explorer lists places from the regions installed on this device. Download a region first.", systemImage: "binoculars") {149                    Button("Browse maps") { app.modal = .downloads }.buttonStyle(PrimaryButtonStyle(tint: AppColor.primaryFill))150                }151                .frame(maxWidth: .infinity).listRowBackground(Color.clear)152            } else if loading {153                HStack { ProgressView(); Text("Looking around the map…").foregroundStyle(.secondary) }154            } else if results.isEmpty {155                Text("Nothing of this kind was found around the centre of the map in the installed regions.").foregroundStyle(.secondary)156            } else {157                Section {158                    ForEach(results) { r in159                        Button {160                            app.modal = nil161                            app.select(r.selection(language: language), moveCamera: true)162                        } label: {163                            HStack(spacing: ORIX.Spacing.m) {164                                Image(systemName: r.symbol).frame(width: 34, height: 34).foregroundStyle(ORIX.Palette.accent).background(ORIX.Palette.accent.opacity(0.12), in: .circle).accessibilityHidden(true)165                                VStack(alignment: .leading, spacing: 1) {166                                    Text(r.name.isEmpty ? (r.category?.label(languageCode: language) ?? "") : r.name).foregroundStyle(Color.primary)167                                    Text(verbatim: [r.category?.label(languageCode: language), r.secondaryLine].compactMap { $0 }.filter { !$0.isEmpty }.joined(separator: " · ")).font(.footnote).foregroundStyle(Color.secondary).lineLimit(1)168                                }169                                Spacer()170                                if let d = r.distance { Text(verbatim: app.settings.formatter.distance(d)).font(.footnote.monospacedDigit()).foregroundStyle(Color.secondary) }171                            }172                        }173                    }174                } footer: {175                    Text("Sorted by distance from the centre of the map. The list reflects what OpenStreetMap contributors mapped; it has no ratings, opening hours or recommendations.")176                }177            }178        }179        .navigationTitle("Explore")180        .navigationBarTitleDisplayMode(.inline)181        .task(id: theme) {182            loading = true183            results = await app.search.explore(theme.categories)184            loading = false185        }186    }187}188
Files main
Menu

Theme