팔로잉/팔로워 리스트 - 팔로우와 알림설정

- 팔로잉 상태에서 알림 켜기/끄기 상태 추가
This commit is contained in:
Yu Sung
2024-09-23 17:54:35 +09:00
parent 31696ce7da
commit 6c8f3eb8bb
8 changed files with 167 additions and 100 deletions

View File

@@ -12,9 +12,7 @@ struct FollowCreatorItemView: View {
let creator: GetCreatorFollowingAllListItem
let onClickFollow: (Int) -> Void
let onClickUnFollow: (Int) -> Void
@State private var isFollow = true
let showCreatorFollowNotifyDialog: (Int) -> Void
var body: some View {
VStack(spacing: 13.3) {
@@ -26,29 +24,30 @@ struct FollowCreatorItemView: View {
Text(creator.nickname)
.font(.custom(Font.bold.rawValue, size: 16.7))
.foregroundColor(Color(hex: "eeeeee"))
.foregroundColor(Color.grayee)
.padding(.leading, 13.3)
Spacer()
Image(isFollow ? "btn_following_big" : "btn_follow_big")
.onTapGesture {
if isFollow {
onClickUnFollow(creator.creatorId)
} else {
onClickFollow(creator.creatorId)
}
isFollow = !isFollow
Image(
creator.isFollow ?
creator.isNotify ?
"btn_following_big" :
"btn_following_no_alarm_big" :
"btn_follow_big"
)
.onTapGesture {
if creator.isFollow {
showCreatorFollowNotifyDialog(creator.creatorId)
} else {
onClickFollow(creator.creatorId)
}
}
}
Rectangle()
.foregroundColor(Color(hex: "595959"))
.foregroundColor(Color.gray59)
.frame(height: 0.5)
}
.onAppear {
isFollow = creator.isFollow
}
}
}

View File

@@ -11,6 +11,10 @@ struct FollowCreatorView: View {
@StateObject var viewModel = FollowCreatorViewModel()
@State private var isShowFollowNotifyDialog: Bool = false
@State private var creatorId: Int = 0
@State private var selectedItemIndex: Int = 0
var body: some View {
BaseView(isLoading: $viewModel.isLoading) {
VStack(spacing: 0) {
@@ -42,8 +46,14 @@ struct FollowCreatorView: View {
FollowCreatorItemView(
creator: creator,
onClickFollow: { viewModel.creatorFollow(userId: $0) },
onClickUnFollow: { viewModel.creatorUnFollow(userId: $0) }
onClickFollow: {
viewModel.creatorFollow(creatorId: $0, index: index)
},
showCreatorFollowNotifyDialog: {
creatorId = $0
selectedItemIndex = index
isShowFollowNotifyDialog = true
}
)
.padding(.horizontal, 20)
.onTapGesture {
@@ -84,6 +94,42 @@ struct FollowCreatorView: View {
Spacer()
}
}
if isShowFollowNotifyDialog {
CreatorFollowNotifyDialog(
isShowing: $isShowFollowNotifyDialog,
onClickNotifyAll: {
viewModel.creatorFollow(
creatorId: creatorId,
index: selectedItemIndex,
follow: true,
notify: true
)
creatorId = 0
selectedItemIndex = -1
},
onClickNotifyNone: {
viewModel.creatorFollow(
creatorId: creatorId,
index: selectedItemIndex,
follow: true,
notify: false
)
creatorId = 0
selectedItemIndex = -1
},
onClickUnFollow: {
viewModel.creatorFollow(
creatorId: creatorId,
index: selectedItemIndex,
follow: false,
notify: false
)
creatorId = 0
selectedItemIndex = -1
}
)
}
}
}
}

View File

@@ -80,8 +80,9 @@ final class FollowCreatorViewModel: ObservableObject {
}
}
func creatorFollow(userId: Int) {
userRepository.creatorFollow(creatorId: userId)
func creatorFollow(creatorId: Int, index: Int, follow: Bool = true, notify: Bool = true) {
isLoading = true
userRepository.creatorFollow(creatorId: creatorId, follow: follow, notify: notify)
.sink { result in
switch result {
case .finished:
@@ -89,20 +90,34 @@ final class FollowCreatorViewModel: ObservableObject {
case .failure(let error):
ERROR_LOG(error.localizedDescription)
}
} receiveValue: { _ in }
.store(in: &subscription)
}
func creatorUnFollow(userId: Int) {
userRepository.creatorUnFollow(creatorId: userId)
.sink { result in
switch result {
case .finished:
DEBUG_LOG("finish")
case .failure(let error):
ERROR_LOG(error.localizedDescription)
} receiveValue: { [unowned self] response in
self.isLoading = false
let responseData = response.data
do {
let jsonDecoder = JSONDecoder()
let decoded = try jsonDecoder.decode(ApiResponseWithoutData.self, from: responseData)
if decoded.success {
var creator = self.creatorList[index]
creator.isFollow = follow
creator.isNotify = notify
self.creatorList.remove(at: index)
self.creatorList.insert(creator, at: index)
} else {
if let message = decoded.message {
self.errorMessage = message
} else {
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
}
self.isShowPopup = true
}
} catch {
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
self.isShowPopup = true
}
} receiveValue: { _ in }
}
.store(in: &subscription)
}
}

View File

@@ -16,5 +16,6 @@ struct GetCreatorFollowingAllListItem: Decodable {
let creatorId: Int
let nickname: String
let profileImageUrl: String
let isFollow: Bool
var isFollow: Bool
var isNotify: Bool
}