diff --git a/JustTags/List/TagListView.swift b/JustTags/List/TagListView.swift index f1d9d62..f8b5357 100644 --- a/JustTags/List/TagListView.swift +++ b/JustTags/List/TagListView.swift @@ -40,7 +40,7 @@ struct EMVTagListView_Previews: PreviewProvider { static var previews: some View { TagListView( tags: [.mockTag, .mockTagExtended, .mockTagConstructed] - .map(TagRowVM.make(with:)), + .map { .init(tag: $0, isSubtag: false) }, searchInProgress: .constant(true) ).environmentObject(MainVM()) } diff --git a/JustTags/Main/MainVM.swift b/JustTags/Main/MainVM.swift index b62d207..f8ee9c6 100644 --- a/JustTags/Main/MainVM.swift +++ b/JustTags/Main/MainVM.swift @@ -224,4 +224,8 @@ internal final class MainVM: AnyWindowVM, Identifiable { ) } + internal func removeTag(with id: EMVTag.ID) { + self.initialTags.removeAll(where: { $0.id == id }) + } + } diff --git a/JustTags/Main/MainView.swift b/JustTags/Main/MainView.swift index 84254cd..bf04f15 100644 --- a/JustTags/Main/MainView.swift +++ b/JustTags/Main/MainView.swift @@ -78,7 +78,7 @@ struct MainView: View { if vm.showsTags { ScrollView { TagListView( - tags: vm.currentTags.map(TagRowVM.init), + tags: vm.currentTags.map { .init(tag: $0, isSubtag: false) }, searchInProgress: $searchInProgress ) } diff --git a/JustTags/TagRowView/TagRowView.swift b/JustTags/TagRowView/TagRowView.swift index 0fcaa05..0b21dfb 100644 --- a/JustTags/TagRowView/TagRowView.swift +++ b/JustTags/TagRowView/TagRowView.swift @@ -14,6 +14,7 @@ internal struct TagRowVM: Equatable, Identifiable { internal let category: Category internal let fullHexString: String internal let valueHexString: String + internal let isSubTag: Bool internal enum Category { case plain(PlainTagVM) @@ -39,12 +40,14 @@ internal struct TagRowVM: Equatable, Identifiable { } init( - tag: EMVTag + tag: EMVTag, + isSubtag: Bool ) { self.id = tag.id self.category = .category(with: tag) self.fullHexString = tag.fullHexString self.valueHexString = tag.valueHexString + self.isSubTag = isSubtag } } @@ -115,6 +118,11 @@ internal struct TagRowView: View { action: windowVM.diffSelectedTags ) } + if vm.isSubTag == false { + Button("Remove tag") { + windowVM.removeTag(with: vm.id) + } + } } } @@ -122,10 +130,10 @@ internal struct TagRowView: View { struct TagRowView_Previews: PreviewProvider { static var previews: some View { VStack { - TagRowView(vm: .make(with: .mockTag)) - TagRowView(vm: .make(with: .mockTagExtended)) - TagRowView(vm: .make(with: .mockTagConstructed)) - TagRowView(vm: .make(with: .mockTagMultipleKernels)) + TagRowView(vm: .init(tag: .mockTag, isSubtag: false)) + TagRowView(vm: .init(tag: .mockTagExtended, isSubtag: false)) + TagRowView(vm: .init(tag: .mockTagConstructed, isSubtag: false)) + TagRowView(vm: .init(tag: .mockTagMultipleKernels, isSubtag: false)) } .environmentObject(MainVM()) } diff --git a/JustTags/Utils/EMVTag/EMVTagExtensions.swift b/JustTags/Utils/EMVTag/EMVTagExtensions.swift index e311e66..5518f47 100644 --- a/JustTags/Utils/EMVTag/EMVTagExtensions.swift +++ b/JustTags/Utils/EMVTag/EMVTagExtensions.swift @@ -120,15 +120,11 @@ extension EMVTag { name: name, headerVM: tagHeaderVM, valueVM: tagValueVM, - subtags: subtags.map(\.tagRowVM), + subtags: subtags.map { TagRowVM(tag: $0, isSubtag: true) }, showsDetails: isUnknown == false ) } - var tagRowVM: TagRowVM { - .init(tag: self) - } - var tagInfoVMs: [TagInfoVM] { switch self.decodingResult { case .unknown: diff --git a/JustTags/Utils/UI/PreviewHelpers.swift b/JustTags/Utils/UI/PreviewHelpers.swift index 0088655..c28d822 100644 --- a/JustTags/Utils/UI/PreviewHelpers.swift +++ b/JustTags/Utils/UI/PreviewHelpers.swift @@ -98,16 +98,6 @@ extension ConstructedTagVM { } -extension TagRowVM { - - static func make( - with tag: EMVTag - ) -> TagRowVM { - .init(tag: tag) - } - -} - extension KernelSelectionRowVM { static var mockShortVM: KernelSelectionRowVM = .init(