Skip to content

Commit

Permalink
Merge pull request #283 from depromeet/feat/#282-feat-회원가입-프로세스-가족초대-…
Browse files Browse the repository at this point in the history
…가족-가입-화면-추가

feat:  가족생성 및 초대화면 추가에 따른 기존 로직 수정 및 추가 개발
  • Loading branch information
YuGeonHui authored Jan 16, 2024
2 parents 627e7d3 + b811eef commit 5fcd910
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 34 deletions.
1 change: 1 addition & 0 deletions 14th-team5-iOS/App/Sources/Application/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
return
}

// UserDefaults.standard.inviteUrl = String("\(incomingURL)")
guard let path = components.path else {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,11 @@ extension AccountSignInViewController {
let container = UINavigationController(rootViewController: AccountSignUpDIContainer().makeViewController())
container.modalPresentationStyle = .fullScreen
present(container, animated: false)
} else {
let container = UINavigationController(rootViewController: HomeDIContainer().makeViewController())
container.modalPresentationStyle = .fullScreen
present(container, animated: false)
return
}

let container = UINavigationController(rootViewController: OnBoardingDIContainer().makeViewController())
container.modalPresentationStyle = .fullScreen
present(container, animated: false)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ final class InputFamilyLinkViewController: BaseViewController<InputFamilyLinkRea
}

