Skip to content

Commit 59d3780

Browse files
committed
[#118] Tag 생성 시 색 랜덤으로 바뀌는 버그 수정
1 parent 4b29e2f commit 59d3780

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

LabDuck/Model/KPBoard.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,16 @@ struct KPBoard: Identifiable {
122122
}
123123
}
124124

125+
public mutating func createTag(_ name: String, _ color: KPTagColor) -> KPTag {
126+
if let tag = getTag(name) {
127+
return tag
128+
} else {
129+
let tag = KPTag(id: UUID(), name: name, colorTheme: color)
130+
self.allTags.append(tag)
131+
return tag
132+
}
133+
}
134+
125135
public mutating func deleteTag(_ tagID: KPTag.ID) {
126136
self.allTags.removeAll(where: { $0.id == tagID })
127137
}

LabDuck/Model/KPBoardDocument.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,21 @@ extension KPBoardDocument {
423423
}
424424
}
425425

426+
func createTag(_ name: String, color: KPTagColor, undoManager: UndoManager?, animation: Animation? = .default) {
427+
let name = name.trimmingCharacters(in: .whitespacesAndNewlines)
428+
if let tag = self.board.getTag(name) {
429+
print("Already there : \(tag)")
430+
} else {
431+
let tag = withAnimation(animation) {
432+
self.board.createTag(name, color)
433+
}
434+
435+
undoManager?.registerUndo(withTarget: self) { doc in
436+
doc.deleteTag(tagID: tag.id, undoManager: undoManager)
437+
}
438+
}
439+
}
440+
426441
// tag를 삭제할 때 사용.
427442
// 보드에 해당 tag가 없으면 무시. 아니면 지우기
428443
func deleteTag(tagID: KPTag.ID, undoManager: UndoManager?, animation: Animation? = .default) {

LabDuck/View/TagPopupView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ struct TagPopupView: View {
190190
private func createTag() {
191191
guard let previewTag = previewTag else { return }
192192

193-
document.createTag(textForTags, undoManager: undoManager)
193+
document.createTag(textForTags, color: previewTag.colorTheme, undoManager: undoManager)
194194
var tags = document.board.getTags(node.id).map { $0.id }
195195
guard let createdTag = document.board.getTag(textForTags)?.id else { return }
196196
tags.append(createdTag)

0 commit comments

Comments
 (0)