-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: develop
Are you sure you want to change the base?
Changes from all commits
1f10c53
66cfc4f
958471e
d7b1335
dd07db4
5fb18f5
5f667a4
c9c52cc
078a1a3
21f74a6
08bbe18
0a89c8e
86a5583
384a13f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,13 +47,30 @@ struct BookmarkInfo: Decodable { | |
} | ||
} | ||
|
||
extension BookmarkInfo { | ||
static let empty: Self = .init(id: 0, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 북마크 정보에 emtpy 모델을 추가신 이유가 있을까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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 | ||
|
@@ -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 | ||
|
This file was deleted.
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 |
---|---|---|
|
@@ -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 | ||
|
||
|
@@ -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 | ||
|
@@ -169,6 +171,12 @@ final class BookmarkBottomSheetVC: ReetBottomSheet { | |
|
||
// MARK: - Life Cycle | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
reactor = viewModel | ||
} | ||
|
||
override func configureView() { | ||
super.configureView() | ||
|
||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 skip은 어떤 상황에서 역할을 하게 되는건가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
.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() { | ||
|
@@ -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? { | ||
|
@@ -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 | ||
|
@@ -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) | ||
|
||
|
@@ -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) | ||
|
||
|
@@ -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) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
앗 여기서 커밋 메시지로 작성한 스레드 문제가 뭐였나요?? 어떤 점이 문제였는지 기억이 나질 않네요😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
기존
AuthInterceptor
에서 해당 코드를 호출할 때메인 스레드가 아닌 다른 스레드에서 UI 작업을 시도하기 때문에 문제가 발생했습니다!
이번에 발견한 문제였어요,, 😅