Skip to content

Commit 05289df

Browse files
committed
feat: 최대 20자 제한
1 parent 02d13d8 commit 05289df

3 files changed

Lines changed: 43 additions & 21 deletions

File tree

DevLog/Presentation/ViewModel/TodoManageViewModel.swift

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ final class TodoManageViewModel: Store {
5656
isEditing ? "저장" : "추가"
5757
}
5858

59+
var placerholder: String {
60+
state.category?.name ?? "이름"
61+
}
62+
63+
var categoryNameCountText: String {
64+
"\((state.category?.name ?? "").count)/\(20)"
65+
}
66+
5967
var canSubmitUserCategory: Bool {
6068
let trimmedCategoryName = state.category?.name.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
6169
if trimmedCategoryName.isEmpty {
@@ -129,19 +137,22 @@ final class TodoManageViewModel: Store {
129137
state.category = nil
130138
}
131139
case .setCategoryName(let name):
132-
state.category?.name = name
140+
guard var category = state.category else { break }
141+
category.name = String(name.prefix(20))
142+
state.category = category
133143
case .setCategoryColor(let color):
134-
state.category?.colorHex = color.hexString ?? "#0A84FF"
144+
guard var category = state.category else { break }
145+
146+
category.colorHex = color.hexString ?? "#0A84FF"
147+
state.category = category
135148
case .saveUserCategory:
136-
guard let userTodoCategory = state.category else {
137-
break
138-
}
149+
guard let category = state.category else { break }
139150

140-
let trimmedCategoryName = userTodoCategory.name.trimmingCharacters(in: .whitespacesAndNewlines)
151+
let name = category.name.trimmingCharacters(in: .whitespacesAndNewlines)
141152
let updatedCategory = UserTodoCategory(
142-
id: userTodoCategory.id,
143-
name: trimmedCategoryName,
144-
colorHex: userTodoCategory.colorHex
153+
id: category.id,
154+
name: name,
155+
colorHex: category.colorHex
145156
)
146157

147158
if let index = state.preferences.firstIndex(where: {

DevLog/Resource/Localizable.xcstrings

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,6 @@
456456
},
457457
"카테고리 삭제" : {
458458

459-
},
460-
"카테고리명" : {
461-
462459
},
463460
"컨텐츠" : {
464461

DevLog/UI/Home/TodoManageView.swift

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import SwiftUI
99

1010
struct TodoManageView: View {
1111
@State var viewModel: TodoManageViewModel
12+
@State private var tmpText: String = ""
1213
var onDismiss: (([TodoCategoryPreference]) -> Void)?
1314

1415
var body: some View {
@@ -23,6 +24,7 @@ struct TodoManageView: View {
2324
viewModel.send(.tapItem(category))
2425
}
2526
Text(category.localizedName)
27+
.lineLimit(1)
2628
Spacer()
2729
if case .user = category {
2830
Button {
@@ -102,22 +104,34 @@ struct TodoManageView: View {
102104
NavigationStack {
103105
Form {
104106
Section {
105-
TextField(
106-
"카테고리명",
107-
text: Binding(
108-
get: { viewModel.state.category?.name ?? "" },
109-
set: { viewModel.send(.setCategoryName($0)) }
107+
HStack(spacing: 8) {
108+
TextField(
109+
"",
110+
text: $tmpText,
111+
prompt: Text(viewModel.placerholder).foregroundStyle(.secondary)
110112
)
111-
)
112-
.frame(height: UIFont.preferredFont(forTextStyle: .body).lineHeight)
113+
.frame(height: UIFont.preferredFont(forTextStyle: .body).lineHeight)
114+
.onAppear {
115+
tmpText = viewModel.state.category?.name ?? ""
116+
}
117+
.onChange(of: tmpText) { _, value in
118+
viewModel.send(.setCategoryName(value))
119+
tmpText = viewModel.state.category?.name ?? ""
120+
}
121+
122+
Text(viewModel.categoryNameCountText)
123+
.font(.footnote)
124+
.foregroundStyle(.secondary)
125+
.monospacedDigit()
126+
}
113127
}
114128

115129
Section {
130+
let color = Color(hexString: viewModel.state.category?.colorHex ?? "#0A84FF") ?? .blue
116131
ColorPicker(selection: Binding(
117-
get: { Color(hexString: viewModel.state.category?.colorHex ?? "#0A84FF") ?? .blue },
132+
get: { color },
118133
set: { viewModel.send(.setCategoryColor($0)) }
119134
), supportsOpacity: false) {
120-
let color = Color(hexString: viewModel.state.category?.colorHex ?? "#0A84FF") ?? .blue
121135
Text(viewModel.state.category?.colorHex ?? "#")
122136
.foregroundStyle(color)
123137
}

0 commit comments

Comments
 (0)