Impressia/Vernissage/Views/SearchView.swift

65 lines
2.6 KiB
Swift
Raw Normal View History

2023-03-06 16:00:53 +01:00
//
// https://mczachurski.dev
// Copyright © 2023 Marcin Czachurski and the repository contributors.
2023-03-28 10:35:38 +02:00
// Licensed under the Apache License 2.0.
2023-03-06 16:00:53 +01:00
//
import SwiftUI
struct SearchView: View {
2023-03-07 16:45:44 +01:00
@EnvironmentObject var routerPath: RouterPath
2023-03-06 16:00:53 +01:00
@State private var query = String.empty()
@FocusState private var focusedField: FocusField?
enum FocusField: Hashable {
case unknown
case search
}
var body: some View {
List {
Section {
2023-03-13 13:53:36 +01:00
TextField("search.title.placeholder", text: $query)
2023-03-08 12:07:43 +01:00
.padding(8)
.focused($focusedField, equals: .search)
.keyboardType(.default)
.autocapitalization(.none)
.autocorrectionDisabled()
.clearButton(text: $query)
.onAppear() {
self.focusedField = .search
2023-03-06 16:00:53 +01:00
}
2023-03-08 12:07:43 +01:00
.buttonStyle(PlainButtonStyle())
2023-03-06 16:00:53 +01:00
}
if self.query.isEmpty == false {
Section {
2023-03-08 12:07:43 +01:00
NavigationLink(value: RouteurDestinations.accountsPhoto(listType: .search(query: self.query))) {
2023-03-13 13:53:36 +01:00
Label(String(format: NSLocalizedString("search.title.usersWith", comment: "Users with "), self.query),
systemImage: "person.3.sequence")
2023-03-06 16:00:53 +01:00
}
2023-03-07 16:45:44 +01:00
NavigationLink(value: RouteurDestinations.userProfile(accountId: "", accountDisplayName: "", accountUserName: self.query)) {
2023-03-13 13:53:36 +01:00
Label(String(format: NSLocalizedString("search.title.goToUser", comment: "Go to user "), "\"@\(self.query)\""),
systemImage: "person.crop.circle")
2023-03-06 16:00:53 +01:00
}
}
Section {
2023-03-07 16:45:44 +01:00
NavigationLink(value: RouteurDestinations.hashtags(listType: .search(query: self.query))) {
2023-03-13 13:53:36 +01:00
Label(String(format: NSLocalizedString("search.title.hashtagWith", comment: "Hashtags with "), self.query),
systemImage: "tag")
2023-03-06 16:00:53 +01:00
}
2023-03-07 16:45:44 +01:00
NavigationLink(value: RouteurDestinations.statuses(listType: .hashtag(tag: self.query))) {
2023-03-13 13:53:36 +01:00
Label(String(format: NSLocalizedString("search.title.goToHashtag", comment: "Go to hashtag "), "\"#\(self.query)\""),
systemImage: "tag.circle")
2023-03-06 16:00:53 +01:00
}
}
}
2023-03-06 16:29:37 +01:00
}
2023-03-13 13:53:36 +01:00
.navigationTitle("search.navigationBar.title")
2023-03-06 16:00:53 +01:00
}
}