Skip to content

Commit

Permalink
#296: 마이페이지 필터링 타입 바인딩 및 드랍 시간 표기 작업
Browse files Browse the repository at this point in the history
- 백엔드 작업 후 좋아요한 뮤직 노출 처리 필요
  • Loading branch information
thoonk committed Oct 1, 2024
1 parent 8f71a7f commit 6f164d8
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 24 deletions.
8 changes: 8 additions & 0 deletions StreetDrop/StreetDrop.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
0856525D2B1F29FD00FD9BCB /* ModalOption.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0856525C2B1F29FD00FD9BCB /* ModalOption.swift */; };
08810C2E2BD3FB00004FC6C1 /* LevelPolicyPopUpViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08810C2D2BD3FB00004FC6C1 /* LevelPolicyPopUpViewController.swift */; };
08810C322BD3FC57004FC6C1 /* LevelPolicySubView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08810C312BD3FC57004FC6C1 /* LevelPolicySubView.swift */; };
088F000B2CAACDB100F97992 /* String+ToDate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 088F000A2CAACDB100F97992 /* String+ToDate.swift */; };
088F000D2CAACE0D00F97992 /* Date+TimeAgoDisplay.swift in Sources */ = {isa = PBXBuildFile; fileRef = 088F000C2CAACE0D00F97992 /* Date+TimeAgoDisplay.swift */; };
08B97EA52B44303C00084F66 /* UniviersialLinkKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08B97EA42B44303C00084F66 /* UniviersialLinkKey.swift */; };
08BE57162BD4C887007EA949 /* UILabel+applyGradient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08BE57152BD4C887007EA949 /* UILabel+applyGradient.swift */; };
08F574512C4696AC00635B54 /* FetchingMyDropListUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08F574502C4696AC00635B54 /* FetchingMyDropListUseCase.swift */; };
Expand Down Expand Up @@ -333,6 +335,8 @@
0856525C2B1F29FD00FD9BCB /* ModalOption.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModalOption.swift; sourceTree = "<group>"; };
08810C2D2BD3FB00004FC6C1 /* LevelPolicyPopUpViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LevelPolicyPopUpViewController.swift; sourceTree = "<group>"; };
08810C312BD3FC57004FC6C1 /* LevelPolicySubView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LevelPolicySubView.swift; sourceTree = "<group>"; };
088F000A2CAACDB100F97992 /* String+ToDate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+ToDate.swift"; sourceTree = "<group>"; };
088F000C2CAACE0D00F97992 /* Date+TimeAgoDisplay.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+TimeAgoDisplay.swift"; sourceTree = "<group>"; };
08B97EA42B44303C00084F66 /* UniviersialLinkKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UniviersialLinkKey.swift; sourceTree = "<group>"; };
08BE57152BD4C887007EA949 /* UILabel+applyGradient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UILabel+applyGradient.swift"; sourceTree = "<group>"; };
08F574502C4696AC00635B54 /* FetchingMyDropListUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FetchingMyDropListUseCase.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1692,6 +1696,8 @@
F4AA84DE2C1F3B0200CADB1A /* Array+Extension.swift */,
6A51EC3B2C3E52FE00DEF6F3 /* UIViewController+Rx.swift */,
6A51EC3D2C3E536000DEF6F3 /* Map+Rx.swift */,
088F000A2CAACDB100F97992 /* String+ToDate.swift */,
088F000C2CAACE0D00F97992 /* Date+TimeAgoDisplay.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -2062,6 +2068,7 @@
41A3DDF12A593ED4004CFA2F /* AlertViewController.swift in Sources */,
C47F02222A38633500F48884 /* SettingsViewController.swift in Sources */,
C44A54982BBC08D200354F8F /* DefaultPopUpRepository.swift in Sources */,
088F000D2CAACE0D00F97992 /* Date+TimeAgoDisplay.swift in Sources */,
C434A4DC2A19CA6F00C63526 /* SearchingMusicTableViewCell.swift in Sources */,
18D671F62A35C5D4003B1A71 /* UIImage+Resizing.swift in Sources */,
C4E4C6B42A5ADC4B00B1C84A /* DefaultSettingsRepository.swift in Sources */,
Expand Down Expand Up @@ -2196,6 +2203,7 @@
C419724E2ABDCABD00211222 /* DefaultBlockUserUseCase.swift in Sources */,
1876F0412A66E5440064B887 /* MyLevelResponseDTO+Mapping.swift in Sources */,
C4685B3D2B7261A000F514C7 /* SplashViewModel.swift in Sources */,
088F000B2CAACDB100F97992 /* String+ToDate.swift in Sources */,
F4AA84DF2C1F3B0200CADB1A /* Array+Extension.swift in Sources */,
082F17062AB6DFEC00174D98 /* DropMusicUseCase.swift in Sources */,
18683FD92A2A251E005A94AC /* ViewModel.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ final class MusicListCell: UITableViewCell {
self.locationLabel.text = item.location
self.likeLabel.text = String(item.likeCount)
self.userNameLabel.text = item.userName

if let createdDate = item.createdAt.toDate() {
let timeAgoText: String = Date().timeAgoDisplay(from: createdDate)
self.timeAgoLabel.text = timeAgoText
}
/*
TODO:
- 백엔드 개발 완료 후 내가 좋아요한 뮤직 노출 처리
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class MyPageViewController: UIViewController, Toastable, Alertable {
private let selectedMusicEvent = PublishRelay<Int>()
private let disposeBag = DisposeBag()
private let totalMusicsCountRelay: ReplayRelay<Int> = .create(bufferSize: 1)
private let selectedFilterType: BehaviorRelay<FilterType> = .init(value: .newest)
private let selectedFilterTypeEvent: BehaviorRelay<FilterType> = .init(value: .newest)

// MARK: - Init

Expand Down Expand Up @@ -454,7 +454,7 @@ private extension MyPageViewController {

func bindFilterButtonAction(in musicListFilterView: MusicListFilterView) {
musicListFilterView.rx.onSortFilterTap
.withLatestFrom(selectedFilterType)
.withLatestFrom(selectedFilterTypeEvent)
.bind(with: self) { owner, type in
owner.showFilteringOptionsModal(with: type)
}
Expand All @@ -466,7 +466,7 @@ private extension MyPageViewController {
}
.disposed(by: disposeBag)

selectedFilterType
selectedFilterTypeEvent
.bind(to: musicListFilterView.rx.setSortButtonText)
.disposed(by: disposeBag)
}
Expand Down Expand Up @@ -532,7 +532,8 @@ private extension MyPageViewController {
viewWillAppearEvent: viewWillAppearEvent.asObservable(),
listTypeTapEvent: listTypeTapEvent.asObservable(),
levelPolicyTapEvent: levelPolicyTapEvent.asObservable(),
selectedMusicEvent: selectedMusicEvent.asObservable()
selectedMusicEvent: selectedMusicEvent.asObservable(),
selectedFilterTypeEvent: selectedFilterTypeEvent.asObservable()
)

let output = viewModel.convert(input: input, disposedBag: disposeBag)
Expand Down Expand Up @@ -731,13 +732,8 @@ private extension MyPageViewController {

func filterMusicList(by type: FilterType) -> UIAction {
return UIAction { [weak self] _ in
self?.selectedFilterType.accept(type)
self?.selectedFilterTypeEvent.accept(type)
self?.navigationController?.dismiss(animated: true)

/*
TODO:
- API 개발후 작업 예정
*/
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ extension MyPageViewModel: ViewModel {
let listTypeTapEvent: Observable<MyMusicType>
let levelPolicyTapEvent: Observable<Void>
let selectedMusicEvent: Observable<Int>
let selectedFilterTypeEvent: Observable<FilterType>
}

