Skip to content

Commit

Permalink
Merge pull request #91 from mash-up-kr/feature/#90
Browse files Browse the repository at this point in the history
fix: 리젝 대응
  • Loading branch information
lina0322 authored Oct 4, 2024
2 parents c63ca37 + 5edee4e commit 6f38491
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public struct MemeCategoryView: View {
}

public var body: some View {
VStack(spacing: 0) {
VStack(alignment: .leading, spacing: 0) {
HStack {
Text(category)
.font(Font.Body.Small.semiBold)
Expand Down
2 changes: 1 addition & 1 deletion Projects/Core/PPACData/Sources/Endpoint/MemeEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public enum MemeEndpoint: Requestable {
return "/meme/recommend-memes"
case .getSearchKeywordMemeList(_,_,let keyword):
return "/meme/search/\(keyword)"
case .getSearchByTextMemeList(_,_,let text):
case .getSearchByTextMemeList(_,_,_):
return "/meme/search"
case .meme(let memeId):
return "/meme/\(memeId)"
Expand Down
63 changes: 46 additions & 17 deletions Projects/Features/MemeDetail/Sources/MemeDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ public struct MemeDetailView: View {
@State private var totalHeight: CGFloat = 0
@State private var memeCardHeight: CGFloat = 0
@State private var tabBarHeight: CGFloat = 0

@State private var isSheetPresented: Bool = false
@State private var isWebViewPresented: Bool = false
@State private var showContactUsAlert: Bool = false

private var isShortCard: Bool {
memeCardHeight + tabBarHeight > totalHeight - 30
}
Expand All @@ -43,19 +46,42 @@ public struct MemeDetailView: View {
public var body: some View {
ZStack {
memeDetailCardView
if viewModel.state.isSheetPresented {
.sheet(isPresented: $isSheetPresented) {
bottomSheetView
.presentationDetents([.height(66+40)])
}

if isSheetPresented {
Color.black.opacity(0.4)
.ignoresSafeArea([.container])
}
}
.onAppear {
viewModel.logMemeDetail(interaction: .view, event: .meme)
}
.plainNavigationBar(
backHandler: { viewModel.dispatch(type: .naviBackButtonTapped) },
rightActionHandler: { viewModel.dispatch(type: .naviMoreButtonTapped) },
rightActionHandler: { isSheetPresented = true },
hasConfigureButton: true,
title: viewModel.state.meme.title
)
.sheet(isPresented: $isWebViewPresented, onDismiss: { isWebViewPresented = false }) {
WebView(url: viewModel.state.reportProblemUrl)
.presentationDetents([.large])
}
.basicModal(
isPresented: $showContactUsAlert,
opacity: 0.5,
content: {
FarmemeAlertView(
title: "문의하기",
description: "[email protected]",
dismiss: {
showContactUsAlert = false
}
)
}
)
.popup(
isActive: $viewModel.state.isCopied,
image: ResourceKitAsset.Icon.copyFilled.swiftUIImage,
Expand All @@ -66,16 +92,6 @@ public struct MemeDetailView: View {
image: viewModel.state.meme.isFarmemed ? ResourceKitAsset.Icon.copyFilled.swiftUIImage : nil,
text: viewModel.state.meme.isFarmemed ? "파밈 완료!" : "파밈을 취소했어요"
)
.sheet(isPresented: $viewModel.state.isSheetPresented) {
ZStack(alignment: .bottom) {
bottomSheetView
.presentationDetents([.height(66)])
}
}
.sheet(isPresented: $viewModel.state.isWebViewPresented) {
WebView(url: viewModel.state.reportProblemUrl)
.presentationDetents([.large])
}
}

private var memeDetailCardView: some View {
Expand Down Expand Up @@ -153,11 +169,18 @@ public struct MemeDetailView: View {
.frame(height: 16)
.foregroundStyle(Color.Background.white)
reportProblembutton
.onTapGesture {
isSheetPresented = false
isWebViewPresented = true
}
contactUsButton
.onTapGesture {
isSheetPresented = false
isWebViewPresented = false // 신고하기 후에 누르면, 신고하기가 떠서 강제로 막음
showContactUsAlert = true
}
}
.padding(.bottom, 10)
.onTapGesture {
viewModel.dispatch(type: .reportProblemButtonTapped)
}
}

private var reportProblembutton: some View {
Expand All @@ -167,6 +190,13 @@ public struct MemeDetailView: View {
.padding(.vertical, 16)
}

private var contactUsButton: some View {
Text("문의하기")
.font(Font.Body.Xlarge.medium)
.foregroundStyle(Color.Text.primary)
.padding(.vertical, 16)
}

@MainActor
private func tabBarTap(_ type: MemeDetailTab) {
switch type {
Expand All @@ -178,7 +208,6 @@ public struct MemeDetailView: View {
viewModel.dispatch(type: .shreButtonTapped)
}
}

}

#Preview {
Expand Down
81 changes: 34 additions & 47 deletions Projects/Features/MemeDetail/Sources/MemeDetailViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,12 @@ public final class MemeDetailViewModel: ViewModelType, ObservableObject {
case shreButtonTapped
case farmemeButtonTapped
case naviBackButtonTapped
case naviMoreButtonTapped
case reportProblemButtonTapped
}

public struct State {
var meme: MemeDetail
var isCopied: Bool = false
var isFarmemeChanged: Bool = false
var isSheetPresented: Bool = false
var isWebViewPresented: Bool = false

let reportProblemUrl: URL? = URL(string: "https://forms.gle/a5QkMnLD8AANtYCo7")
}

Expand All @@ -57,8 +52,6 @@ public final class MemeDetailViewModel: ViewModelType, ObservableObject {
private var reactionTask: Task<Void, Never>?

private let trotller = Throttler(seconds: 3)



// MARK: - Initializers

Expand All @@ -70,7 +63,7 @@ public final class MemeDetailViewModel: ViewModelType, ObservableObject {
watchMemeUseCase: WatchMemeUseCase,
reactToMemeUseCase: ReactToMemeUseCase
) {
print("memeviewmodel init")
debugPrint("memeviewmodel init")
self.router = router
self.state = State(meme: meme)
self.bookmarkMemeUseCase = bookmarkMemeUseCase
Expand All @@ -80,18 +73,18 @@ public final class MemeDetailViewModel: ViewModelType, ObservableObject {
}

deinit {
print("memeviewmodel deinit")
reactionTask?.cancel()
debugPrint("memeviewmodel deinit")
reactionTask?.cancel()
}

// MARK: - Methods

public func dispatch(type: Action) {
Task { @MainActor in
print("type: \(type)")
debugPrint("type: \(type)")
switch type {
case .likeButtonTapped:
await postReaction()
postReaction()
case .copyButtonTapped:
await copyImage()
case .shreButtonTapped:
Expand All @@ -103,13 +96,8 @@ public final class MemeDetailViewModel: ViewModelType, ObservableObject {
await postSavedFarmeme()
}
case .naviBackButtonTapped:
await sendReactions()
router?.popView()
case .naviMoreButtonTapped:
state.isSheetPresented = true
case .reportProblemButtonTapped:
state.isSheetPresented = false
state.isWebViewPresented = true
print("reportProblemButtonTapped")
}
}
}
Expand All @@ -130,37 +118,36 @@ public final class MemeDetailViewModel: ViewModelType, ObservableObject {
}

private extension MemeDetailViewModel {

@MainActor
func postReaction() {
reactionCount += 1
self.state.meme.reaction += 1
self.state.meme.isReaction = true
self.logMemeDetail(event: .reaction)
reactionCount += 1
self.state.meme.reaction += 1
self.state.meme.isReaction = true
self.logMemeDetail(event: .reaction)

trotller.throttle {
await self.sendReactions()
}
trotller.throttle {
await self.sendReactions()
}
}



@MainActor
func sendReactions() async {
let count = reactionCount
guard count > 0 else {
// 전송할 리액션이 없음
return
}
reactionCount = 0
do {
let count = try await reactToMemeUseCase.execute(memeId: state.meme.id, count: count)
print("currentMeme count: \(self.state.meme.reaction)")
print("new count: \(count)")
self.state.meme.reaction = count
print("Reactions sent successfully with count: \(count)")
} catch {
print("Failed to send reactions: \(error)")
}
let count = reactionCount
guard count > 0 else {
// 전송할 리액션이 없음
return
}
reactionCount = 0
do {
let count = try await reactToMemeUseCase.execute(memeId: state.meme.id, count: count)
debugPrint("currentMeme count: \(self.state.meme.reaction)")
debugPrint("new count: \(count)")
self.state.meme.reaction = count
debugPrint("Reactions sent successfully with count: \(count)")
} catch {
debugPrint("Failed to send reactions: \(error)")
}
}

@MainActor
Expand All @@ -177,7 +164,7 @@ private extension MemeDetailViewModel {
state.isCopied = true
self.logMemeDetail(event: .copy)
} catch {
print("Failed to load image data: \(error)")
debugPrint("Failed to load image data: \(error)")
}
}

Expand All @@ -192,7 +179,7 @@ private extension MemeDetailViewModel {
self.logMemeDetail(event: .save)
} catch {
// TODO: - 에러처리
print(error)
debugPrint(error)
}
}

Expand All @@ -207,7 +194,7 @@ private extension MemeDetailViewModel {
self.logMemeDetail(event: .saveCancel)
} catch {
// TODO: - 에러처리
print(error)
debugPrint(error)
}
}

Expand All @@ -220,7 +207,7 @@ private extension MemeDetailViewModel {
self.logMemeDetail(event: .share)
} catch {
// TODO: - 에러처리
print(error)
debugPrint(error)
}
}
}
1 change: 1 addition & 0 deletions Projects/Features/MemeEditor/Sources/MemeEditorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ struct MemeEditorView: View {
keywordTags: keywordTags
) { keyword in
viewModel.dispatch(type: .memeKeywordTapped(keyword: keyword))
endTextEditing()
}
}
.id(viewModel.state.memeCategories.count)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import PPACNetwork

import DesignSystem



public struct RecommendView: View {

@ObservedObject private var viewModel: RecommendViewModel
Expand Down Expand Up @@ -71,6 +69,11 @@ public struct RecommendView: View {
.onReadSize { size in
memeImageHeight = size.height
}
.onTapGesture {
if let currentMeme {
viewModel.router?.showMemeDetailView(meme: currentMeme)
}
}

Spacer()
}
Expand Down Expand Up @@ -126,6 +129,9 @@ public struct RecommendView: View {
)
)
.edgesIgnoringSafeArea(.bottom)
.onAppear {
viewModel.dispatch(type: .viewInitialized)
}
.onChange(of: viewModel.state.isSuccessFetch) {
withAnimation(.spring()) {
currentOffsetY = viewModel.state.isSuccessFetch ? .zero : 20
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private extension RecommendViewModel {
@MainActor
func getRecommendAndUser() async {
do {
let recommendMemeSize = 5
let recommendMemeSize = 20
let recommendMemes = try await getRecommendMemesUseCase.execute(size: recommendMemeSize)
let user = try await getUserInfoUseCase.execute()
print("👍memeids: \(recommendMemes.map { $0.id })")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public final class SearchResultRouter: Router, SearchResultRouting {
text: text,
router: self,
searchKeywordUseCase: SearchKeywordUseCaseImpl(repository: repository),
searchByTextUseCase: SearchByTextUseCaseImpl(repository: repository),
searchByTextUseCase: SearchByTextUseCaseImpl(repository: repository),
getMemeDetailUseCase: GetMemeDetailUseCaseImpl(repository: repository),
copyImageUseCase: CopyImageUseCaseImpl(),
watchMemeUseCase: WatchMemeUseCaseImpl(repository: repository)
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public struct SearchResultView: View {
}
}
}
.refreshable {
viewModel.dispatch(type: .refresh)
}
}
.onAppear {
viewModel.dispatch(type: .viewWillAppear)
Expand Down
Loading

0 comments on commit 6f38491

Please sign in to comment.