parent
ed4729ac11
commit
842cbc3073
|
@ -34,4 +34,5 @@ struct GetSeriesDetailCreator: Decodable {
|
||||||
let nickname: String
|
let nickname: String
|
||||||
let profileImage: String
|
let profileImage: String
|
||||||
let isFollow: Bool
|
let isFollow: Bool
|
||||||
|
let isNotify: Bool
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,16 @@ struct SeriesDetailView: View {
|
||||||
|
|
||||||
let seriesId: Int
|
let seriesId: Int
|
||||||
|
|
||||||
|
@State private var isShowFollowNotifyDialog: Bool = false {
|
||||||
|
didSet {
|
||||||
|
if !isShowFollowNotifyDialog {
|
||||||
|
creatorId = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@State private var creatorId: Int = 0
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
BaseView(isLoading: $viewModel.isLoading) {
|
BaseView(isLoading: $viewModel.isLoading) {
|
||||||
ZStack(alignment: .top) {
|
ZStack(alignment: .top) {
|
||||||
|
@ -122,14 +132,21 @@ struct SeriesDetailView: View {
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
if seriesDetail.creator.creatorId != UserDefaults.int(forKey: .userId) {
|
if seriesDetail.creator.creatorId != UserDefaults.int(forKey: .userId) {
|
||||||
Image(viewModel.isFollow ? "btn_following_big" : "btn_follow_big")
|
Image(
|
||||||
.onTapGesture {
|
viewModel.isFollow ?
|
||||||
if viewModel.isFollow {
|
viewModel.isNotify ?
|
||||||
viewModel.unFollow(seriesDetail.creator.creatorId)
|
"btn_following_big" :
|
||||||
} else {
|
"btn_following_no_alarm_big" :
|
||||||
viewModel.follow(seriesDetail.creator.creatorId)
|
"btn_follow_big"
|
||||||
}
|
)
|
||||||
|
.onTapGesture {
|
||||||
|
if viewModel.isFollow {
|
||||||
|
creatorId = seriesDetail.creator.creatorId
|
||||||
|
isShowFollowNotifyDialog = true
|
||||||
|
} else {
|
||||||
|
viewModel.follow(seriesDetail.creator.creatorId)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.padding(.top, 16)
|
.padding(.top, 16)
|
||||||
|
@ -183,6 +200,21 @@ struct SeriesDetailView: View {
|
||||||
.background(Color.gray11)
|
.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)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ final class SeriesDetailViewModel: ObservableObject {
|
||||||
@Published var isShowPopup = false
|
@Published var isShowPopup = false
|
||||||
|
|
||||||
@Published var isFollow: Bool = false
|
@Published var isFollow: Bool = false
|
||||||
|
@Published var isNotify: Bool = false
|
||||||
@Published var seriesDetail: GetSeriesDetailResponse? = nil
|
@Published var seriesDetail: GetSeriesDetailResponse? = nil
|
||||||
|
|
||||||
var seriesId: Int = 0
|
var seriesId: Int = 0
|
||||||
|
@ -44,6 +45,7 @@ final class SeriesDetailViewModel: ObservableObject {
|
||||||
if let data = decoded.data, decoded.success {
|
if let data = decoded.data, decoded.success {
|
||||||
self.seriesDetail = data
|
self.seriesDetail = data
|
||||||
self.isFollow = data.creator.isFollow
|
self.isFollow = data.creator.isFollow
|
||||||
|
self.isNotify = data.creator.isNotify
|
||||||
} else {
|
} else {
|
||||||
if let message = decoded.message {
|
if let message = decoded.message {
|
||||||
self.errorMessage = message
|
self.errorMessage = message
|
||||||
|
@ -63,10 +65,10 @@ final class SeriesDetailViewModel: ObservableObject {
|
||||||
.store(in: &subscription)
|
.store(in: &subscription)
|
||||||
}
|
}
|
||||||
|
|
||||||
func follow(_ creatorId: Int) {
|
func follow(_ creatorId: Int, follow: Bool = true, notify: Bool = true) {
|
||||||
isLoading = true
|
isLoading = true
|
||||||
|
|
||||||
userRepository.creatorFollow(creatorId: creatorId)
|
userRepository.creatorFollow(creatorId: creatorId, follow: follow, notify: notify)
|
||||||
.sink { result in
|
.sink { result in
|
||||||
switch result {
|
switch result {
|
||||||
case .finished:
|
case .finished:
|
||||||
|
@ -83,7 +85,8 @@ final class SeriesDetailViewModel: ObservableObject {
|
||||||
let decoded = try jsonDecoder.decode(ApiResponseWithoutData.self, from: responseData)
|
let decoded = try jsonDecoder.decode(ApiResponseWithoutData.self, from: responseData)
|
||||||
|
|
||||||
if decoded.success {
|
if decoded.success {
|
||||||
self.isFollow = !self.isFollow
|
self.isFollow = follow
|
||||||
|
self.isNotify = notify
|
||||||
} else {
|
} else {
|
||||||
if let message = decoded.message {
|
if let message = decoded.message {
|
||||||
self.errorMessage = message
|
self.errorMessage = message
|
||||||
|
|
|
@ -93,6 +93,7 @@ struct CreatorFollowNotifyItem: View {
|
||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
}
|
}
|
||||||
|
.contentShape(Rectangle())
|
||||||
.onTapGesture(perform: onTapGesture)
|
.onTapGesture(perform: onTapGesture)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue