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

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

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