Skip to content

Commit

Permalink
Close #66. Delete tags from list
Browse files Browse the repository at this point in the history
  • Loading branch information
kaphacius committed Sep 15, 2024
1 parent 5a2f49a commit 808e666
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 22 deletions.
2 changes: 1 addition & 1 deletion JustTags/List/TagListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
4 changes: 4 additions & 0 deletions JustTags/Main/MainVM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,8 @@ internal final class MainVM: AnyWindowVM, Identifiable {
)
}

internal func removeTag(with id: EMVTag.ID) {
self.initialTags.removeAll(where: { $0.id == id })
}

}
2 changes: 1 addition & 1 deletion JustTags/Main/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
Expand Down
18 changes: 13 additions & 5 deletions JustTags/TagRowView/TagRowView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
}

Expand Down Expand Up @@ -115,17 +118,22 @@ internal struct TagRowView: View {
action: windowVM.diffSelectedTags
)
}
if vm.isSubTag == false {
Button("Remove tag") {
windowVM.removeTag(with: vm.id)
}
}
}

}

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())
}
Expand Down
6 changes: 1 addition & 5 deletions JustTags/Utils/EMVTag/EMVTagExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 0 additions & 10 deletions JustTags/Utils/UI/PreviewHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 808e666

Please sign in to comment.