시리즈 상세 - 크리에이터 팔로우와 알림설정

- 팔로잉 상태에서 알림 켜기/끄기 상태 추가
This commit is contained in:
Yu Sung 2024-09-23 16:57:22 +09:00
parent ed4729ac11
commit 842cbc3073
4 changed files with 47 additions and 10 deletions

View File

@ -34,4 +34,5 @@ struct GetSeriesDetailCreator: Decodable {
let nickname: String
let profileImage: String
let isFollow: Bool
let isNotify: Bool
}

View File

@ -14,6 +14,16 @@ struct SeriesDetailView: View {
let seriesId: Int
@State private var isShowFollowNotifyDialog: Bool = false {
didSet {
if !isShowFollowNotifyDialog {
creatorId = 0
}
}
}
@State private var creatorId: Int = 0
var body: some View {
BaseView(isLoading: $viewModel.isLoading) {
ZStack(alignment: .top) {
@ -122,14 +132,21 @@ struct SeriesDetailView: View {
Spacer()
if seriesDetail.creator.creatorId != UserDefaults.int(forKey: .userId) {
Image(viewModel.isFollow ? "btn_following_big" : "btn_follow_big")
.onTapGesture {
if viewModel.isFollow {
viewModel.unFollow(seriesDetail.creator.creatorId)
} else {
viewModel.follow(seriesDetail.creator.creatorId)
}
Image(
viewModel.isFollow ?
viewModel.isNotify ?
"btn_following_big" :
"btn_following_no_alarm_big" :
"btn_follow_big"
)
.onTapGesture {
if viewModel.isFollow {
creatorId = seriesDetail.creator.creatorId
isShowFollowNotifyDialog = true
} else {
viewModel.follow(seriesDetail.creator.creatorId)
}
}
}
}
.padding(.top, 16)
@ -183,6 +200,21 @@ struct SeriesDetailView: View {
.background(Color.gray11)
}
}
if isShowFollowNotifyDialog {
CreatorFollowNotifyDialog(
isShowing: $isShowFollowNotifyDialog,
onClickNotifyAll: {
viewModel.follow(creatorId, follow: true, notify: true)
},
onClickNotifyNone: {
viewModel.follow(creatorId, follow: true, notify: false)
},
onClickUnFollow: {
viewModel.follow(creatorId, follow: false, notify: false)
}
)
}
}
}
}

View File

@ -18,6 +18,7 @@ final class SeriesDetailViewModel: ObservableObject {
@Published var isShowPopup = false
@Published var isFollow: Bool = false
@Published var isNotify: Bool = false
@Published var seriesDetail: GetSeriesDetailResponse? = nil
var seriesId: Int = 0
@ -44,6 +45,7 @@ final class SeriesDetailViewModel: ObservableObject {
if let data = decoded.data, decoded.success {
self.seriesDetail = data
self.isFollow = data.creator.isFollow
self.isNotify = data.creator.isNotify
} else {
if let message = decoded.message {
self.errorMessage = message
@ -63,10 +65,10 @@ final class SeriesDetailViewModel: ObservableObject {
.store(in: &subscription)
}
func follow(_ creatorId: Int) {
func follow(_ creatorId: Int, follow: Bool = true, notify: Bool = true) {
isLoading = true
userRepository.creatorFollow(creatorId: creatorId)
userRepository.creatorFollow(creatorId: creatorId, follow: follow, notify: notify)
.sink { result in
switch result {
case .finished:
@ -83,7 +85,8 @@ final class SeriesDetailViewModel: ObservableObject {
let decoded = try jsonDecoder.decode(ApiResponseWithoutData.self, from: responseData)
if decoded.success {
self.isFollow = !self.isFollow
self.isFollow = follow
self.isNotify = notify
} else {
if let message = decoded.message {
self.errorMessage = message

View File

@ -93,6 +93,7 @@ struct CreatorFollowNotifyItem: View {
Spacer()
}
.contentShape(Rectangle())
.onTapGesture(perform: onTapGesture)
}
}