Skip to content

Commit

Permalink
Merge pull request #79 from mash-up-kr/feature/#78-recommend-tab-fix
Browse files Browse the repository at this point in the history
Feat : 둘러보기 디자인 수정
  • Loading branch information
jongnan authored Oct 3, 2024
2 parents 6c3c73b + ad85fe9 commit 26670fc
Show file tree
Hide file tree
Showing 23 changed files with 285 additions and 231 deletions.
2 changes: 1 addition & 1 deletion Projects/Core/DesignSystem/Sources/MainTab/MainTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public enum MainTab: String, CaseIterable, Identifiable {
public var title: String {
switch self {
case .recommend:
return "추천"
return "둘러보기"
case .search:
return "검색"
case .mypage:
Expand Down
2 changes: 2 additions & 0 deletions Projects/Core/DesignSystem/Sources/View/CircleButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ public struct CircleButton: View {
.overlay {
self.image
.resizable()
.animation(nil)
.scaledToFill()
.frame(width: 20, height: 20, alignment: .center)
}
.frame(width: self.width, height: self.height,alignment: .center)
.shadow(color: shadowColor, radius: 20)
}
.buttonStyle(PlainButtonStyle())
}
}

Expand Down
12 changes: 2 additions & 10 deletions Projects/Core/PPACData/Sources/DTO/MemeReactionRequestDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,12 @@
// MemeReactionRequestDTO.swift
// PPACData
//
// Created by kimchansoo on 10/1/24.
// Created by 김종윤 on 9/28/24.
//

import Foundation

public struct MemeReactionRequestDTO: Codable {
public let count: Int

public init(count: Int) {
self.count = count
}
}

public struct MemeReactionResponseDTO: Codable {
struct MemeReactionRequestDTO: Encodable {
public let count: Int

public init(count: Int) {
Expand Down
16 changes: 16 additions & 0 deletions Projects/Core/PPACData/Sources/DTO/MemeReactionResponseDTO.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// MemeReactionResponseDTO.swift
// PPACData
//
// Created by 김종윤 on 9/28/24.
//

import Foundation

struct MemeReactionResponseDTO: Decodable {
public let count: Int

public init(count: Int) {
self.count = count
}
}
4 changes: 2 additions & 2 deletions Projects/Core/PPACData/Sources/Endpoint/MemeEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public enum MemeEndpoint: Requestable {
case .watch(let memeId, let type):
return "/meme/\(memeId)/watch/\(type)"
case .reaction(let memeId, _):
return "meme/\(memeId)/reaction"
return "/meme/\(memeId)/reaction"
}
}

Expand All @@ -85,7 +85,7 @@ public enum MemeEndpoint: Requestable {
return nil
case .watch:
return nil
case let .reaction(memeId, count):
case .reaction(_, let count):
return .body(MemeReactionRequestDTO(count: count))
case .meme(memeId: _):
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ public protocol MemeRepository {
func shareMeme(memeId: String) async throws
func watchMeme(memeId: String, type: String) async throws
func reactToMeme(memeId: String, count: Int) async throws -> Int

func registerMeme(formData: FormData, title: String, source: String, keywordIds: [String]) async throws
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ public protocol ReactToMemeUseCase {
}

public class ReactToMemeUseCaseImpl: ReactToMemeUseCase {
private let repository: MemeRepository

public init(repository: MemeRepository) {
self.repository = repository
}

public func execute(memeId: String, count: Int) async throws -> Int {
try await repository.reactToMeme(memeId: memeId, count: count)
}
private let repository: MemeRepository
public init(repository: MemeRepository) {
self.repository = repository
}
public func execute(memeId: String, count: Int) async throws -> Int {
return try await repository.reactToMeme(memeId: memeId, count: count)
}
}
2 changes: 1 addition & 1 deletion Projects/Core/PPACNetwork/Sources/Requestable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public protocol Requestable {
extension Requestable {

private var baseUrl: String {
return "http://ppac-server.run.goorm.io/api/" // 개발 서버
return "http://ppac-server.run.goorm.io/api" // 개발 서버
//return "https://ppac-server-goorm.run.goorm.site/api" // 운영 서버
}

Expand Down
38 changes: 38 additions & 0 deletions Projects/Core/PPACUtil/Sources/Throttler.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// Throttler.swift
// PPACUtil
//
// Created by 김종윤 on 9/25/24.
//

import Foundation

public class Throttler {
private var workItem: DispatchWorkItem?
private var lastExecution: Date?
private let queue: DispatchQueue
private let interval: TimeInterval

public init(seconds: TimeInterval, queue: DispatchQueue = DispatchQueue.main) {
self.interval = seconds
self.queue = queue
}

public func throttle(action: @escaping () -> Void) {
// 기존의 예약된 작업이 있으면 취소
workItem?.cancel()

// 새로운 작업 생성
workItem = DispatchWorkItem { [weak self] in
self?.lastExecution = Date()
action()
}

// 인터벌 후에 작업을 실행하도록 예약 (즉시 실행하지 않음)
queue.asyncAfter(deadline: .now() + interval, execute: workItem!)
}

public func cancel() {
workItem?.cancel()
}
}
6 changes: 5 additions & 1 deletion Projects/DemoApp/Sources/DemoApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ private extension DemoApp.Views {
router: nil,
searchKeywordUseCase: SearchKeywordUseCaseImpl(
repository: MemeRepositoryImpl(networkservice: NetworkService())
), copyImageUseCase: CopyImageUseCaseImpl()
),
copyImageUseCase: CopyImageUseCaseImpl(),
watchMemeUseCase: WatchMemeUseCaseImpl(
repository: MemeRepositoryImpl(networkservice: NetworkService())
)
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,101 +10,77 @@ import SkeletonUI

import ResourceKit

import Lottie

struct RecommendHeaderView: View {

@Binding var userLevel: Int
@Binding var seenMemeCount: Int
@Binding var recommendMemeSize: Int
let isLoad: Bool
let uploadButtonTap: () -> Void

public var body: some View {
let isNotLoading = userLevel == 0 || seenMemeCount == 0

VStack(spacing: 0) {
ResourceKitAsset.Icon.homeLogo.swiftUIImage
.resizable()
.frame(width: 212, height: 45, alignment: .center)
.padding(.bottom, 10)
.frame(width: 106, height: 32, alignment: .center)
.padding(.bottom, 12)

recommendTitle

if !isNotLoading {
recommendProgressBar(
seenMemeCount: self.seenMemeCount,
total: recommendMemeSize
)

recommendText(getRecommendText())
if isLoad {
memeUploadButton(uploadButtonTap)
.padding(.top, 20)
.padding(.bottom, 28)
} else {
EmptyView()
.recommendSkeleton(isShow: isNotLoading, radius: 4, width: 200, height: 16)
.recommendSkeleton(isShow: !isLoad, radius: 4, width: 130, height: 36)
.padding(.top, 20)
.padding(.bottom, 37)
.padding(.bottom, 28)
}
}
}

private func getRecommendText() -> String {
return if userLevel == 0 || seenMemeCount == 0 {
"확인한 밈을 불러오지 못 했어요. 새로고침 해주세요"
} else if userLevel == 1 &&
(1...(recommendMemeSize - 1)).contains(seenMemeCount)
{
"밈 보고 레벨 포인트 받아요!"
} else if userLevel == 2 &&
(1...(recommendMemeSize - 1)).contains(seenMemeCount)
{
"추천 밈 둘러보세요!"
} else {
"완밈! 다음 주 밈도 기대해 주세요"
}
}
}

private var recommendTitle : some View {
Text("이번 주 이 밈 어때!")
.font(Font.Heading.Large.semiBold)
.padding(.bottom, 16)
}

private func recommendProgressBar(
seenMemeCount: Int,
total: Int
) -> some View {
HStack(spacing: 0) {
ResourceKitAsset.Icon.squareCheck.swiftUIImage
VStack(spacing: 0) {
Text("NEW! 따끈따끈한 밈")
.font(Font.Heading.Large.semiBold)
.padding(.bottom, 4)

ProgressView(
value: Double(seenMemeCount),
total: Double(total)
)
.frame(width: 125, height: 8)
.tint(Color.Icon.brand)
.padding(.vertical, 4)
.padding(.horizontal, 8)

Text("\(seenMemeCount == 0 ? "?" : "\(seenMemeCount)")개 봤어요")
.font(Font.Body.Small.semiBold)
.foregroundColor(Color.Text.brand)
Text("최근에 사람들이 올린 밈 구경하세요.")
.font(Font.Body.Medium.medium)
.foregroundStyle(Color.Text.secondary)
}
}

private func recommendText(_ text: String) -> some View {
Text(text)
.font(Font.Body.Medium.medium)
.foregroundStyle(Color.Text.secondary)
.padding(.top, 8)
.padding(.bottom, 32)
private func memeUploadButton(
_ uploadButtonTap: @escaping () -> Void
) -> some View {
@State var playbackMode: LottiePlaybackMode = .paused(at: .progress(100))

return Button(
action: {
uploadButtonTap()
},
label: {
LottieView(
animation: AnimationAsset.uploadLottie.animation
)
.looping()
}
)
.buttonStyle(PlainButtonStyle())
.frame(width: 130, height: 36)
.contentShape(RoundedRectangle(cornerRadius: 10))
}


#Preview {
@State var userLevel: Int = 0
@State var seenMemeCount: Int = 5
@State var recommendMemeSize: Int = 5

return RecommendHeaderView(
userLevel: $userLevel,
seenMemeCount: $seenMemeCount,
recommendMemeSize: $recommendMemeSize
isLoad: true,
uploadButtonTap: {
print("Upload Button Tap!")
}
)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(
Expand Down
Loading

0 comments on commit 26670fc

Please sign in to comment.