Skip to content

Commit

Permalink
[:sparkles: feature] 메인화면 팔로우 기능 추가
Browse files Browse the repository at this point in the history
feat: 보틀월드 유저 팔로우 버튼 기능 추가 #112
  • Loading branch information
Juhyeoklee committed Sep 15, 2022
1 parent 6cb7339 commit 88bc842
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
10 changes: 7 additions & 3 deletions Code-Zero/Screen/Challenge/Storyboards/Challenge.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="20037" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="IES-Xf-5J6">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21225" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="IES-Xf-5J6">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21207"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
Expand Down Expand Up @@ -59,13 +59,17 @@
</stackView>
<button hidden="YES" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="cD2-kI-bZf">
<rect key="frame" x="302" y="54" width="53" height="30"/>
<color key="backgroundColor" name="orangeMain"/>
<constraints>
<constraint firstAttribute="height" constant="30" id="9J8-8U-kC3"/>
<constraint firstAttribute="width" constant="53" id="DBt-02-1aE"/>
</constraints>
<fontDescription key="fontDescription" name="SpoqaHanSansNeo-Bold" family="Spoqa Han Sans Neo" pointSize="12"/>
<inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
<state key="normal" title="팔로잉">
<state key="normal" title="팔로우">
<color key="titleColor" name="white"/>
</state>
<state key="selected" title="팔로잉">
<color key="titleColor" name="orangeMain"/>
</state>
<connections>
Expand Down
19 changes: 19 additions & 0 deletions Code-Zero/Screen/Challenge/VC/ChallengeVC+Network.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,23 @@ extension ChallengeVC {
Indicator.shared.dismiss()
}
}

internal func toggleFollow(completion: @escaping (Bool) -> Void) {
guard let userID = fetchedUserId, let token = accessToken else { return }

BottleWorldService.shared.makeBottleworldFollow(
token: token,
id: userID
) { result in
switch result {
case .success(let isSuccess):
completion(isSuccess)
case .requestErr(let message):
print(message)
completion(false)
case .networkFail, .serverErr:
completion(false)
}
}
}
}
18 changes: 16 additions & 2 deletions Code-Zero/Screen/Challenge/VC/ChallengeVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ class ChallengeVC: UIViewController {
}

// MARK: - IBAction Method

@IBAction func cheerUpButtonDidTap(_ sender: Any) {
guard let userName = userInfo?.name else { return }
cheerUpUser { [weak self] isSuccess in
Expand All @@ -168,7 +167,15 @@ class ChallengeVC: UIViewController {
}

@IBAction func followingButtonDidTap(_ sender: Any) {
// TODO: 팔로잉 버튼 액션
toggleFollow { [weak self] isSuccess in
var isCurrentFollowing = self?.challengeData?.isFollowing ?? false
if isSuccess {
isCurrentFollowing.toggle()
}
DispatchQueue.main.async {
self?.updateFollowButton(isFollowing: isCurrentFollowing)
}
}
}

@IBAction private func moveBottleWorldButtonDidTap() {
Expand Down Expand Up @@ -377,6 +384,13 @@ extension ChallengeVC {
let isChallenging = challengeData?.myChallenge != nil
cheerUpButton.isHidden = (isChallenging == false) || isMine
followingButton.isHidden = isMine && isFollowing
let isCurrentFollowing = self.challengeData?.isFollowing ?? false
updateFollowButton(isFollowing: isCurrentFollowing)
}
private func updateFollowButton(isFollowing: Bool) {
followingButton.isSelected = isFollowing
let backgroundColor: UIColor = isFollowing ? .white : .orangeMain
followingButton.backgroundColor = backgroundColor
}
private func updateBottleImageView() {

Expand Down

0 comments on commit 88bc842

Please sign in to comment.