Skip to content

Commit b3b5795

Browse files
committed
๐Ÿ› :: [#33] UserList 5๋ช… ์ œํ•œ ์˜ค๋ฅ˜ ์ˆ˜์ •
1 parent 19863b8 commit b3b5795

File tree

2 files changed

+81
-73
lines changed

2 files changed

+81
-73
lines changed

โ€ŽProjects/App/Sources/Feature/PostCreateFeature/Sources/PostCreateView.swift

Lines changed: 70 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ struct PostCreateView: View {
1919
@State private var tagUserYear: [Int] = [0, 0, 0, 0, 0]
2020
@State private var tagUserId: [Int?] = Array(repeating: nil, count: 5)
2121
@State private var toast: FancyToast? = nil
22-
@State private var boolState: Bool = false
2322
@State private var buttonState: Bool = true
2423

2524
var body: some View {
@@ -346,7 +345,6 @@ struct PostCreateView: View {
346345
buttonState: isFormValid && buttonState,
347346
buttonOkColor: GPleAsset.Color.main.swiftUIColor
348347
){
349-
350348
print("ํด๋ฆญ")
351349
buttonState = false
352350
toast = FancyToast(type: .info, title: "์—…๋กœ๋“œ ์ค‘...", message: "ํ•ด๋‹น ๊ฒŒ์‹œ๋ฌผ์˜ ์—…๋กœ๋“œ๊ฐ€ ์ง„ํ–‰์ค‘์ž…๋‹ˆ๋‹ค. ์ž ์‹œ๋งŒ ๊ธฐ๋‹ค๋ ค์ฃผ์„ธ์š”.")
@@ -447,15 +445,13 @@ struct PostCreateView: View {
447445
userProfileImage: student.profileImage,
448446
userName: student.name,
449447
userYear: student.grade,
450-
userId: student.id,
451-
userProfileImageList: $tagUserImages[index],
452-
userNameList: $tagUserName[index],
453-
userYearList: $tagUserYear[index],
454-
tagUserId: $tagUserId[index]
448+
userId: student.id
455449
)
450+
.padding(.bottom, 20)
456451
}
457452
}
458453

454+
459455
Spacer()
460456
}
461457
.frame(maxWidth: .infinity, maxHeight: .infinity)
@@ -470,81 +466,84 @@ struct PostCreateView: View {
470466
.navigationBarBackButtonHidden(true)
471467
}
472468

473-
private var isFormValid: Bool {
474-
return !titleTextField.isEmpty &&
475-
images[0] != nil
476-
}
477-
}
478-
479-
@ViewBuilder
480-
func searchUserList(
481-
userProfileImage: String,
482-
userName: String,
483-
userYear: Int,
484-
userId: Int,
485-
userProfileImageList: Binding<String>,
486-
userNameList: Binding<String>,
487-
userYearList: Binding<Int>,
488-
tagUserId: Binding<Int?>
489-
) -> some View {
490-
Button {
491-
userProfileImageList.wrappedValue = userProfileImage
492-
userNameList.wrappedValue = userName
493-
userYearList.wrappedValue = userYear
494-
tagUserId.wrappedValue = userId
495-
496-
print("์ถ”๊ฐ€: \(userId)")
497-
print("์ถ”๊ฐ€: \(userName)")
498-
print("์ถ”๊ฐ€: \(userYear)ํ•™๋…„")
499-
} label: {
500-
HStack(spacing: 4) {
501-
if let url = URL(string: userProfileImage) {
502-
AsyncImage(url: url) { image in
503-
image
504-
.resizable()
505-
.scaledToFit()
506-
.frame(width: 32, height: 32)
507-
.clipShape(Circle())
508-
} placeholder: {
469+
@ViewBuilder
470+
func searchUserList(
471+
userProfileImage: String,
472+
userName: String,
473+
userYear: Int,
474+
userId: Int
475+
) -> some View {
476+
Button {
477+
if let emptyIndex = tagUserName.firstIndex(of: "") {
478+
tagUserImages[emptyIndex] = userProfileImage
479+
tagUserName[emptyIndex] = userName
480+
tagUserYear[emptyIndex] = userYear
481+
tagUserId[emptyIndex] = userId
482+
483+
print("์ถ”๊ฐ€๋œ ์œ ์ € ID: \(userId)")
484+
print("์ถ”๊ฐ€๋œ ์œ ์ € ์ด๋ฆ„: \(userName)")
485+
print("์ถ”๊ฐ€๋œ ์œ ์ € ํ•™๋…„: \(userYear)")
486+
} else {
487+
tagUserImages[4] = userProfileImage
488+
tagUserName[4] = userName
489+
tagUserYear[4] = userYear
490+
tagUserId[4] = userId
491+
}
492+
} label: {
493+
HStack(spacing: 4) {
494+
if let url = URL(string: userProfileImage) {
495+
AsyncImage(url: url) { image in
496+
image
497+
.resizable()
498+
.scaledToFit()
499+
.frame(width: 32, height: 32)
500+
.clipShape(Circle())
501+
} placeholder: {
502+
GPleAsset.Assets.profile.swiftUIImage
503+
.resizable()
504+
.scaledToFit()
505+
.frame(width: 32, height: 32)
506+
}
507+
.padding(.leading, 24)
508+
} else {
509509
GPleAsset.Assets.profile.swiftUIImage
510510
.resizable()
511511
.scaledToFit()
512512
.frame(width: 32, height: 32)
513+
.padding(.leading, 24)
513514
}
514-
.padding(.leading, 24)
515-
} else {
516-
GPleAsset.Assets.profile.swiftUIImage
517-
.resizable()
518-
.scaledToFit()
519-
.frame(width: 32, height: 32)
520-
.padding(.leading, 24)
521-
}
522515

523-
Text(userName)
524-
.font(GPleFontFamily.Pretendard.semiBold.swiftUIFont(size: 16))
525-
.foregroundStyle(.white)
526-
.padding(.leading, 4)
516+
Text(userName)
517+
.font(GPleFontFamily.Pretendard.semiBold.swiftUIFont(size: 16))
518+
.foregroundStyle(.white)
519+
.padding(.leading, 4)
527520

528-
Text("ยท \(userYear)ํ•™๋…„")
529-
.font(GPleFontFamily.Pretendard.regular.swiftUIFont(size: 14))
530-
.foregroundStyle(GPleAsset.Color.gray800.swiftUIColor)
521+
Text("ยท \(userYear)ํ•™๋…„")
522+
.font(GPleFontFamily.Pretendard.regular.swiftUIFont(size: 14))
523+
.foregroundStyle(GPleAsset.Color.gray800.swiftUIColor)
531524

532-
Spacer()
525+
Spacer()
533526

534-
HStack(spacing: 8) {
535-
GPleAsset.Assets.grayUserPlus.swiftUIImage
527+
HStack(spacing: 8) {
528+
GPleAsset.Assets.grayUserPlus.swiftUIImage
536529

537-
Text("์ถ”๊ฐ€ํ•˜๊ธฐ")
538-
.font(GPleFontFamily.Pretendard.regular.swiftUIFont(size: 14))
539-
.foregroundStyle(GPleAsset.Color.gray400.swiftUIColor)
530+
Text("์ถ”๊ฐ€ํ•˜๊ธฐ")
531+
.font(GPleFontFamily.Pretendard.regular.swiftUIFont(size: 14))
532+
.foregroundStyle(GPleAsset.Color.gray400.swiftUIColor)
533+
}
534+
.padding(.horizontal, 12)
535+
.padding(.vertical, 8)
536+
.background(
537+
RoundedRectangle(cornerRadius: 8)
538+
.foregroundStyle(GPleAsset.Color.gray1000.swiftUIColor)
539+
)
540+
.padding(.trailing, 20)
540541
}
541-
.padding(.horizontal, 12)
542-
.padding(.vertical, 8)
543-
.background(
544-
RoundedRectangle(cornerRadius: 8)
545-
.foregroundStyle(GPleAsset.Color.gray1000.swiftUIColor)
546-
)
547-
.padding(.trailing, 20)
548542
}
549543
}
544+
545+
private var isFormValid: Bool {
546+
return !titleTextField.isEmpty &&
547+
images[0] != nil
548+
}
550549
}

โ€ŽProjects/App/Sources/Feature/PostCreateFeature/Sources/PostViewModel.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,20 +163,29 @@ public final class PostViewModel: ObservableObject {
163163
switch result {
164164
case let .success(response):
165165
do {
166-
print("์„ฑ๊ณตใ…ฃ์œ ์ € ๋ฆฌ์ŠคํŠธ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ")
166+
// ์‘๋‹ต ๋ฐ์ดํ„ฐ๋ฅผ String์œผ๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ์ถœ๋ ฅ
167+
if let responseString = String(data: response.data, encoding: .utf8) {
168+
print("Response Data as String: \(responseString)")
169+
}
170+
171+
// JSON ๋””์ฝ”๋”ฉ
172+
print("์„ฑ๊ณต: ์œ ์ € ๋ฆฌ์ŠคํŠธ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ")
167173
self.allUserList = try JSONDecoder().decode([UserListResponse].self, from: response.data)
168174
completion(true)
169175
} catch {
170-
print("Failed to decode JSON response")
176+
// ๋””์ฝ”๋”ฉ ์‹คํŒจ ์‹œ ์—๋Ÿฌ ์ถœ๋ ฅ
177+
print("Failed to decode JSON response: \(error)")
171178
completion(false)
172179
}
173180
case let .failure(err):
181+
// ๋„คํŠธ์›Œํฌ ์š”์ฒญ ์‹คํŒจ ์‹œ ์—๋Ÿฌ ์ถœ๋ ฅ
174182
print("Network request failed: \(err)")
175183
completion(false)
176184
}
177185
}
178186
}
179187

188+
180189
public func popularityUserList(completion: @escaping (Bool) -> Void) {
181190
authProvider.request(.popularityUserList(authorization: accessToken)) { result in
182191
switch result {

0 commit comments

Comments
ย (0)