Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/#138 ReactorKit 적용 - 북마크 #141

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Reet-Place/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ target 'Reet-Place' do
pod 'RxDataSources', '~> 5.0'

# Others
pod 'ReactorKit'
pod 'Alamofire'
pod 'SnapKit'
pod 'Then'
Expand Down
11 changes: 10 additions & 1 deletion Reet-Place/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ PODS:
- NMapsGeometry (1.0.1)
- NMapsMap (3.16.2):
- NMapsGeometry
- ReactorKit (3.2.0):
- RxSwift (~> 6.0)
- WeakMapTable (~> 1.1)
- RxCocoa (6.5.0):
- RxRelay (= 6.5.0)
- RxSwift (= 6.5.0)
Expand All @@ -31,6 +34,7 @@ PODS:
- RxSwift (6.5.0)
- SnapKit (5.6.0)
- Then (3.0.0)
- WeakMapTable (1.2.0)

DEPENDENCIES:
- Alamofire
Expand All @@ -39,6 +43,7 @@ DEPENDENCIES:
- KakaoSDKUser (<= 2.16)
- Kingfisher (~> 7.0)
- NMapsMap
- ReactorKit
- RxCocoa (= 6.5.0)
- RxDataSources (~> 5.0)
- RxGesture
Expand All @@ -56,13 +61,15 @@ SPEC REPOS:
- Kingfisher
- NMapsGeometry
- NMapsMap
- ReactorKit
- RxCocoa
- RxDataSources
- RxGesture
- RxRelay
- RxSwift
- SnapKit
- Then
- WeakMapTable

SPEC CHECKSUMS:
Alamofire: 4e95d97098eacb88856099c4fc79b526a299e48c
Expand All @@ -73,14 +80,16 @@ SPEC CHECKSUMS:
Kingfisher: 6c5449c6450c5239166510ba04afe374a98afc4f
NMapsGeometry: 53c573ead66466681cf123f99f698dc8071a4b83
NMapsMap: aaa64717249b06ae82c3a3addb3a01f0e33100ab
ReactorKit: e8b11d6b9c415405f381669b095c154a05b59eca
RxCocoa: 94f817b71c07517321eb4f9ad299112ca8af743b
RxDataSources: aa47cc1ed6c500fa0dfecac5c979b723542d79cf
RxGesture: f3efb47ed2d26a8082f7b660d4a59970e275a7f8
RxRelay: 1de1523e604c72b6c68feadedd1af3b1b4d0ecbd
RxSwift: 5710a9e6b17f3c3d6e40d6e559b9fa1e813b2ef8
SnapKit: e01d52ebb8ddbc333eefe2132acf85c8227d9c25
Then: 844265ae87834bbe1147d91d5d41a404da2ec27d
WeakMapTable: 05c694ce8439a7a9ebabb56187287a63c57673d6

PODFILE CHECKSUM: 6eace9c5f53459f66ad27511b12d74fe7bca04d0
PODFILE CHECKSUM: 65003312d4883474af61cbcbaac9fb791372e229

