Skip to content

Commit

Permalink
[Merge] #100 - 답글 좋아요 및 답글 좋아요 삭제 API 연결 및 UI 세부사항 수정
Browse files Browse the repository at this point in the history
Network [#100] 답글 좋아요 및 답글 좋아요 삭제 API 연결 및 UI 세부사항 수정
  • Loading branch information
Heyjooo authored Jan 18, 2024
2 parents 898a76e + 3d041d4 commit 5f093cc
Show file tree
Hide file tree
Showing 19 changed files with 263 additions and 61 deletions.
4 changes: 4 additions & 0 deletions DontBe-iOS/DontBe-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
2A5220EC2B507F2A001510B7 /* UITableViewCellRegisterable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A5220EB2B507F2A001510B7 /* UITableViewCellRegisterable.swift */; };
2A5220EF2B507F97001510B7 /* NotificationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A5220EE2B507F97001510B7 /* NotificationViewModel.swift */; };
2A5220F22B507FAE001510B7 /* NotificationTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A5220F12B507FAE001510B7 /* NotificationTableViewCell.swift */; };
2A5D68F82B58E9C0000AE1B7 /* CommentLikeRequestDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A5D68F72B58E9C0000AE1B7 /* CommentLikeRequestDTO.swift */; };
2A6D54C12B479B4300F9891E /* adjusted+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A6D54C02B479B4300F9891E /* adjusted+.swift */; };
2A6D54C32B493A8400F9891E /* UIFont+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A6D54C22B493A8400F9891E /* UIFont+.swift */; };
2A6D54C62B493E3F00F9891E /* Pretendard-SemiBold.otf in Resources */ = {isa = PBXBuildFile; fileRef = 2A6D54C42B493E3F00F9891E /* Pretendard-SemiBold.otf */; };
Expand Down Expand Up @@ -173,6 +174,7 @@
2A5220EB2B507F2A001510B7 /* UITableViewCellRegisterable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UITableViewCellRegisterable.swift; sourceTree = "<group>"; };
2A5220EE2B507F97001510B7 /* NotificationViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationViewModel.swift; sourceTree = "<group>"; };
2A5220F12B507FAE001510B7 /* NotificationTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationTableViewCell.swift; sourceTree = "<group>"; };
2A5D68F72B58E9C0000AE1B7 /* CommentLikeRequestDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentLikeRequestDTO.swift; sourceTree = "<group>"; };
2A6D54C02B479B4300F9891E /* adjusted+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "adjusted+.swift"; sourceTree = "<group>"; };
2A6D54C22B493A8400F9891E /* UIFont+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIFont+.swift"; sourceTree = "<group>"; };
2A6D54C42B493E3F00F9891E /* Pretendard-SemiBold.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Pretendard-SemiBold.otf"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -641,6 +643,7 @@
isa = PBXGroup;
children = (
2F05B1B62B57F1FD00AC368D /* WriteReplyRequestDTO.swift */,
2A5D68F72B58E9C0000AE1B7 /* CommentLikeRequestDTO.swift */,
);
path = RequestDTO;
sourceTree = "<group>";
Expand Down Expand Up @@ -1228,6 +1231,7 @@
3CF184D12B4EFF9900816D5F /* MyPageProfileView.swift in Sources */,
2A51831A2B571CC400B43BA8 /* NotificationList.swift in Sources */,
3C61931B2B3A7AD000220CEB /* NetworkError.swift in Sources */,
2A5D68F82B58E9C0000AE1B7 /* CommentLikeRequestDTO.swift in Sources */,
2F05B1B72B57F1FD00AC368D /* WriteReplyRequestDTO.swift in Sources */,
3CBF99272B549C7D0015FE4B /* WriteViewModel.swift in Sources */,
3C70BE332B53EF92001AA5A6 /* MyPageViewModel.swift in Sources */,
Expand Down
4 changes: 2 additions & 2 deletions DontBe-iOS/DontBe-iOS/Global/Extension/String+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ extension String {
} else if let minute = components.minute, minute == 0 {
return "지금"
} else {
return "시간을 불러올 수 없습니다."
return "알 수 없음"
}
} else {
return "날짜 변환 실패"
return "알 수 없음"
}
}
}
17 changes: 17 additions & 0 deletions DontBe-iOS/DontBe-iOS/Global/Extension/UIViewController+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,21 @@ extension UIViewController {
var statusBarHeight: CGFloat {
return UIApplication.shared.windows.filter({$0.isKeyWindow}).first?.windowScene?.statusBarManager?.statusBarFrame.height ?? 20
}

func applyTabBarAttributes(to tabBarItem: UITabBarItem, isSelected: Bool) {
let attributes: [NSAttributedString.Key: Any]

if isSelected {
attributes = [
.font: UIFont.font(.caption3),
.foregroundColor: UIColor.donSecondary
] // title이 선택되었을 때 폰트, 색상 설정
} else {
attributes = [
.font: UIFont.font(.caption4),
.foregroundColor: UIColor.donGray7
] // title이 선택되지 않았을 때 폰트, 색상 설정
}
tabBarItem.setTitleTextAttributes(attributes, for: .normal)
}
}
1 change: 1 addition & 0 deletions DontBe-iOS/DontBe-iOS/Global/Literals/ImageLiterals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ enum ImageLiterals {
static var btnBack: UIImage { .load(name: "btn_back") }
static var logoSymbol: UIImage { .load(name: "logo_symbol") }
static var imgProfile: UIImage { .load(name: "img_profile") }
static var btnBackGray: UIImage { .load(name: "btn_back_gray") }
}

enum TabBar {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "btn_back.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// CommentLikeRequestDTO.swift
// DontBe-iOS
//
// Created by 변희주 on 1/18/24.
//

import Foundation

struct CommentLikeRequestDTO: Encodable {
let notificationTriggerType: String
let notificationText: String
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ final class HomeCollectionViewCell: UICollectionViewCell, UICollectionViewRegist
var KebabButtonAction: (() -> Void) = {}
var LikeButtonAction: (() -> Void) = {}
var TransparentButtonAction: (() -> Void) = {}
var ProfileButtonAction: (() -> Void) = {}
var isLiked: Bool = false
var alarmTriggerType: String = ""
var targetMemberId: Int = 0
Expand Down Expand Up @@ -44,8 +45,9 @@ final class HomeCollectionViewCell: UICollectionViewCell, UICollectionViewRegist
image.clipsToBounds = true
image.layer.borderWidth = 1.adjusted
image.layer.borderColor = UIColor.clear.cgColor
image.image = UIImage.checkmark
image.image = ImageLiterals.Common.imgProfile
image.layer.cornerRadius = 22.adjusted
image.isUserInteractionEnabled = true
return image
}()

Expand Down Expand Up @@ -276,6 +278,7 @@ extension HomeCollectionViewCell {
kebabButton.addTarget(self, action: #selector(showButtons), for: .touchUpInside)
likeButton.addTarget(self, action: #selector(likeToggleButton), for: .touchUpInside)
ghostButton.addTarget(self, action: #selector(transparentShowPopupButton), for: .touchUpInside)
profileImageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(profileButton)))
}

@objc
Expand All @@ -291,4 +294,9 @@ extension HomeCollectionViewCell {
func transparentShowPopupButton() {
TransparentButtonAction()
}

@objc
func profileButton() {
ProfileButtonAction()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,13 @@ final class HomeViewController: UIViewController {

override func viewWillAppear(_ animated: Bool) {
self.navigationController?.navigationBar.isHidden = true
self.tabBarController?.tabBar.isHidden = false
bindViewModel()
}

override func viewWillDisappear(_ animated: Bool) {
self.navigationController?.navigationBar.isHidden = false

self.navigationController?.navigationBar.backgroundColor = .clear
refreshPost()
}
}
Expand Down Expand Up @@ -287,7 +288,7 @@ extension HomeViewController {

private func postLikeButtonAPI(isClicked: Bool, contentId: Int) {
// 최초 한 번만 publisher 생성
var likeButtonTapped: AnyPublisher<(Bool, Int), Never>? = Just(())
let likeButtonTapped: AnyPublisher<(Bool, Int), Never>? = Just(())
.map { _ in return (!isClicked, contentId) }
.throttle(for: .seconds(2), scheduler: DispatchQueue.main, latest: false)
.eraseToAnyPublisher()
Expand All @@ -297,9 +298,7 @@ extension HomeViewController {
let output = self.viewModel.transform(from: input, cancelBag: self.cancelBag)

output.toggleLikeButton
.sink { value in
print(value)
}
.sink { _ in }
.store(in: self.cancelBag)
}
}
Expand Down Expand Up @@ -355,13 +354,37 @@ extension HomeViewController: UICollectionViewDataSource, UICollectionViewDelega
cell.likeButton.setImage(cell.isLiked ? ImageLiterals.Posting.btnFavoriteActive : ImageLiterals.Posting.btnFavoriteInActive, for: .normal)
self.postLikeButtonAPI(isClicked: cell.isLiked, contentId: self.viewModel.postData[indexPath.row].contentId)
}

cell.ProfileButtonAction = {
let memberId = self.viewModel.postData[indexPath.row].memberId

if memberId == loadUserData()?.memberId ?? 0 {
self.tabBarController?.selectedIndex = 3
if let selectedViewController = self.tabBarController?.selectedViewController {
self.applyTabBarAttributes(to: selectedViewController.tabBarItem, isSelected: true)
}
let myViewController = self.tabBarController?.viewControllers ?? [UIViewController()]
for (index, controller) in myViewController.enumerated() {
if let tabBarItem = controller.tabBarItem {
if index != self.tabBarController?.selectedIndex {
self.applyTabBarAttributes(to: tabBarItem, isSelected: false)
}
}
}
} else {
let viewController = MyPageViewController(viewModel: MyPageViewModel(networkProvider: NetworkService()))
viewController.memberId = memberId
self.navigationController?.pushViewController(viewController, animated: true)
}
}

cell.TransparentButtonAction = {
self.alarmTriggerType = cell.alarmTriggerType
self.targetMemberId = cell.targetMemberId
self.alarmTriggerdId = cell.alarmTriggerdId
self.present(self.transparentPopupVC, animated: false, completion: nil)
}
cell.profileImageView.load(url: viewModel.postData[indexPath.row].memberProfileUrl)
cell.nicknameLabel.text = viewModel.postData[indexPath.row].memberNickname
cell.transparentLabel.text = "투명도 \(viewModel.postData[indexPath.row].memberGhost)%"
cell.contentTextLabel.text = viewModel.postData[indexPath.row].contentText
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ extension HomeViewModel {
body: requestDTO,
pathVariables: ["":""]
)
print ("👻👻👻👻👻게시글 좋아요 버튼 클릭👻👻👻👻👻")
print ("👻👻👻👻👻게시물 좋아요 버튼 클릭👻👻👻👻👻")
return data
} catch {
return nil
Expand All @@ -141,7 +141,7 @@ extension HomeViewModel {
body: EmptyBody(),
pathVariables: ["":""]
)
print ("👻👻👻👻👻게시글 좋아요 취소 버튼 클릭👻👻👻👻👻")
print ("👻👻👻👻👻게시물 좋아요 취소 버튼 클릭👻👻👻👻👻")
return data
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ extension MyPageAccountInfoViewController {
}

private func bindViewModel() {
let input = MyPageViewModel.Input(viewUpdate: Just((0)).eraseToAnyPublisher())
let memberId = loadUserData()?.memberId ?? 0
let input = MyPageViewModel.Input(viewUpdate: Just((0, memberId )).eraseToAnyPublisher())

let output = viewModel.transform(from: input, cancelBag: cancelBag)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ final class MyPageViewController: UIViewController {

private var cancelBag = CancelBag()
var viewModel: MyPageViewModel
var memberId: Int = loadUserData()?.memberId ?? 0

var currentPage: Int = 0 {
didSet {
Expand All @@ -43,8 +44,14 @@ final class MyPageViewController: UIViewController {
// MARK: - UI Components

let rootView = MyPageView()

// MARK: - Life Cycles
let statusBarView = UIView(frame: UIApplication.shared.statusBarFrame)
private var navigationBackButton: UIButton = {
let button = UIButton()
button.setImage(ImageLiterals.Common.btnBackGray, for: .normal)
return button
}()

// MARK: - Life Cycles

override func loadView() {
super.loadView()
Expand Down Expand Up @@ -75,15 +82,35 @@ final class MyPageViewController: UIViewController {
super.viewWillAppear(true)

bindViewModel()
let image = ImageLiterals.MyPage.icnMenu
let renderedImage = image.withRenderingMode(.alwaysOriginal)
let hambergerButton = UIBarButtonItem(image: renderedImage,
style: .plain,
target: self,
action: #selector(hambergerButtonTapped))
navigationItem.rightBarButtonItem = hambergerButton

self.navigationItem.title = StringLiterals.MyPage.MyPageNavigationTitle
if memberId == loadUserData()?.memberId ?? 0 {
self.navigationItem.title = StringLiterals.MyPage.MyPageNavigationTitle
self.tabBarController?.tabBar.isHidden = false
hambergerButton.isHidden = false
navigationBackButton.isHidden = true
} else {
self.navigationItem.title = ""
self.tabBarController?.tabBar.isHidden = true
hambergerButton.isHidden = true
navigationBackButton.isHidden = false
}
self.navigationController?.navigationBar.titleTextAttributes = [.foregroundColor: UIColor.donWhite]
self.navigationItem.hidesBackButton = true
}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(true)

self.navigationController?.navigationBar.backgroundColor = .clear
statusBarView.removeFromSuperview()
navigationBackButton.removeFromSuperview()
}

override func viewDidLayoutSubviews() {
Expand Down Expand Up @@ -111,18 +138,14 @@ extension MyPageViewController {
self.tabBarController?.tabBar.isTranslucent = true
self.navigationController?.navigationBar.backgroundColor = .donBlack
self.navigationController?.navigationBar.barTintColor = .donBlack

let image = ImageLiterals.MyPage.icnMenu
let renderedImage = image.withRenderingMode(.alwaysOriginal)
let hambergerButton = UIBarButtonItem(image: renderedImage,
style: .plain,
target: self,
action: #selector(hambergerButtonTapped))

navigationItem.rightBarButtonItem = hambergerButton
}

private func setLayout() {
self.navigationController?.navigationBar.addSubviews(navigationBackButton)
navigationBackButton.snp.makeConstraints {
$0.centerY.equalToSuperview()
$0.leading.equalToSuperview().inset(23.adjusted)
}
rootView.pageViewController.view.snp.makeConstraints {
$0.top.equalTo(rootView.segmentedControl.snp.bottom).offset(2.adjusted)
$0.leading.trailing.equalToSuperview()
Expand All @@ -140,6 +163,7 @@ extension MyPageViewController {
}

private func setAddTarget() {
navigationBackButton.addTarget(self, action: #selector(backButtonPressed), for: .touchUpInside)
rootView.segmentedControl.addTarget(self, action: #selector(changeValue(control:)), for: .valueChanged)
rootView.myPageBottomsheet.profileEditButton.addTarget(self, action: #selector(profileEditButtonTapped), for: .touchUpInside)
rootView.myPageBottomsheet.accountInfoButton.addTarget(self, action: #selector(accountInfoButtonTapped), for: .touchUpInside)
Expand All @@ -148,7 +172,7 @@ extension MyPageViewController {
}

private func bindViewModel() {
let input = MyPageViewModel.Input(viewUpdate: Just((1)).eraseToAnyPublisher())
let input = MyPageViewModel.Input(viewUpdate: Just((1, self.memberId)).eraseToAnyPublisher())

let output = viewModel.transform(from: input, cancelBag: cancelBag)

Expand Down Expand Up @@ -258,6 +282,11 @@ extension MyPageViewController {
let navigationBarHeight = self.navigationController?.navigationBar.frame.height ?? 0
rootView.myPageScrollView.setContentOffset(CGPoint(x: 0, y: -rootView.myPageScrollView.contentInset.top - navigationBarHeight - statusBarHeight), animated: true)
}

@objc
private func backButtonPressed() {
self.navigationController?.popViewController(animated: true)
}
}

// MARK: - Network
Expand Down
Loading

0 comments on commit 5f093cc

Please sign in to comment.