Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] #223 - Home 최근 저장한 링크 #225

Merged
merged 15 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions TOASTER-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,9 @@
83CFC3372B564F1100A2EB2B /* WeeklyLinkModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83CFC3362B564F1100A2EB2B /* WeeklyLinkModel.swift */; };
83CFC3392B568BE700A2EB2B /* RecommendSiteModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83CFC3382B568BE700A2EB2B /* RecommendSiteModel.swift */; };
83CFC33B2B57324700A2EB2B /* SaveLinkModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83CFC33A2B57324700A2EB2B /* SaveLinkModel.swift */; };
83D80DCC2CC1059000DD5410 /* RecentLinkModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83D80DCB2CC1059000DD5410 /* RecentLinkModel.swift */; };
83D80DD02CC10D8C00DD5410 /* GetRecentLinkResponseDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83D80DCF2CC10D8C00DD5410 /* GetRecentLinkResponseDTO.swift */; };
83D80DD12CC1113E00DD5410 /* GetRecentLinkResponseDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83D80DCF2CC10D8C00DD5410 /* GetRecentLinkResponseDTO.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -510,6 +513,8 @@
83CFC3362B564F1100A2EB2B /* WeeklyLinkModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeeklyLinkModel.swift; sourceTree = "<group>"; };
83CFC3382B568BE700A2EB2B /* RecommendSiteModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecommendSiteModel.swift; sourceTree = "<group>"; };
83CFC33A2B57324700A2EB2B /* SaveLinkModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SaveLinkModel.swift; sourceTree = "<group>"; };
83D80DCB2CC1059000DD5410 /* RecentLinkModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecentLinkModel.swift; sourceTree = "<group>"; };
83D80DCF2CC10D8C00DD5410 /* GetRecentLinkResponseDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetRecentLinkResponseDTO.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -1436,6 +1441,7 @@
6BE6DA872B546B24008B06FA /* PatchOpenLinkResponseDTO.swift */,
6BE6DA8B2B546CA9008B06FA /* GetWeeksLinkResponseDTO.swift */,
8364220B2BE7BFB2005C4085 /* PatchEditLinkTitleResponseDTO.swift */,
83D80DCF2CC10D8C00DD5410 /* GetRecentLinkResponseDTO.swift */,
);
path = Response;
sourceTree = "<group>";
Expand Down Expand Up @@ -1545,6 +1551,7 @@
83CFC3362B564F1100A2EB2B /* WeeklyLinkModel.swift */,
83CFC3382B568BE700A2EB2B /* RecommendSiteModel.swift */,
396DCE022CA26C6600FEF7C8 /* PopupInfoModel.swift */,
83D80DCB2CC1059000DD5410 /* RecentLinkModel.swift */,
);
path = Model;
sourceTree = "<group>";
Expand Down Expand Up @@ -1889,6 +1896,7 @@
3F3ED27C2BA1A29F004E79F0 /* BaseAPIService.swift in Sources */,
3F3ED2B32BA1D59D004E79F0 /* ClipListCollectionViewCell.swift in Sources */,
3F3ED2B72BA1D897004E79F0 /* SearchResultModel.swift in Sources */,
83D80DD12CC1113E00DD5410 /* GetRecentLinkResponseDTO.swift in Sources */,
3F3ED2812BA1A3F5004E79F0 /* ClipAPIService.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -1901,6 +1909,7 @@
6BE6DAA42B547579008B06FA /* GetDetailTimerResponseDTO.swift in Sources */,
6BE6D9E22B4E9B58008B06FA /* CompleteTimerCollectionViewCell.swift in Sources */,
8334CFA02CA6E2D200319922 /* ViewModelType.swift in Sources */,
83D80DD02CC10D8C00DD5410 /* GetRecentLinkResponseDTO.swift in Sources */,
3F2FA1792B45C46F00EDBF95 /* KakaoAuthenticateAdapter.swift in Sources */,
6BE6DA342B50594B008B06FA /* MoyaPlugin.swift in Sources */,
396DCDFA2CA19F2000FEF7C8 /* PopupTargetType.swift in Sources */,
Expand Down Expand Up @@ -2021,6 +2030,7 @@
391908422B56CFE4006F978A /* PatchEditPriorityCategoryRequestDTO.swift in Sources */,
6BE6DA732B50C33A008B06FA /* GetAllCategoryResponseDTO.swift in Sources */,
3F2FA1752B45C0AF00EDBF95 /* Config.swift in Sources */,
83D80DCC2CC1059000DD5410 /* RecentLinkModel.swift in Sources */,
6B6AE6AC2B3FF6F7000E2366 /* UIColor+.swift in Sources */,
6BC493682B45D7B100544249 /* ToasterNavigationController.swift in Sources */,
6BE6DA492B50ADC2008B06FA /* NetworkService.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// GetRecentLinkResponseDTO.swift
// TOASTER-iOS
//
// Created by Gahyun Kim on 10/17/24.
//

import Foundation

struct GetRecentLinkResponseDTO: Codable {
let code: Int
let message: String
let data: [GetRecentLinkResponseData]
}

struct GetRecentLinkResponseData: Codable {
let toastId: Int
let toastTitle: String
let linkUrl: String
let isRead: Bool
let categoryTitle: String?
let thumbnailUrl: String?
}
17 changes: 17 additions & 0 deletions TOASTER-iOS/Network/Toaster/ToasterAPIService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ protocol ToasterAPIServiceProtocol {
func getWeeksLink(completion: @escaping (NetworkResult<GetWeeksLinkResponseDTO>) -> Void)
func patchEditLinkTitle(requestBody: PatchEditLinkTitleRequestDTO,
completion: @escaping (NetworkResult<PatchEditLinkTitleResponseDTO>) -> Void)
func getRecentLink(completion: @escaping (NetworkResult<GetRecentLinkResponseDTO>) -> Void)
}

final class ToasterAPIService: BaseAPIService, ToasterAPIServiceProtocol {
Expand Down Expand Up @@ -108,4 +109,20 @@ final class ToasterAPIService: BaseAPIService, ToasterAPIServiceProtocol {
}
}
}

func getRecentLink(completion: @escaping (NetworkResult<GetRecentLinkResponseDTO>) -> Void) {
provider.request(.getRecentLink) { result in
switch result {
case .success(let response):
let networkResult: NetworkResult<GetRecentLinkResponseDTO> = self.fetchNetworkResult(statusCode: response.statusCode, data: response.data)
print(networkResult.stateDescription)
completion(networkResult)
case .failure(let error):
if let response = error.response {
let networkResult: NetworkResult<GetRecentLinkResponseDTO> = self.fetchNetworkResult(statusCode: response.statusCode, data: response.data)
completion(networkResult)
}
}
}
}
}
3 changes: 3 additions & 0 deletions TOASTER-iOS/Network/Toaster/ToasterTargetType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ enum ToasterTargetType {
case deleteLink(toastId: Int)
case getWeeksLink
case patchEditLinkTitle(requestBody: PatchEditLinkTitleRequestDTO)
case getRecentLink
}

extension ToasterTargetType: BaseTargetType {
Expand Down Expand Up @@ -46,6 +47,7 @@ extension ToasterTargetType: BaseTargetType {
case .deleteLink: return utilPath.rawValue + "/delete"
case .getWeeksLink: return utilPath.rawValue + "/week"
case .patchEditLinkTitle: return utilPath.rawValue + "/title"
case .getRecentLink: return utilPath.rawValue + "/recent-saved"
}
}

Expand All @@ -56,6 +58,7 @@ extension ToasterTargetType: BaseTargetType {
case .deleteLink: return .delete
case .getWeeksLink: return .get
case .patchEditLinkTitle: return .patch
case .getRecentLink: return .get
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,29 @@ extension DetailClipListCollectionViewCell {
}
}

func configureCell(forModel: RecentLinkModel, isClipHidden: Bool) {
modifiedButton.isHidden = false
mcrkgus marked this conversation as resolved.
Show resolved Hide resolved
clipNameLabel.text = forModel.toastTitle
linkTitleLabel.text = forModel.toastTitle
linkLabel.text = forModel.linkUrl
isClipNameLabelHidden = forModel.categoryTitle != nil ? true : false
isReadDimmedView = forModel.isRead
toastId = forModel.toastId

if forModel.categoryTitle != nil && !isClipHidden {
clipNameLabel.text = forModel.categoryTitle
isClipNameLabelHidden = false
} else {
isClipNameLabelHidden = true
}

if let imageURL = forModel.thumbnailUrl {
linkImage.kf.setImage(with: URL(string: imageURL))
} else {
linkImage.image = .imgThumbnail
}
}

func configureCell(forModel: SearchResultDetailClipModel, forText: String) {
modifiedButton.isHidden = true
linkTitleLabel.text = forModel.title
Expand Down
17 changes: 17 additions & 0 deletions TOASTER-iOS/Present/Home/Model/RecentLinkModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// RecentLinkModel.swift
// TOASTER-iOS
//
// Created by Gahyun Kim on 10/17/24.
//

import Foundation

struct RecentLinkModel {
let toastId: Int
let toastTitle: String
let linkUrl: String
let isRead: Bool
let categoryTitle: String?
let thumbnailUrl: String?
}
20 changes: 17 additions & 3 deletions TOASTER-iOS/Present/Home/View/Cell/HomeHeaderCollectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ final class HomeHeaderCollectionView: UICollectionReusableView {
// MARK: - Properties

private let titleLabel = UILabel()
let arrowButton = UIButton()

// MARK: - Life Cycle

override init(frame: CGRect) {
super.init(frame: frame)

self.backgroundColor = .clear

setView()
}

Expand All @@ -41,33 +43,45 @@ final class HomeHeaderCollectionView: UICollectionReusableView {
$0.textColor = .black900
$0.font = .suitMedium(size: 18)
}

arrowButton.do {
$0.setImage(.icArrow20, for: .normal)
$0.isUserInteractionEnabled = true
$0.isHidden = false
}
}

// MARK: - set up Hierarchy

private func setupHierarchy() {
addSubview(titleLabel)
addSubviews(titleLabel, arrowButton)
}

// MARK: - set up Layout

private func setupLayout() {
titleLabel.snp.makeConstraints {
$0.leading.trailing.equalToSuperview().inset(10)
$0.leading.equalToSuperview().inset(10)
$0.bottom.equalToSuperview().inset(5)
}

arrowButton.snp.makeConstraints {
$0.top.equalTo(titleLabel.snp.top).inset(1)
$0.trailing.equalToSuperview().inset(10)
}
}
}

extension HomeHeaderCollectionView {
func configureHeader(forTitle: String, num: Int) {
if num == 1 {
titleLabel.text = forTitle + "님의 클립"
titleLabel.text = forTitle + "님이 최근 저장한 링크"
titleLabel.font = .suitMedium(size: 18)
titleLabel.asFont(targetString: forTitle, font: .suitBold(size: 18))
} else {
titleLabel.text = forTitle
titleLabel.asFont(targetString: forTitle, font: .suitBold(size: 18))
arrowButton.isHidden = true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private extension UserClipEmptyCollectionViewCell {
addClipLabel.do {
$0.font = .suitBold(size: 14)
$0.textColor = .gray200
$0.text = "클립 추가"
$0.text = "첫번째 링크를 저장해보세요"
}
}

Expand All @@ -66,13 +66,13 @@ private extension UserClipEmptyCollectionViewCell {
func setupLayout() {
addClipImage.snp.makeConstraints {
$0.centerX.equalToSuperview()
$0.top.equalToSuperview().inset(34)
$0.top.equalToSuperview().inset(17)
$0.size.equalTo(42)
}

addClipLabel.snp.makeConstraints {
$0.centerX.equalToSuperview()
$0.top.equalTo(addClipImage.snp.bottom).offset(1)
$0.top.equalTo(addClipImage.snp.bottom).offset(5)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ enum CompositionalFactory {
case 0:
section = createMainSection()
case 1:
section = createUserClipSection()
section = createUserRecentLinkSection()
case 2:
section = createWeeklyLinkSection()
case 3:
Expand Down Expand Up @@ -68,22 +68,22 @@ enum CompositionalFactory {

// MARK: - User Clip 에 대한 Layout

static func createUserClipSection() -> NSCollectionLayoutSection {
let itemFractionalWidthFraction = 1.0 / 2.0
let itemInset: CGFloat = 7
static func createUserRecentLinkSection() -> NSCollectionLayoutSection {
let itemFractionalWidthFraction = 1.0 / 1.0
let itemInset: CGFloat = 8

// item
let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(itemFractionalWidthFraction),
heightDimension: .absolute(150))
heightDimension: .absolute(104))
let item = NSCollectionLayoutItem(layoutSize: itemSize)
item.contentInsets = NSDirectionalEdgeInsets(top: itemInset,
item.contentInsets = NSDirectionalEdgeInsets(top: 0,
leading: itemInset,
bottom: itemInset,
trailing: itemInset)

// group
let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1),
heightDimension: .absolute(150))
heightDimension: .absolute(104))
let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize,
subitems: [item])

Expand All @@ -101,7 +101,7 @@ enum CompositionalFactory {
elementKind: UICollectionView.elementKindSectionHeader,
alignment: .top),
NSCollectionLayoutBoundarySupplementaryItem(layoutSize: .init(widthDimension: .fractionalWidth(1),
heightDimension: .absolute(17)),
heightDimension: .absolute(9)),
elementKind: UICollectionView.elementKindSectionFooter,
alignment: .bottom)]
return section
Expand Down
Loading