struct Output {
Expand Down Expand Up @@ -78,18 +79,30 @@ extension MyPageViewModel: ViewModel {
.bind(to: lastestListType)
.disposed(by: disposedBag)

lastestListType
.bind(with: self) { owner, type in
owner.myMusicType = type

switch type {
case .drop:
owner.fetchMyDropMusicsSections(output: output, disposedBag: disposedBag)
case .like:
owner.fetchMyLikeMusicsSections(output: output, disposedBag: disposedBag)
}
Observable.combineLatest(
lastestListType,
input.selectedFilterTypeEvent
)
.bind(with: self) { owner, types in
let (myMusicType, selectedFilterType) = types
owner.myMusicType = myMusicType

switch myMusicType {
case .drop:
owner.fetchMyDropMusicsSections(
filterType: selectedFilterType,
output: output,
disposedBag: disposedBag
)
case .like:
owner.fetchMyLikeMusicsSections(
filterType: selectedFilterType,
output: output,
disposedBag: disposedBag
)
}
.disposed(by: disposedBag)
}
.disposed(by: disposedBag)

input.levelPolicyTapEvent
.bind(with: self) { owner, _ in
Expand Down Expand Up @@ -154,10 +167,11 @@ private extension MyPageViewModel {
}

func fetchMyDropMusicsSections(
filterType: FilterType,
output: Output,
disposedBag: DisposeBag
) {
fetchingMyDropListUseCase.fetchMyDropList()
fetchingMyDropListUseCase.fetchMyDropList(filterType: filterType)
.subscribe(with: self, onSuccess: { owner, totalMusics in
output.totalMusicsCount.accept(totalMusics.totalCount)
let myMusicsSections = owner.convertToSectionTypes(from: totalMusics)
Expand All @@ -169,8 +183,12 @@ private extension MyPageViewModel {
.disposed(by: disposedBag)
}

func fetchMyLikeMusicsSections(output: Output, disposedBag: DisposeBag) {
fetchingMyLikeListUseCase.fetchMyLikeList()
func fetchMyLikeMusicsSections(
filterType: FilterType,
output: Output,
disposedBag: DisposeBag
) {
fetchingMyLikeListUseCase.fetchMyLikeList(filterType: filterType)
.subscribe(with: self, onSuccess: { owner, totalMusics in
output.totalMusicsCount.accept(totalMusics.totalCount)
let myMusicsSections = owner.convertToSectionTypes(from: totalMusics)
Expand Down
46 changes: 46 additions & 0 deletions StreetDrop/StreetDrop/Util/Extensions/Date+TimeAgoDisplay.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// Date+TimeAgoDisplay.swift
// StreetDrop
//
// Created by thoonk on 9/30/24.
//

import Foundation

extension Date {
func timeAgoDisplay(from date: Date) -> String {
let calendar = Calendar.current
let components = calendar.dateComponents([
.year,
.month,
.weekOfYear,
.day,
.hour,
.minute,
.second
], from: date, to: self)

if let years = components.year, years > 0 {
return "\(years)년 전"
}
if let months = components.month, months > 0 {
return "\(months)달 전"
}
if let weeks = components.weekOfYear, weeks > 0 {
return "\(weeks)주 전"
}
if let days = components.day, days > 0 {
return "\(days)일 전"
}
if let hours = components.hour, hours > 0 {
return "\(hours)시간 전"
}
if let minutes = components.minute, minutes > 0 {
return "\(minutes)분 전"
}
if let seconds = components.second, seconds > 0 {
return "\(seconds)초 전"
}
return "1초 전"
}
}
20 changes: 20 additions & 0 deletions StreetDrop/StreetDrop/Util/Extensions/String+ToDate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// String+ToDate.swift
// StreetDrop
//
// Created by thoonk on 9/30/24.
//

import Foundation

extension String {
func toDate(
format: String = "yyyy-MM-dd HH:mm:ss",
timeZone: TimeZone? = TimeZone(identifier: "Asia/Seoul")
) -> Date? {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = format
dateFormatter.timeZone = timeZone
return dateFormatter.date(from: self)
}
}

0 comments on commit 6f164d8

Please sign in to comment.