diff --git a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/All/CreatorCommunityAllItemView.swift b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/All/CreatorCommunityAllItemView.swift index fbefe34..d5d25ed 100644 --- a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/All/CreatorCommunityAllItemView.swift +++ b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/All/CreatorCommunityAllItemView.swift @@ -120,6 +120,7 @@ struct CreatorCommunityAllItemView_Previews: PreviewProvider { CreatorCommunityAllItemView( item: GetCommunityPostListResponse( postId: 1, + creatorId: 1, creatorNickname: "민하나", creatorProfileUrl: "https://test-cf.sodalive.net/profile/default-profile.png", imageUrl: "https://test-cf.sodalive.net/profile/default-profile.png", diff --git a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/CreatorCommunityApi.swift b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/CreatorCommunityApi.swift index 2c4f9f7..a48b6a5 100644 --- a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/CreatorCommunityApi.swift +++ b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/CreatorCommunityApi.swift @@ -18,6 +18,7 @@ enum CreatorCommunityApi { case getCommunityPostCommentList(postId: Int, page: Int, size: Int) case getCommentReplyList(commentId: Int, page: Int, size: Int) case modifyComment(request: ModifyCommunityPostCommentRequest) + case getLatestPostListFromCreatorsYouFollow } extension CreatorCommunityApi: TargetType { @@ -44,6 +45,9 @@ extension CreatorCommunityApi: TargetType { case .getCommunityPostDetail(let postId): return "/creator-community/\(postId)" + + case .getLatestPostListFromCreatorsYouFollow: + return "/creator-community/latest" } } @@ -52,7 +56,7 @@ extension CreatorCommunityApi: TargetType { case .createCommunityPost, .communityPostLike, .createCommunityPostComment: return .post - case .getCommunityPostList, .getCommunityPostCommentList, .getCommentReplyList, .getCommunityPostDetail: + case .getCommunityPostList, .getCommunityPostCommentList, .getCommentReplyList, .getCommunityPostDetail, .getLatestPostListFromCreatorsYouFollow: return .get case .modifyComment, .modifyCommunityPost: @@ -107,6 +111,10 @@ extension CreatorCommunityApi: TargetType { case .getCommunityPostDetail: let parameters = ["timezone": TimeZone.current.identifier] as [String: Any] return .requestParameters(parameters: parameters, encoding: URLEncoding.queryString) + + case .getLatestPostListFromCreatorsYouFollow: + let parameters = ["timezone": TimeZone.current.identifier] as [String: Any] + return .requestParameters(parameters: parameters, encoding: URLEncoding.queryString) } } diff --git a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/CreatorCommunityItemView.swift b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/CreatorCommunityItemView.swift index 38513f2..0c99de2 100644 --- a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/CreatorCommunityItemView.swift +++ b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/CreatorCommunityItemView.swift @@ -86,6 +86,7 @@ struct CreatorCommunityItemView_Previews: PreviewProvider { CreatorCommunityItemView( item: GetCommunityPostListResponse( postId: 1, + creatorId: 1, creatorNickname: "민하나", creatorProfileUrl: "https://test-cf.sodalive.net/profile/default-profile.png", imageUrl: "https://test-cf.sodalive.net/profile/default-profile.png", diff --git a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/CreatorCommunityRepository.swift b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/CreatorCommunityRepository.swift index 40bc787..2504cf3 100644 --- a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/CreatorCommunityRepository.swift +++ b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/CreatorCommunityRepository.swift @@ -48,4 +48,8 @@ class CreatorCommunityRepository { func modifyComment(request: ModifyCommunityPostCommentRequest) -> AnyPublisher { return api.requestPublisher(.modifyComment(request: request)) } + + func getLatestPostListFromCreatorsYouFollow() -> AnyPublisher { + return api.requestPublisher(.getLatestPostListFromCreatorsYouFollow) + } } diff --git a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/GetCommunityPostListResponse.swift b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/GetCommunityPostListResponse.swift index 884a9ca..15afde1 100644 --- a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/GetCommunityPostListResponse.swift +++ b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/GetCommunityPostListResponse.swift @@ -7,6 +7,7 @@ struct GetCommunityPostListResponse: Decodable { let postId: Int + let creatorId: Int let creatorNickname: String let creatorProfileUrl: String let imageUrl: String? diff --git a/SodaLive/Sources/Live/LiveView.swift b/SodaLive/Sources/Live/LiveView.swift index 1236ab1..0767e95 100644 --- a/SodaLive/Sources/Live/LiveView.swift +++ b/SodaLive/Sources/Live/LiveView.swift @@ -25,11 +25,10 @@ struct LiveView: View { viewModel.getSummary() } ) { - VStack(spacing: 0) { + LazyVStack(spacing: 40) { if viewModel.recommendLiveItems.count > 0 { SectionRecommendLiveView(items: viewModel.recommendLiveItems) .padding(.top, 13.3) - .padding(.bottom, 40) } if viewModel.recommendChannelItems.count > 0 { @@ -50,7 +49,6 @@ struct LiveView: View { AppState.shared.setAppStep(step: .createLive(timeSettingMode: .NOW, onSuccess: onCreateSuccess)) } ) - .padding(.top, 40) if viewModel.eventBannerItems.count > 0 { SectionEventBannerView(items: viewModel.eventBannerItems) @@ -59,7 +57,10 @@ struct LiveView: View { height: viewModel.eventBannerItems.count > 0 ? screenSize().width * 300 / 1000 : 0, alignment: .center ) - .padding(.top, 40) + } + + if viewModel.communityPostItems.count > 0 { + SectionCommunityPostView(items: viewModel.communityPostItems) } SectionLiveReservationView( @@ -73,7 +74,6 @@ struct LiveView: View { AppState.shared.setAppStep(step: .createLive(timeSettingMode: .RESERVATION, onSuccess: onCreateSuccess)) } ) - .padding(.top, 40) } } .frame(width: geo.size.width, height: geo.size.height) diff --git a/SodaLive/Sources/Live/LiveViewModel.swift b/SodaLive/Sources/Live/LiveViewModel.swift index f1896c2..3688c31 100644 --- a/SodaLive/Sources/Live/LiveViewModel.swift +++ b/SodaLive/Sources/Live/LiveViewModel.swift @@ -13,6 +13,7 @@ final class LiveViewModel: ObservableObject { private let repository = LiveRepository() private let eventRepository = EventRepository() private let liveRecommendRepository = LiveRecommendRepository() + private let creatorCommunityRepository = CreatorCommunityRepository() private var subscription = Set() @Published private(set) var eventBannerItems = [EventItem]() @@ -21,6 +22,7 @@ final class LiveViewModel: ObservableObject { @Published private(set) var recommendLiveItems: [GetRecommendLiveResponse] = [] @Published private(set) var recommendChannelItems: [GetRecommendChannelResponse] = [] @Published private(set) var followedChannelItems: [GetRecommendChannelResponse] = [] + @Published private(set) var communityPostItems: [GetCommunityPostListResponse] = [] @Published var errorMessage = "" @Published var isShowPopup = false @@ -80,6 +82,7 @@ final class LiveViewModel: ObservableObject { getFollowedChannelList() getRecommendChannelList() getRecommendLive() + getLatestPostListFromCreatorsYouFollow() isLoading = true eventBannerItems.removeAll() @@ -644,4 +647,42 @@ final class LiveViewModel: ObservableObject { } .store(in: &subscription) } + + private func getLatestPostListFromCreatorsYouFollow() { + communityPostItems.removeAll() + + creatorCommunityRepository.getLatestPostListFromCreatorsYouFollow() + .sink { result in + switch result { + case .finished: + DEBUG_LOG("finish") + case .failure(let error): + ERROR_LOG(error.localizedDescription) + } + } receiveValue: { [unowned self] response in + self.isRecommendLiveLoading = false + let responseData = response.data + + do { + let jsonDecoder = JSONDecoder() + let decoded = try jsonDecoder.decode(ApiResponse<[GetCommunityPostListResponse]>.self, from: responseData) + + if let data = decoded.data, decoded.success { + self.communityPostItems.append(contentsOf: data) + } else { + if let message = decoded.message { + self.errorMessage = message + } else { + self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다." + } + self.isShowPopup = true + } + } catch { + self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다." + self.isShowPopup = true + } + } + .store(in: &subscription) + + } } diff --git a/SodaLive/Sources/Live/SectionCommunityPostView.swift b/SodaLive/Sources/Live/SectionCommunityPostView.swift new file mode 100644 index 0000000..f622ee3 --- /dev/null +++ b/SodaLive/Sources/Live/SectionCommunityPostView.swift @@ -0,0 +1,66 @@ +// +// SectionCommunityPostView.swift +// SodaLive +// +// Created by klaus on 2023/12/21. +// + +import SwiftUI + +struct SectionCommunityPostView: View { + + let items: [GetCommunityPostListResponse] + + var body: some View { + ScrollView(.horizontal, showsIndicators: false) { + HStack(spacing: 13.3) { + ForEach(0..