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

Fix: QA 반영 및 믹스패널 로깅 추가 #183

Merged
merged 8 commits into from
Jun 8, 2023
Merged
25 changes: 25 additions & 0 deletions Projects/App/Sources/Global/Extensions/UIViewController+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,31 @@ extension UIViewController {

self.present(alertViewController, animated: true)
}

public func showToast(message: String, font: UIFont) {
let toastLabel = UILabel()
toastLabel.backgroundColor = UIColor.wkBlack45.withAlphaComponent(0.8)
toastLabel.textColor = UIColor.white
toastLabel.font = font
toastLabel.textAlignment = .center
toastLabel.text = message
toastLabel.alpha = 1.0
toastLabel.layer.cornerRadius = 10
toastLabel.clipsToBounds = true

self.view.addSubview(toastLabel)
toastLabel.snp.makeConstraints { make in
make.top.equalTo(self.view.safeAreaLayoutGuide)
make.leading.trailing.equalToSuperview().inset(20)
make.height.equalTo(40)
}

UIView.animate(withDuration: 1.0, delay: 3.0, options: .curveEaseOut, animations: {
toastLabel.alpha = 0.0
}, completion: { _ in
toastLabel.removeFromSuperview()
})
}
}

struct AlertButton {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import DesignSystem
import UIKit

import ReactorKit
import Mixpanel

class AbilityViewController: BaseViewController, PageTabProtocol, View {

Expand Down Expand Up @@ -113,6 +114,8 @@ class AbilityViewController: BaseViewController, PageTabProtocol, View {

extension AbilityViewController: UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
Mixpanel.mainInstance().track(event: "모아보기_역량_목록_Clicked")

let detailViewController = DetailViewController(previousView: .ability)
detailViewController.reactor = DetailReactor(
title: self.reactor?.currentState.abilities[indexPath.row].name ?? "",
Expand Down
11 changes: 11 additions & 0 deletions Projects/App/Sources/Screens/Library/DetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import DesignSystem
import UIKit

import ReactorKit
import Mixpanel

class DetailViewController: BaseViewController, View {
var disposeBag = DisposeBag()
Expand Down Expand Up @@ -67,6 +68,7 @@ class DetailViewController: BaseViewController, View {
self.setLayout()
self.registerCell()
self.setDataSource()
self.trackEmptyView()
}

private func setNavigationBar() {
Expand Down Expand Up @@ -190,6 +192,15 @@ class DetailViewController: BaseViewController, View {
self.dataSource.apply(snapshot)
}

func trackEmptyView() {
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(addMixpanel(sender:)))
emptyView.addGestureRecognizer(tapGesture)
}

@objc
func addMixpanel(sender: UITapGestureRecognizer) {
Mixpanel.mainInstance().track(event: "모아보기_프로젝트_목록_Clicked")
}
}

extension DetailViewController: CalendarBottomSheetDelegate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import DesignSystem
import UIKit

import ReactorKit
import Mixpanel

class ProjectViewController: BaseViewController, PageTabProtocol, View {

Expand Down Expand Up @@ -118,6 +119,8 @@ class ProjectViewController: BaseViewController, PageTabProtocol, View {

extension ProjectViewController: UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
Mixpanel.mainInstance().track(event: "모아보기_프로젝트_목록_Clicked")

let detailViewController = DetailViewController(previousView: .project)
detailViewController.reactor = DetailReactor(
title: self.reactor?.currentState.projects[indexPath.row].name ?? "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import Domain

import ReactorKit
import Mixpanel

final class ProjectManagementReactor: Reactor {
var initialState: State
Expand All @@ -21,7 +22,8 @@ final class ProjectManagementReactor: Reactor {
newProjectTitle: "",
projectList: [],
isEnableCreateButton: false,
isDuplicatedProject: false
isDuplicatedProject: false,
isShowingToast: false
)
}

Expand All @@ -39,6 +41,7 @@ final class ProjectManagementReactor: Reactor {
var projectList: [Project]
var isEnableCreateButton: Bool
var isDuplicatedProject: Bool
var isShowingToast: Bool
}

enum Mutation {
Expand All @@ -48,6 +51,7 @@ final class ProjectManagementReactor: Reactor {
case modifyTitle(String, Int, Int)
case deleteProject(Int, Int)
case setNewProjectTitle(String?)
case showToast(Bool)
}

func mutate(action: Action) -> Observable<Mutation> {
Expand All @@ -65,10 +69,17 @@ final class ProjectManagementReactor: Reactor {
return .empty()
}

return self.projectUseCase
.createProject(title: currentState.newProjectTitle)
.map { Mutation.createProject($0) }
.asObservable()
Mixpanel.mainInstance().track(event: "설정_프로젝트 생성 버튼_Clicked")

return .concat(
[self.projectUseCase
.createProject(title: currentState.newProjectTitle)
.map { Mutation.createProject($0) }
.asObservable(),
.just(.showToast(true)),
.just(.showToast(false)).delay(.seconds(3), scheduler: MainScheduler.instance)
]
)

case let .modifyButtonTapped(projectName, projectID):
if let projectName = projectName,
Expand Down Expand Up @@ -98,6 +109,7 @@ final class ProjectManagementReactor: Reactor {
var newState = state

switch mutation {

case let .projects(projects):
newState.projectList = projects

Expand All @@ -110,6 +122,7 @@ final class ProjectManagementReactor: Reactor {
return newState
}
newState.isDuplicatedProject = false
newState.newProjectTitle = ""
newState.projectList.insert(project, at: 0)

case let .modifyTitle(name, projectID, statusCode):
Expand All @@ -120,7 +133,7 @@ final class ProjectManagementReactor: Reactor {

newState.projectList[index].title = name
}

case let .deleteProject(projectID, statusCode):
if statusCode == 20000 {
guard let index = newState.projectList.firstIndex(where: { item in
Expand All @@ -137,9 +150,13 @@ final class ProjectManagementReactor: Reactor {
return newState
}
newState.isEnableCreateButton = true

case let .showToast(show):
newState.isShowingToast = show
}

return newState

}
// swiftlint:enable cyclomatic_complexity

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
import Domain
import DesignSystem
import UIKit
import Global

import SnapKit
import ReactorKit

// swiftlint:disable type_body_length
final class ProjectManagementViewController: BaseViewController, View {

typealias DiffableDataSource = UICollectionViewDiffableDataSource<Section, Project>
Expand Down Expand Up @@ -64,6 +66,8 @@ final class ProjectManagementViewController: BaseViewController, View {

private let projectCreateView = ProjectCreateView()

// swiftlint:enable type_body_length

// MARK: - Properties

var dataSource: DiffableDataSource!
Expand Down Expand Up @@ -125,6 +129,7 @@ final class ProjectManagementViewController: BaseViewController, View {
reactor.state
.map { $0.projectList }
.filter { !$0.isEmpty }
.distinctUntilChanged()
.withUnretained(self)
.bind { owner, projects in
owner.applySnapshot(projects: projects)
Expand All @@ -133,21 +138,33 @@ final class ProjectManagementViewController: BaseViewController, View {

reactor.state
.map { $0.isEnableCreateButton }
.distinctUntilChanged()
.withUnretained(self)
.bind { owner, isEnableCreateButton in
owner.projectCreateView.createButton.isEnabled = isEnableCreateButton
}
.disposed(by: disposeBag)

reactor.state
.map { $0.isDuplicatedProject }
.compactMap { $0.newProjectTitle }
.distinctUntilChanged()
.withUnretained(self)
.bind { _, isDuplicatedProject in
if isDuplicatedProject {

.bind { owner, text in
owner.projectCreateView.textField.text = text
}
.disposed(by: disposeBag)

reactor.state
.map { $0.isShowingToast }
.distinctUntilChanged()
.withUnretained(self)
.bind { owner, isShowingToast in
if isShowingToast && reactor.currentState.isDuplicatedProject {
owner.showToast(message: "이미 생성된 프로젝트입니다.", font: .b2M)
}
}
.disposed(by: disposeBag)

}

// MARK: - Methods
Expand Down
Loading