diff --git a/PingPong/Projects/Feature/Core/Sources/UI/View/TabView/CoreView.swift b/PingPong/Projects/Feature/Core/Sources/UI/View/TabView/CoreView.swift index 1e00a643..cc34595e 100644 --- a/PingPong/Projects/Feature/Core/Sources/UI/View/TabView/CoreView.swift +++ b/PingPong/Projects/Feature/Core/Sources/UI/View/TabView/CoreView.swift @@ -23,7 +23,7 @@ public struct CoreView: View { @Binding var isFistUserPOPUP: Bool @StateObject var authViewModel: AuthorizationViewModel @StateObject var viewModel: CommonViewViewModel - + @StateObject var homeViewModel: HomeViewViewModel = HomeViewViewModel() public init( viewModel: CommonViewViewModel, @@ -107,7 +107,29 @@ public struct CoreView: View { backAction: { appState.isGoToProfileView = false }, - authViewModel: authViewModel) + authViewModel: authViewModel, cardChange: { + viewModel.cards = [] + + DispatchQueue.main.async { + homeViewModel.randomQuoteRequest(userID: authViewModel.userid ) { model in + for quoteContent in model.data?.content ?? [] { + let hashTags = viewModel.getHashtags(post: quoteContent) + self.homeViewModel.selecteLikeYn = quoteContent.likeID != nil + let card = CardInfomation(qouteId: quoteContent.quoteID ?? .zero, + hashtags: hashTags, image: "", + title: quoteContent.content ?? "", + sources: quoteContent.author ?? "", + isBookrmark: quoteContent.likeID != nil, + likeId: quoteContent.likeID + ) + if !viewModel.cards.contains(card) { + viewModel.cards.append(card) + } + } + } + } + + }) .environmentObject(sheetManager) } } diff --git a/PingPong/Projects/Feature/Home/Sources/UI/ViewModel/HomeViewViewModel.swift b/PingPong/Projects/Feature/Home/Sources/UI/ViewModel/HomeViewViewModel.swift index 9d35cce8..b7615402 100644 --- a/PingPong/Projects/Feature/Home/Sources/UI/ViewModel/HomeViewViewModel.swift +++ b/PingPong/Projects/Feature/Home/Sources/UI/ViewModel/HomeViewViewModel.swift @@ -23,6 +23,7 @@ public class HomeViewViewModel: ObservableObject { @State var isOn: [Bool] = [] @Published public var selecteLikeYn: Bool = false @Published public var currentPage = 0 +// @Published public var currentPage = 0 @Published public var homeUserPrefModel: UserPrefModel? public var homeUserPrefCancellable: AnyCancellable? @@ -48,7 +49,7 @@ public class HomeViewViewModel: ObservableObject { } let provider = MoyaProvider(plugins: [MoyaLoggingPlugin()]) - homeRandomQuoteCancellable = provider.requestWithProgressPublisher(.homeRandomQuote(page: currentPage, sizePerPage: 100, userId: (((userID?.isEmpty) == nil) ? "" : userID) ?? "")) + homeRandomQuoteCancellable = provider.requestWithProgressPublisher(.homeRandomQuote(page: 0, sizePerPage: 200, userId: (((userID?.isEmpty) == nil) ? "" : userID) ?? "")) .compactMap { $0.response?.data } .receive(on: DispatchQueue.main) .decode(type: HomeRandomQuoteModel.self, decoder: JSONDecoder()) diff --git a/PingPong/Projects/Feature/Profile/Sources/UI/View/MainView/ProfileView.swift b/PingPong/Projects/Feature/Profile/Sources/UI/View/MainView/ProfileView.swift index 5e0bfa63..34446d3d 100644 --- a/PingPong/Projects/Feature/Profile/Sources/UI/View/MainView/ProfileView.swift +++ b/PingPong/Projects/Feature/Profile/Sources/UI/View/MainView/ProfileView.swift @@ -24,18 +24,21 @@ public struct ProfileView: View { @EnvironmentObject var sheetManager: SheetManager var backAction: () -> Void + var cardChange: () -> Void public init( viewModel: CommonViewViewModel, appState: AppState, backAction: @escaping () -> Void, - authViewModel: AuthorizationViewModel + authViewModel: AuthorizationViewModel, + cardChange: @escaping() -> Void ) { self._appState = StateObject(wrappedValue: appState) self._viewModel = StateObject(wrappedValue: viewModel) self.backAction = backAction self._authViewModel = StateObject(wrappedValue: authViewModel) + self.cardChange = cardChange } @@ -66,7 +69,7 @@ public struct ProfileView: View { Rectangle() .foregroundColor(sheetManager.isPopup ? Color.basicBlackDimmed : .clear) } - .profileModal(with: sheetManager, viewModel: viewModel) + .profileModal(with: sheetManager, viewModel: viewModel, cardChange: cardChange) .ignoresSafeArea() .navigationBarBackButtonHidden() diff --git a/PingPong/Projects/Feature/Profile/Sources/UI/View/ModalModifier/ProfileModalView.swift b/PingPong/Projects/Feature/Profile/Sources/UI/View/ModalModifier/ProfileModalView.swift index cd4e823c..554a9bf3 100644 --- a/PingPong/Projects/Feature/Profile/Sources/UI/View/ModalModifier/ProfileModalView.swift +++ b/PingPong/Projects/Feature/Profile/Sources/UI/View/ModalModifier/ProfileModalView.swift @@ -27,14 +27,16 @@ public struct ProfileModalView: View { let didClose: () -> Void + var cardChange: () -> Void let height:CGFloat = UIScreen.screenHeight == 667 ? UIScreen.screenHeight * 0.8 : UIScreen.screenHeight * 0.7 - public init(viewModel: CommonViewViewModel, config: SheetManager.Config, isPopup: Bool, defaultYoffset: CGFloat, didClose: @escaping () -> Void) { + public init(viewModel: CommonViewViewModel, config: SheetManager.Config, isPopup: Bool, defaultYoffset: CGFloat, didClose: @escaping () -> Void, cardChange: @escaping () -> Void) { self._viewModel = StateObject(wrappedValue: viewModel) self.config = config self.isPopup = isPopup self.didClose = didClose + self.cardChange = cardChange self.defaultYoffset = defaultYoffset } @@ -231,6 +233,7 @@ private extension ProfileModalView { Task { await profileViewModel.profileUserPrefEditPUT(userPrefId: profileViewModel.userPrefId, flavors: flavorStringArray, sources: sourceStringArray) { + cardChange() } } diff --git a/PingPong/Projects/Feature/Profile/Sources/UI/View/ModalModifier/ProfileModalViewModifier.swift b/PingPong/Projects/Feature/Profile/Sources/UI/View/ModalModifier/ProfileModalViewModifier.swift index 09443585..fc4d4033 100644 --- a/PingPong/Projects/Feature/Profile/Sources/UI/View/ModalModifier/ProfileModalViewModifier.swift +++ b/PingPong/Projects/Feature/Profile/Sources/UI/View/ModalModifier/ProfileModalViewModifier.swift @@ -17,14 +17,16 @@ struct ProfileModalViewModifier: ViewModifier { @ObservedObject var sheetManager: SheetManager var backAction: () -> Void + var cardChange: () -> Void // 커스텀 모달 y offset let defaultYoffset: CGFloat = 30 - public init(viewModel: CommonViewViewModel, sheetManager: SheetManager) { + public init(viewModel: CommonViewViewModel, sheetManager: SheetManager, cardChange: @escaping() -> Void) { self._viewModel = StateObject(wrappedValue: viewModel) self._sheetManager = ObservedObject(wrappedValue: sheetManager) self.backAction = sheetManager.dismiss + self.cardChange = cardChange } func body(content: Content) -> some View { @@ -37,10 +39,15 @@ struct ProfileModalViewModifier: ViewModifier { defaultYoffset: defaultYoffset) { withAnimation(.spring()) { +// viewModel.cards = [] sheetManager.dismiss() viewModel.offsetY = defaultYoffset sheetManager.isPopup = false } + } cardChange: { + DispatchQueue.main.asyncAfter(deadline: .now() + 1){ + cardChange() + } } } } @@ -48,7 +55,7 @@ struct ProfileModalViewModifier: ViewModifier { } extension View { - public func profileModal(with sheetManager: SheetManager, viewModel: CommonViewViewModel) -> some View { - self.modifier(ProfileModalViewModifier(viewModel: viewModel, sheetManager: sheetManager)) + public func profileModal(with sheetManager: SheetManager, viewModel: CommonViewViewModel, cardChange: @escaping() -> Void) -> some View { + self.modifier(ProfileModalViewModifier(viewModel: viewModel, sheetManager: sheetManager, cardChange: cardChange)) } }