From 842cbc307313979fbbd9b047412228da7cd274dc Mon Sep 17 00:00:00 2001 From: Yu Sung Date: Mon, 23 Sep 2024 16:57:22 +0900 Subject: [PATCH] =?UTF-8?q?=EC=8B=9C=EB=A6=AC=EC=A6=88=20=EC=83=81?= =?UTF-8?q?=EC=84=B8=20-=20=ED=81=AC=EB=A6=AC=EC=97=90=EC=9D=B4=ED=84=B0?= =?UTF-8?q?=20=ED=8C=94=EB=A1=9C=EC=9A=B0=EC=99=80=20=EC=95=8C=EB=A6=BC?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20-=20=ED=8C=94=EB=A1=9C=EC=9E=89=20?= =?UTF-8?q?=EC=83=81=ED=83=9C=EC=97=90=EC=84=9C=20=EC=95=8C=EB=A6=BC=20?= =?UTF-8?q?=EC=BC=9C=EA=B8=B0/=EB=81=84=EA=B8=B0=20=EC=83=81=ED=83=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Detail/GetSeriesDetailResponse.swift | 1 + .../Series/Detail/SeriesDetailView.swift | 46 ++++++++++++++++--- .../Series/Detail/SeriesDetailViewModel.swift | 9 ++-- .../Dialog/CreatorFollowNotifyDialog.swift | 1 + 4 files changed, 47 insertions(+), 10 deletions(-) diff --git a/SodaLive/Sources/Content/Series/Detail/GetSeriesDetailResponse.swift b/SodaLive/Sources/Content/Series/Detail/GetSeriesDetailResponse.swift index 8a2f320..70462eb 100644 --- a/SodaLive/Sources/Content/Series/Detail/GetSeriesDetailResponse.swift +++ b/SodaLive/Sources/Content/Series/Detail/GetSeriesDetailResponse.swift @@ -34,4 +34,5 @@ struct GetSeriesDetailCreator: Decodable { let nickname: String let profileImage: String let isFollow: Bool + let isNotify: Bool } diff --git a/SodaLive/Sources/Content/Series/Detail/SeriesDetailView.swift b/SodaLive/Sources/Content/Series/Detail/SeriesDetailView.swift index 20d4028..25e3a83 100644 --- a/SodaLive/Sources/Content/Series/Detail/SeriesDetailView.swift +++ b/SodaLive/Sources/Content/Series/Detail/SeriesDetailView.swift @@ -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) + } + ) + } } } } diff --git a/SodaLive/Sources/Content/Series/Detail/SeriesDetailViewModel.swift b/SodaLive/Sources/Content/Series/Detail/SeriesDetailViewModel.swift index bd15baa..f1fbb1f 100644 --- a/SodaLive/Sources/Content/Series/Detail/SeriesDetailViewModel.swift +++ b/SodaLive/Sources/Content/Series/Detail/SeriesDetailViewModel.swift @@ -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 diff --git a/SodaLive/Sources/Dialog/CreatorFollowNotifyDialog.swift b/SodaLive/Sources/Dialog/CreatorFollowNotifyDialog.swift index 14736b5..adf31d4 100644 --- a/SodaLive/Sources/Dialog/CreatorFollowNotifyDialog.swift +++ b/SodaLive/Sources/Dialog/CreatorFollowNotifyDialog.swift @@ -93,6 +93,7 @@ struct CreatorFollowNotifyItem: View { Spacer() } + .contentShape(Rectangle()) .onTapGesture(perform: onTapGesture) } }