-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGlossary.swift
More file actions
81 lines (75 loc) · 3.26 KB
/
Glossary.swift
File metadata and controls
81 lines (75 loc) · 3.26 KB
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
//
// Glossary.swift
// awsary (iOS)
//
// Created by Tiago Rodrigues on 10/11/2024.
//
import SwiftUI
import SwiftData
struct Glossary: View {
@State private var showingSheet = false
@ObservedObject var awsServices = AwsServices()
@State private var searchQuery = ""
@Environment(\.colorScheme) var colorScheme
@Environment(\.modelContext) private var modelContext
@Query(filter: #Predicate<SystemSetting> { $0.key == "awsServiceLogoWithLabel" }) var logoSettings: [SystemSetting]
// Cached property for awsServiceLogoWithLabel setting to reduce database queries
private var awsServiceLogoWithLabel: Bool {
return logoSettings.first?.boolValue ?? true
}
var filteredAwsServices: [awsService] {
if searchQuery.isEmpty {
return awsServices.services
} else {
return awsServices.services.filter { $0.name.lowercased().contains(searchQuery.lowercased()) }
}
}
var body: some View {
NavigationStack{
ScrollView{
if awsServices.isLoading {
ProgressView("Loading AWS Services...")
.frame(maxWidth: .infinity, maxHeight: .infinity)
.padding()
} else {
LazyVGrid(
columns: [GridItem(.adaptive(minimum: 100))], content: {
ForEach(filteredAwsServices, id: \.self){ service in
NavigationLink(destination: DetailsView(service: service)){
VStack(alignment: .center, spacing: 4, content: {
AWSserviceImagePlaceHolderView(service: service, showLabel: awsServiceLogoWithLabel)
.frame(minHeight: 140)
if (!awsServiceLogoWithLabel){
Text(service.name)
.font(.subheadline)
.lineLimit(3)
}
Spacer()
})
}
}
}).padding(.horizontal, 12)
.accentColor(Color(colorScheme == .dark ? .white : .black))
}
}
.refreshable {
await awsServices.refresh()
}
.searchable(text: $searchQuery, placement: .navigationBarDrawer(displayMode: .always), prompt: "Search for an AWS Service")
.disableAutocorrection(true) // .autocorrectionDisabled() //only available on iOS 16
.navigationTitle("AWSary")
.toolbar {
Button(action: {
showingSheet.toggle()
}) {
Image(systemName: "gear")
}
}
}.sheet(isPresented: $showingSheet) {
AboutView()
}
}
}
#Preview {
Glossary()
}