Expands fields searched in the monster search.
This commit is contained in:
@@ -37,4 +37,12 @@ class StringHelper {
|
||||
return joined
|
||||
}
|
||||
}
|
||||
|
||||
static func safeContainsCaseInsensitive(_ str: String?, _ match: String) -> Bool {
|
||||
if (str == nil) {
|
||||
return false
|
||||
}
|
||||
|
||||
return str!.containsCaseInsensitive(match)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,41 @@ struct Search: View {
|
||||
SearchBar(text: $searchText)
|
||||
.padding(.top, -30)
|
||||
|
||||
ForEach(allMonsters.filter({searchText.isEmpty ? true : $0.name?.containsCaseInsensitive(searchText) ?? false })) { monster in
|
||||
ForEach(
|
||||
allMonsters.filter(
|
||||
{
|
||||
// TODO: consider splitting search text into words and if each word appears in any of these fields return true e.g, "large demon" would match large in size and demon in type.
|
||||
// TODO: add tags and search by tags
|
||||
// TODO: add a display of what fields matched on each item in the results
|
||||
// TODO: make the criteria configurable from this screen
|
||||
// TODO: find a way to add challenge rating as a search criteria
|
||||
|
||||
if (searchText.isEmpty) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (StringHelper.safeContainsCaseInsensitive($0.name, searchText)) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (StringHelper.safeContainsCaseInsensitive($0.size, searchText)) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (StringHelper.safeContainsCaseInsensitive($0.type, searchText)) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (StringHelper.safeContainsCaseInsensitive($0.subtype, searchText)) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (StringHelper.safeContainsCaseInsensitive($0.alignment, searchText)) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
})) { monster in
|
||||
NavigationLink(destination: MonsterDetail(monster: monster)) {
|
||||
Text(monster.name ?? "")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user