Skip to content

Commit

Permalink
Always show create tag button when not exactly matching an existing tag
Browse files Browse the repository at this point in the history
  • Loading branch information
acez committed Apr 17, 2023
1 parent 65fa490 commit 1ddc959
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
8 changes: 4 additions & 4 deletions BookmarkCompanion.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,7 @@
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
CODE_SIGN_ENTITLEMENTS = ShareExtension/ShareExtension.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = "$(inherited)";
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = ShareExtension/Info.plist;
Expand Down Expand Up @@ -1216,7 +1216,7 @@
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
CODE_SIGN_ENTITLEMENTS = ShareExtension/ShareExtension.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = "$(inherited)";
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = ShareExtension/Info.plist;
Expand Down Expand Up @@ -1363,7 +1363,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = BookmarkCompanion/BookmarkCompanion.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_ASSET_PATHS = "\"BookmarkCompanion/Preview Content\"";
DEVELOPMENT_TEAM = "$(inherited)";
ENABLE_PREVIEWS = YES;
Expand Down Expand Up @@ -1399,7 +1399,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = BookmarkCompanion/BookmarkCompanion.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_ASSET_PATHS = "\"BookmarkCompanion/Preview Content\"";
DEVELOPMENT_TEAM = "$(inherited)";
ENABLE_PREVIEWS = YES;
Expand Down
34 changes: 18 additions & 16 deletions Shared/components/list/CommonSelectListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,11 @@ public struct CommonSelectListView<T: CommonListItem>: View {

public var body: some View {
List {
if self.filteredItems().isEmpty {
if self.searchTerm == "" || self.createNotFoundHandler == nil {
Text("No items")
} else {
Button(action: {
self.createNotFoundHandler?.createItem(text: self.searchTerm)
}) {
HStack {
Image(systemName: "square.and.pencil")
.foregroundColor(.blue)
Text("Create \(self.searchTerm)")
.foregroundColor(.blue)
}
}
.buttonStyle(.plain)
let exactSearchMatch = !self.filteredItems().map({ $0.getDisplayText().lowercased() }).contains(self.searchTerm.lowercased())
let showCreateButton = (exactSearchMatch && self.searchTerm != "") && self.createNotFoundHandler != nil

}
if self.filteredItems().isEmpty && !showCreateButton {
Text("No items")
} else {
ForEach(self.filteredItems()) { item in
SelectableListItemView(text: item.getDisplayText(), selected: self.selectedItems.wrappedValue.contains(item), tapHandler: {
Expand All @@ -60,6 +48,20 @@ public struct CommonSelectListView<T: CommonListItem>: View {
})
}
}

if showCreateButton {
Button(action: {
self.createNotFoundHandler?.createItem(text: self.searchTerm)
}) {
HStack {
Image(systemName: "square.and.pencil")
.foregroundColor(.blue)
Text("Create \(self.searchTerm)")
.foregroundColor(.blue)
}
}
.buttonStyle(.plain)
}
}
.searchable(text: self.$searchTerm)
}
Expand Down

0 comments on commit 1ddc959

Please sign in to comment.