Skip to content

Commit

Permalink
Fix: 유저 가져오는 부분이 이상해서 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
ksiomng committed Oct 24, 2024
1 parent d558658 commit ac18995
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions Kabinett/Presentation/View/WriteLetter/UserSelectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ struct UserSelectionView: View {
.lineSpacing(3)
.foregroundStyle(Color("ContentSecondary"))
.bold()
.onAppear {
letterContent.toUserName = ""
letterContent.fromUserName = ""
}
HStack {
Spacer()
Button("로그인하기") {
Expand Down Expand Up @@ -94,8 +90,6 @@ struct FormToUser: View {
@ObservedObject var viewModel : UserSelectionViewModel

var body: some View {
let fromName = letterContent.fromUserName.isEmpty ? viewModel.fromUser?.name ?? "" : letterContent.fromUserName

HStack {
Text("보내는 사람")
.foregroundStyle(Color("ContentPrimary"))
Expand All @@ -111,31 +105,27 @@ struct FormToUser: View {
}
.padding(.top, 15)
.onChange(of: viewModel.fromUser?.kabinettNumber) {
letterContent.toUserId = viewModel.toUser?.id
letterContent.toUserName = viewModel.checkLogin ? viewModel.toUser?.name ?? "" : ""
letterContent.toUserKabinettNumber = viewModel.toUser?.kabinettNumber
if viewModel.checkLogin {
letterContent.fromUserId = viewModel.fromUser?.id
letterContent.fromUserName = viewModel.fromUser?.name ?? ""
letterContent.fromUserKabinettNumber = viewModel.fromUser?.kabinettNumber
letterContent.toUserId = viewModel.toUser?.id
letterContent.toUserName = viewModel.toUser?.name ?? ""
letterContent.toUserKabinettNumber = viewModel.toUser?.kabinettNumber
} else {
letterContent.toUserName = ""
letterContent.fromUserName = ""
}
letterContent.date = Date()
}

HStack {
Text("받는 사람")
.foregroundStyle(Color("ContentPrimary"))
.font(.system(size: 16))
.bold()
.onAppear {
letterContent.fromUserId = viewModel.fromUser?.id
letterContent.fromUserName = viewModel.fromUser?.name ?? ""
letterContent.fromUserKabinettNumber = viewModel.fromUser?.kabinettNumber
if letterContent.toUserId == "" {
viewModel.updateToUser(&letterContent, toUserName: letterContent.fromUserName)
}
letterContent.toUserId = viewModel.toUser?.id
letterContent.toUserName = viewModel.toUser?.name ?? ""
letterContent.toUserKabinettNumber = viewModel.toUser?.kabinettNumber

letterContent.date = Date()
}
Spacer(minLength: 37)
let toName = letterContent.toUserName.isEmpty ? fromName : letterContent.toUserName
let toName = letterContent.toUserName.isEmpty ? viewModel.toUser?.name ?? "" : letterContent.toUserName
let toKabi = letterContent.toUserName.isEmpty ? viewModel.fromUser?.kabinettNumber ?? 0 : letterContent.toUserKabinettNumber
Text(viewModel.checkLogin ? "\(toName) \(viewModel.checkMe(kabiNumber: toKabi ?? 0))" : "")
.foregroundStyle(viewModel.checkLogin ? Color.black : Color("ContentSecondary"))
Expand Down

0 comments on commit ac18995

Please sign in to comment.