Skip to content

Commit

Permalink
Merge pull request #60 from DDD-Community/bug/postupload
Browse files Browse the repository at this point in the history
bug: 공고 등록/수정 관련 버그 수정
  • Loading branch information
Hansangjin98 authored Feb 6, 2025
2 parents 0be6a48 + e3015b8 commit 0dbc298
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public final class RecruitJobGroupView: UIView {
// MARK: - Properties
private let rootContainer: UIView = .init()
private let titleLabel: MozipLabel = .init(style: .heading3, color: MozipColor.gray800, text: "모집 대상")
private let requiredLabel: MozipLabel = .init(style: .heading3, color: MozipColor.primary500, text: " *")

private enum StackViewConstants {
static let rowHeight: Int = 56
Expand Down Expand Up @@ -50,14 +51,7 @@ public final class RecruitJobGroupView: UIView {
return button
}()

private let jobGroupRelay: BehaviorRelay<[BehaviorSubject<String>]> = .init(value: [])

public var allValueObservable: Observable<[String]> {
jobGroupRelay
.flatMapLatest {
Observable.combineLatest($0)
}
}
public let jobGroupRelay: BehaviorRelay<[String]> = .init(value: [])

public let updatedStackViewSubject: PublishSubject<Void> = .init()
private let disposeBag: DisposeBag = .init()
Expand Down Expand Up @@ -86,17 +80,26 @@ public final class RecruitJobGroupView: UIView {
// MARK: - Methods
public func setEditMode() {
jobGroupStackView.arrangedSubviews.first?.removeFromSuperview()
jobGroupRelay.accept([])
jobGroupRelay.accept(Array(jobGroupRelay.value.dropFirst()))
}

public func makeField(value: String = "") {
jobGroupRelay.accept(jobGroupRelay.value + [value])

let textField: MozipTextField = .init(placeHolder: "모집 대상을 입력해주세요. (공백 포함 최대 25자)")
textField.tag = jobGroupRelay.value.count - 1
jobGroupStackView.addArrangedSubview(textField)

textField.rx.text.orEmpty
.skip(1)
.filter { [weak self] in self?.checkTextCount(textField, text: $0) ?? false }
.compactMap { [weak self] text in self?.updateJobGroupArray(tag: textField.tag, text: text) }
.bind(to: jobGroupRelay)
.disposed(by: disposeBag)

if !value.isEmpty {
textField.rx.text.onNext(value)
}
jobGroupStackView.addArrangedSubview(textField)
jobGroupRelay.accept(jobGroupRelay.value + [BehaviorSubject(value: value)])
}
}

Expand All @@ -107,7 +110,12 @@ private extension RecruitJobGroupView {

rootContainer.flex
.define {
$0.addItem(titleLabel)
$0.addItem()
.direction(.row)
.define {
$0.addItem(titleLabel)
$0.addItem(requiredLabel)
}
$0.addItem(jobGroupStackView).marginTop(12).height(56)

$0.addItem()
Expand Down Expand Up @@ -148,14 +156,10 @@ private extension RecruitJobGroupView {
}

func removeLastArrangedSubview() {
guard let lastView = jobGroupStackView.arrangedSubviews.last else {
return
}
guard let lastView = jobGroupStackView.arrangedSubviews.last else { return }
jobGroupStackView.removeArrangedSubview(lastView)
lastView.removeFromSuperview()
var currentSubjects = jobGroupRelay.value
currentSubjects.removeLast()
jobGroupRelay.accept(currentSubjects)
jobGroupRelay.accept(jobGroupRelay.value.dropLast())
}

func updatejobGroupStackViewHeight() {
Expand All @@ -164,4 +168,19 @@ private extension RecruitJobGroupView {
rootContainer.flex.layout()
updatedStackViewSubject.onNext(())
}

func checkTextCount(_ textField: UITextField, text: String) -> Bool {
guard text.count > 25 else { return true }

textField.text = text.dropLast().map { String($0) }.joined()
return false
}

func updateJobGroupArray(tag: Int, text: String) -> [String] {
var jobGroupArray = jobGroupRelay.value
guard tag < jobGroupArray.count else { return jobGroupArray }

jobGroupArray[tag] = text
return jobGroupArray
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ private extension PostUploadViewController {
.bind(to: reactor.action)
.disposed(by: disposeBag)

recruitJobView.allValueObservable
recruitJobView.jobGroupRelay
.skip(1)
.map { Action.inputJobGroup($0) }
.bind(to: reactor.action)
Expand Down

0 comments on commit 0dbc298

Please sign in to comment.