linkTextField.do {
$0.makePlaceholderAttributedString("https://no5ing.kr/", attributed: [
$0.makePlaceholderAttributedString(UserDefaults.standard.inviteUrl ?? "https://no5ing.kr/",
attributed: [
.font: UIFont(font: DesignSystemFontFamily.Pretendard.bold, size: 36)!,
.foregroundColor: DesignSystemAsset.gray700.color
])
Expand Down Expand Up @@ -123,9 +124,7 @@ final class InputFamilyLinkViewController: BaseViewController<InputFamilyLinkRea
.filter { $0 }
.distinctUntilChanged()
.withUnretained(self)
.bind(onNext: {
$0.0.showHomeViewController()
})
.bind(onNext: { $0.0.showHomeViewController() })
.disposed(by: disposeBag)

reactor.state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ final class JoinFamilyViewController: BaseViewController<JoinFamilyReactor> {
super.setupAttributes()

titleLabel.do {
$0.text = "엄마님, 가족 중 첫 번째로\n방을 생성해보세요"
$0.text = "\(UserDefaults.standard.nickname ?? "삐삐"), 가족 중 첫 번째로\n방을 생성해보세요"
$0.numberOfLines = 2
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,13 @@ final public class OnBoardingViewController: BaseViewController<OnBoardingReacto
guard show else { return }
guard let sceneDelegate = UIApplication.shared.connectedScenes.first?.delegate as? SceneDelegate else { return }

sceneDelegate.window?.rootViewController = UINavigationController(rootViewController: JoinFamilyDIContainer().makeViewController())
sceneDelegate.window?.makeKeyAndVisible()
if App.Repository.member.familyId.value == nil {
sceneDelegate.window?.rootViewController = UINavigationController(rootViewController: JoinFamilyDIContainer().makeViewController())
sceneDelegate.window?.makeKeyAndVisible()
} else {
sceneDelegate.window?.rootViewController = UINavigationController(rootViewController: HomeDIContainer().makeViewController())
sceneDelegate.window?.makeKeyAndVisible()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public final class SplashViewController: BaseViewController<SplashViewReactor> {
guard let sceneDelegate = UIApplication.shared.connectedScenes.first?.delegate as? SceneDelegate else { return }
let container: UINavigationController

if let _ = member?.memberId {
if let _ = member?.familyId {
var container: UINavigationController
if UserDefaults.standard.finishTutorial {
container = UINavigationController(rootViewController: HomeDIContainer().makeViewController())
Expand All @@ -126,11 +126,7 @@ public final class SplashViewController: BaseViewController<SplashViewReactor> {
sceneDelegate.window?.makeKeyAndVisible()
return
} else {
if UserDefaults.standard.finishTutorial {
container = UINavigationController(rootViewController: HomeDIContainer().makeViewController())
} else {
container = UINavigationController(rootViewController: OnBoardingDIContainer().makeViewController())
}
container = UINavigationController(rootViewController: OnBoardingDIContainer().makeViewController())
}

sceneDelegate.window?.rootViewController = container
Expand Down
13 changes: 13 additions & 0 deletions 14th-team5-iOS/Core/Sources/Extensions/UserDefaults+Ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ extension UserDefaults {

case familyId
case memberId
case nickname

case inviteUrl
case inviteCode

case profileImage
Expand Down Expand Up @@ -48,11 +51,21 @@ extension UserDefaults {
set { UserDefaults.standard.set(newValue, forKey: Key.memberId.value) }
}

public var nickname: String? {
get { UserDefaults.standard.string(forKey: Key.nickname.value) }
set { UserDefaults.standard.set(newValue, forKey: Key.nickname.value) }
}

public var inviteCode: String? {
get { UserDefaults.standard.string(forKey: Key.inviteCode.value) }
set { UserDefaults.standard.set(newValue, forKey: Key.inviteCode.value) }
}

public var inviteUrl: String? {
get { UserDefaults.standard.string(forKey: Key.inviteUrl.value) }
set { UserDefaults.standard.set(newValue, forKey: Key.inviteUrl.value) }
}

public var profileImage: Data? {
get { UserDefaults.standard.data(forKey: Key.profileImage.value) }
set { UserDefaults.standard.setValue(newValue, forKey: Key.profileImage.value)}
Expand Down
11 changes: 11 additions & 0 deletions 14th-team5-iOS/Core/Sources/Member/MemberRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import RxCocoa
public class MemberRepository: RxObject {
public let familyId = BehaviorRelay<String?>(value: nil)
public let memberID = BehaviorRelay<String?>(value: nil)
public let nickname = BehaviorRelay<String?>(value: nil)
public let inviteCode = BehaviorRelay<String?>(value: nil)

override public func bind() {
Expand All @@ -25,6 +26,11 @@ public class MemberRepository: RxObject {
.withUnretained(self)
.bind(onNext: { $0.0.saveFamilyId(with: $0.1) })
.disposed(by: disposeBag)

nickname
.withUnretained(self)
.bind(onNext: { $0.0.saveNicknmae(with: $0.1) })
.disposed(by: disposeBag)

inviteCode
.withUnretained(self)
Expand All @@ -47,6 +53,11 @@ public class MemberRepository: RxObject {
UserDefaults.standard.inviteCode = code
}

private func saveNicknmae(with nickname: String?) {
guard let nickname = nickname else { return }
UserDefaults.standard.nickname = nickname
}

override public func unbind() {
super.unbind()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ public final class AccountRepository: AccountImpl {
meApiWorekr.fetchMemberInfo()
.asObservable()
.withUnretained(self)
.bind(onNext: {
let memberInfo = $0.1
print("member Info: \(memberInfo?.memberId)")
})
.bind(onNext: { $0.0.saveMemberInfo($0.1) })
.disposed(by: disposeBag)
}

Expand Down Expand Up @@ -142,10 +139,29 @@ public final class AccountRepository: AccountImpl {
.asObservable()
}

private func saveMemberInfo(_ memberInfo: MemberInfo?) {

guard let memberInfo = memberInfo else { return }

App.Repository.member.memberID.accept(memberInfo.memberId)
App.Repository.member.familyId.accept(memberInfo.familyId)
App.Repository.member.nickname.accept(memberInfo.name)

let member: ProfileData = ProfileData(memberId: memberInfo.memberId, profileImageURL: memberInfo.imageUrl, name: memberInfo.name)
FamilyUserDefaults.saveMyMemberId(memberId: memberInfo.memberId)
FamilyUserDefaults.saveMemberToUserDefaults(familyMember: member)
}


public init() {
signInHelper.bind()

signInHelper.snsSignInResult
.filter { $0.0 == .success }
.withUnretained(self)
.bind(onNext: { $0.0.fetchMemberInfo.accept(()) })
.disposed(by: disposeBag)

fetchMemberInfo
.withUnretained(self)
.bind(onNext: { $0.0.fetchMember() })
Expand Down
13 changes: 0 additions & 13 deletions 14th-team5-iOS/Data/Sources/Account/MeAPI/MeAPIWorker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,6 @@ extension MeAPIWorker: MeRepositoryProtocol, JoinFamilyRepository {
.asSingle()
}

private func saveMemberInfo(_ memberInfo: MemberInfo) {
App.Repository.member.memberID.accept(memberInfo.memberId)
App.Repository.member.familyId.accept(memberInfo.familyId)

let member: ProfileData = ProfileData(memberId: memberInfo.memberId, profileImageURL: memberInfo.imageUrl, name: memberInfo.name)
FamilyUserDefaults.saveMyMemberId(memberId: memberInfo.memberId)
FamilyUserDefaults.saveMemberToUserDefaults(familyMember: member)
}

private func getMemberInfo(spec: APISpec, headers: [APIHeader]?) -> Single<MemberInfo?> {

return request(spec: spec, headers: headers)
Expand All @@ -108,10 +99,6 @@ extension MeAPIWorker: MeRepositoryProtocol, JoinFamilyRepository {
})
.map(MemberInfo.self)
.catchAndReturn(nil)
.do {
guard let memberInfo = $0 else { return }
self.saveMemberInfo(memberInfo)
}
.asSingle()
}

Expand Down

0 comments on commit 5fcd910

Please sign in to comment.