summaryrefslogtreecommitdiff
path: root/Sora/Views/SearchSuggestionsView.swift
blob: cae8d436a6bb66d65e5bf3b78b433af2193d3068 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import SwiftUI

struct SearchSuggestionsView: View {
    var tags: [MoebooruTag]
    @Binding var searchText: String
    var lastSearchTag: String {
        String(searchText.split(separator: " ").last ?? "")
    }

    var body: some View {
        ForEach(
            tags.filter { $0.name.lowercased().contains(lastSearchTag)
            }) { suggestion in
                Button {
                    searchText.replaceSubrange(searchText.range(of: lastSearchTag)!, with: suggestion.name)
                } label: {
                    Text(suggestion.name)
                }
            }
    }
}