COCOAPODS: 1.11.3
8 changes: 4 additions & 4 deletions Reet-Place/Reet-Place.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
0E1B62CF2B315AD000C1E609 /* BookmarkSummaryResponseModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E1B62CE2B315AD000C1E609 /* BookmarkSummaryResponseModel.swift */; };
0E1B62D12B3174FE00C1E609 /* DeleteAccountModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E1B62D02B3174FE00C1E609 /* DeleteAccountModel.swift */; };
0E1B62D32B332D2C00C1E609 /* BookmarkSaveRequestModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E1B62D22B332D2C00C1E609 /* BookmarkSaveRequestModel.swift */; };
0E2D6F2A29EBBB7D0053CD90 /* BookmarkMainModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E2D6F2929EBBB7D0053CD90 /* BookmarkMainModel.swift */; };
0E2D6F2A29EBBB7D0053CD90 /* BookmarkTypeInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E2D6F2929EBBB7D0053CD90 /* BookmarkTypeInfo.swift */; };
0E2D6F2C29EBBD180053CD90 /* UIImageView+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E2D6F2B29EBBD180053CD90 /* UIImageView+.swift */; };
0E2D6F5429F140A80053CD90 /* ReetPopUp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E2D6F5329F140A80053CD90 /* ReetPopUp.swift */; };
0E4971E02BA463CF0006BDB1 /* EndPoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E4971DF2BA463CF0006BDB1 /* EndPoint.swift */; };
Expand Down Expand Up @@ -226,7 +226,7 @@
0E1B62CE2B315AD000C1E609 /* BookmarkSummaryResponseModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarkSummaryResponseModel.swift; sourceTree = "<group>"; };
0E1B62D02B3174FE00C1E609 /* DeleteAccountModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeleteAccountModel.swift; sourceTree = "<group>"; };
0E1B62D22B332D2C00C1E609 /* BookmarkSaveRequestModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarkSaveRequestModel.swift; sourceTree = "<group>"; };
0E2D6F2929EBBB7D0053CD90 /* BookmarkMainModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarkMainModel.swift; sourceTree = "<group>"; };
0E2D6F2929EBBB7D0053CD90 /* BookmarkTypeInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarkTypeInfo.swift; sourceTree = "<group>"; };
0E2D6F2B29EBBD180053CD90 /* UIImageView+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImageView+.swift"; sourceTree = "<group>"; };
0E2D6F5329F140A80053CD90 /* ReetPopUp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReetPopUp.swift; sourceTree = "<group>"; };
0E4971DF2BA463CF0006BDB1 /* EndPoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EndPoint.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -507,7 +507,7 @@
0EA432DE29A10F0900C4D47F /* Model */ = {
isa = PBXGroup;
children = (
0E2D6F2929EBBB7D0053CD90 /* BookmarkMainModel.swift */,
0E2D6F2929EBBB7D0053CD90 /* BookmarkTypeInfo.swift */,
0EA432DF29A10F2300C4D47F /* BookmarkCardModel.swift */,
0E502B782A919DEE002C71F2 /* BookmarkCountResponseModel.swift */,
0E502B722A9197BB002C71F2 /* BookmarkListResponseModel.swift */,
Expand Down Expand Up @@ -1421,7 +1421,7 @@
3C3255E32A35ED1300F96F82 /* SearchVC.swift in Sources */,
3C72D92C2B3401F200AF2190 /* ReetPlace.xcdatamodeld in Sources */,
3C4DA53F2A56518900274692 /* LoginVC.swift in Sources */,
0E2D6F2A29EBBB7D0053CD90 /* BookmarkMainModel.swift in Sources */,
0E2D6F2A29EBBB7D0053CD90 /* BookmarkTypeInfo.swift in Sources */,
3C2784162A0A652E0095B706 /* ReetMenuTarBarCVC.swift.swift in Sources */,
0E1B62CD2B315AB900C1E609 /* BookmarkSummaryModel.swift in Sources */,
A4AABE6F299BC0D400BA9D37 /* AssetFonts.swift in Sources */,
Expand Down
1 change: 0 additions & 1 deletion Reet-Place/Reet-Place/Global/Network/AuthInterceptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ final class AuthInterceptor: RequestInterceptor {
completion(.doNotRetryWithError(error))
return
}
tabBarVC.showToast(message: "LogoutSuccess".localized, bottomViewHeight: 50.0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗 여기서 커밋 메시지로 작성한 스레드 문제가 뭐였나요?? 어떤 점이 문제였는지 기억이 나질 않네요😅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기존 AuthInterceptor에서 해당 코드를 호출할 때
메인 스레드가 아닌 다른 스레드에서 UI 작업을 시도하기 때문에 문제가 발생했습니다!
이번에 발견한 문제였어요,, 😅

myPageVC.updateLoginStatus()

print("로그인 만료")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class BookmarkTypeCVC: BaseCollectionViewCell {

// MARK: - Function

func configureData(typeInfo: TypeInfo) {
func configureData(typeInfo: BookmarkTypeInfo) {
switch typeInfo.type {
case "WANT":
titleLabel.text = "BookmarkWishlist".localized
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,30 @@ struct BookmarkInfo: Decodable {
}
}

extension BookmarkInfo {
static let empty: Self = .init(id: 0,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

북마크 정보에 emtpy 모델을 추가신 이유가 있을까요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

State에서 초기값으로 사용하기 위해 추가해주었습니다!

member: .empty,
place: .empty,
type: .empty,
thumbnailImage: nil,
rate: 1,
people: nil,
relLink1: nil,
relLink2: nil,
relLink3: nil)
}

struct BookmarkUserInfo: Decodable {
let id: Int
let uid: String
let loginType: String
let nickname: String
}

extension BookmarkUserInfo {
static let empty: Self = .init(id: 0, uid: .empty, loginType: .empty, nickname: .empty)
}

struct BookmarkPlaceInfo: Decodable {
let id: Int
let kakaoPid: String
Expand All @@ -69,6 +86,21 @@ struct BookmarkPlaceInfo: Decodable {
let lng: String
}

extension BookmarkPlaceInfo {
static let empty: Self = .init(id: 0,
kakaoPid: .empty,
name: .empty,
url: .empty,
categoryGroupCode: nil,
kakaoCategoryName: .empty,
category: .empty,
subCategory: .empty,
lotNumberAddress: .empty,
roadAddress: .empty,
lat: .empty,
lng: .empty)
}

struct SortInfo: Decodable {
let empty: Bool
let unsorted: Bool
Expand Down

This file was deleted.

20 changes: 20 additions & 0 deletions Reet-Place/Reet-Place/Screen/BookMark/Model/BookmarkTypeInfo.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// BookmarkTypeInfo.swift
// Reet-Place
//
// Created by 김태현 on 2023/04/16.
//

import Foundation

struct BookmarkTypeInfo {
let type: String
let cnt: Int
let thumbnailUrlString: String
}

extension BookmarkTypeInfo {
static let empty: Self = .init(type: .empty,
cnt: 0,
thumbnailUrlString: .empty)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import Then
import RxSwift
import RxGesture
import RxCocoa
import ReactorKit

final class BookmarkBottomSheetVC: ReetBottomSheet {
final class BookmarkBottomSheetVC: ReetBottomSheet, View {

// MARK: - UI components

Expand Down Expand Up @@ -142,6 +143,7 @@ final class BookmarkBottomSheetVC: ReetBottomSheet {
// MARK: - Variables and Properties

private let viewModel: BookmarkBottomSheetVM = .init()
var disposeBag: DisposeBag = .init()

private var urlField : [ReetTextField] = []
private let isBookmarking: Bool
Expand Down Expand Up @@ -169,6 +171,12 @@ final class BookmarkBottomSheetVC: ReetBottomSheet {

// MARK: - Life Cycle

override func viewDidLoad() {
super.viewDidLoad()

reactor = viewModel
}

override func configureView() {
super.configureView()

Expand All @@ -184,12 +192,44 @@ final class BookmarkBottomSheetVC: ReetBottomSheet {
override func bindRx() {
super.bindRx()

bind()
bindBtn()
bindKeyboard()
}


// MARK: - Bind Reactor

func bind(reactor: BookmarkBottomSheetVM) {
reactor.state.map { $0.isSuccessDelete }
.filter { $0 }
.withUnretained(self)
.subscribe { owner, _ in
guard let id = owner.bookmarkID else { return }
owner.dismissBottomSheet()
owner.deletedBookmarkId.onNext(id)
}
.disposed(by: disposeBag)

reactor.state.map { $0.successModifiedInfo }
.skip(1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 skip은 어떤 상황에서 역할을 하게 되는건가요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

State의 초기값(empty 모델)을 제외하고 그 다음 데이터부터 받아오기 위해 사용했습니다~!

.withUnretained(self)
.subscribe { owner, modifiedInfo in
owner.dismissBottomSheet()
owner.modifiedBookmarkInfo.onNext(modifiedInfo)
}
.disposed(by: disposeBag)

reactor.state.map { $0.savedType }
.skip(1)
.withUnretained(self)
.subscribe { owner, type in
owner.dismissBottomSheet()
owner.savedBookmarkType.onNext(type)
}
.disposed(by: disposeBag)
}


// MARK: - Functions

func addUrl() {
Expand All @@ -209,7 +249,7 @@ final class BookmarkBottomSheetVC: ReetBottomSheet {

@objc func deleteBookmark() {
guard let id = bookmarkID else { return }
viewModel.deleteBookmark(id: id)
viewModel.action.onNext(.deleteBookmark(id: id))
}

func getModifiedBookmarkData() -> BookmarkCardModel? {
Expand Down Expand Up @@ -407,35 +447,7 @@ extension BookmarkBottomSheetVC {
// MARK: - Bind

extension BookmarkBottomSheetVC {

private func bind() {
viewModel.output.isSuccessDelete
.filter { $0 }
.withUnretained(self)
.subscribe { owner, _ in
guard let id = owner.bookmarkID else { return }
owner.dismissBottomSheet()
owner.deletedBookmarkId.onNext(id)
}
.disposed(by: bag)

viewModel.output.isSuccessModify
.withUnretained(self)
.subscribe { owner, bookmarkInfo in
owner.dismissBottomSheet()
owner.modifiedBookmarkInfo.onNext(bookmarkInfo)
}
.disposed(by: bag)

viewModel.output.isSuccessSave
.withUnretained(self)
.subscribe { owner, bookmarkType in
owner.dismissBottomSheet()
owner.savedBookmarkType.onNext(bookmarkType)
}
.disposed(by: bag)
}


private func bindKeyboard() {
// 키보드가 올라올 때
keyboardWillShow
Expand Down Expand Up @@ -471,9 +483,9 @@ extension BookmarkBottomSheetVC {
private func bindBtn() {
// 관련 url 추가
addBtn.rx.tap
.bind(onNext: { [weak self] _ in
guard let self = self else { return }
self.addUrl()
.withUnretained(self)
.bind(onNext: { owner, _ in
owner.addUrl()
})
.disposed(by: bag)

Expand All @@ -483,7 +495,7 @@ extension BookmarkBottomSheetVC {
.throttle(.seconds(1), latest: false, scheduler: MainScheduler.asyncInstance)
.bind(onNext: { owner, _ in
guard let modifiedData = owner.getModifiedBookmarkData() else { return }
owner.viewModel.modifyBookmark(modifyInfo: modifiedData)
owner.viewModel.action.onNext(.modifyBookmark(modifiedInfo: modifiedData))
})
.disposed(by: bag)

Expand All @@ -505,7 +517,7 @@ extension BookmarkBottomSheetVC {
.bind(onNext: { owner, _ in
guard let searchPlaceInfo = owner.searchPlaceInfo,
let modifiedData = owner.getModifiedBookmarkData() else { return }
owner.viewModel.saveBookmark(searchPlaceInfo: searchPlaceInfo, modifyInfo: modifiedData)
owner.viewModel.action.onNext(.saveBookmark(searchPlaceInfo: searchPlaceInfo, modifiedInfo: modifiedData))
})
.disposed(by: bag)
}
Expand Down
Loading
Loading