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

🎨 refactor/code #21

Merged
merged 2 commits into from
Jan 2, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions Dear-World/Dear-World.xcodeproj/MessageCountBadgeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
// Created by rookie.w on 2020/12/26.
//

import UIKit
import SnapKit
import Then
import SnapKit
import UIKit

public final class MessageCountBadgeView: UIView {
final class MessageCountBadgeView: UIView {
private var totalCount: UILabel = UILabel()

public var count: Int? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Foundation
import ReactorKit

final class CheeringMapReactor: Reactor {

typealias API = World.API
typealias Model = World.Model

Expand All @@ -29,6 +28,8 @@ final class CheeringMapReactor: Reactor {
}

var initialState: State = State()

// MARK: 🔫 Mutate
func mutate(action: Action) -> Observable<Mutation> {
switch action {
case .viewDidLoad:
Expand All @@ -42,6 +43,7 @@ final class CheeringMapReactor: Reactor {
}
}

// MARK: ⚡️ Reduce
func reduce(state: State, mutation: Mutation) -> State {
var newState = currentState
switch mutation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,140 +8,142 @@
import UIKit

final class MessageTableViewCell: UICollectionViewCell {
let emojiLabel: UILabel = UILabel()
let nameLabel: UILabel = UILabel()
let countryLabel: UILabel = UILabel()
let detailTextView: UITextView = UITextView()
// TODO: likeView를 커스텀뷰로 만들기
let likeView: UIImageView = UIImageView()
let likeCountLabel: UILabel = UILabel()
let shareButton: UIButton = UIButton()

override func awakeFromNib() {
super.awakeFromNib()
// Initialization code

// MARK: 🖼 UI
let emojiLabel: UILabel = UILabel()
let nameLabel: UILabel = UILabel()
let countryLabel: UILabel = UILabel()
let detailTextView: UITextView = UITextView()
let likeView: UIImageView = UIImageView()
let likeCountLabel: UILabel = UILabel()
let shareButton: UIButton = UIButton()

// MARK: 🏁 Initialize
override init(frame: CGRect) {
super.init(frame: frame)

setupUI()
bind()
}

required init?(coder: NSCoder) {
super.init(coder: coder)

setupUI()
bind()
}

// MARK: 🎛 Setup
private func setupUI() {
self.do {
$0.backgroundColor = .white
$0.layer.masksToBounds = true
$0.layer.cornerRadius = 20
}

override init(frame: CGRect) {
super.init(frame: frame)
setupUI()
bind()
let emojiView: UIImageView = UIImageView().then {
$0.image = UIImage(named: "emojiBox")
}
self.addSubview(emojiView)
emojiView.snp.makeConstraints {
$0.top.leading.equalToSuperview().inset(30)
$0.height.width.equalTo(40)
}

required init?(coder: NSCoder) {
super.init(coder: coder)
setupUI()
bind()
self.emojiLabel.do {
$0.text = "🎅🏻"
// FIXME : 14처럼 고정된 값 없이 최대로 꽉차게 할 수 없는가?
$0.font = .systemFont(ofSize: 14)
$0.textAlignment = .center
}
self.addSubview(self.emojiLabel)
self.emojiLabel.snp.makeConstraints {
$0.size.equalTo(20)
$0.center.equalTo(emojiView)
}

private func setupUI() {
self.do {
$0.backgroundColor = .white
$0.layer.masksToBounds = true
$0.layer.cornerRadius = 20
}

let emojiView: UIImageView = UIImageView().then {
$0.image = UIImage(named: "emojiBox")
}
self.addSubview(emojiView)
emojiView.snp.makeConstraints {
$0.top.leading.equalToSuperview().inset(30)
$0.height.width.equalTo(40)
}

self.emojiLabel.do {
$0.text = "🎅🏻"
// FIXME : 14처럼 고정된 값 없이 최대로 꽉차게 할 수 없는가?
$0.font = .systemFont(ofSize: 14)
$0.textAlignment = .center
}
self.addSubview(self.emojiLabel)
self.emojiLabel.snp.makeConstraints {
$0.size.equalTo(20)
$0.center.equalTo(emojiView)
}

self.nameLabel.do {
$0.text = "Judy"
$0.font = .boldSystemFont(ofSize: 16)
$0.textColor = .warmBlue
}
self.addSubview(self.nameLabel)
self.nameLabel.snp.makeConstraints {
$0.top.equalTo(emojiView.snp.top)
$0.leading.equalTo(emojiView.snp.trailing).offset(10)
$0.trailing.greaterThanOrEqualToSuperview().inset(30)
}

self.countryLabel.do {
$0.text = "🇰🇷 South Korea"
$0.font = .boldSystemFont(ofSize: 12)
$0.textColor = .grayWhite
}
self.addSubview(self.countryLabel)
self.countryLabel.snp.makeConstraints {
$0.bottom.equalTo(emojiView.snp.bottom)
$0.leading.equalTo(emojiView.snp.trailing).offset(10)
$0.trailing.greaterThanOrEqualToSuperview().inset(30)
}

self.detailTextView.do {
$0.text = "Hello world, dont worry because you’re strong enough to overcome this corona blue. At the end of the day, trust yourself. more"
$0.font = .systemFont(ofSize: 12)
$0.textColor = .black
$0.textContainerInset = .zero
$0.isScrollEnabled = false
$0.isEditable = false
}
self.addSubview(self.detailTextView)
self.detailTextView.snp.makeConstraints {
$0.leading.trailing.equalToSuperview().inset(30)
$0.top.equalTo(emojiView.snp.bottom).offset(10)
$0.height.equalTo(43)
}

self.likeView.do {
$0.image = UIImage(named: "heart")
}
self.addSubview(likeView)
self.likeView.snp.makeConstraints {
$0.leading.equalToSuperview().inset(30)
$0.bottom.equalToSuperview().inset(29)
$0.height.equalTo(17)
$0.width.equalTo(20)
}

self.likeCountLabel.do {
$0.font = .boldSystemFont(ofSize: 12)
$0.textColor = .grayWhite
$0.text = "32"
}
self.addSubview(self.likeCountLabel)
self.likeCountLabel.snp.makeConstraints {
$0.centerY.equalTo(likeView.snp.centerY)
$0.width.equalTo(16)
$0.height.equalTo(14)
$0.leading.equalTo(likeView.snp.trailing).offset(5)
}

self.shareButton.do {
$0.backgroundColor = .refreshingWhite
$0.layer.masksToBounds = true
$0.layer.cornerRadius = 8
$0.setImage(UIImage(named: "share"), for: .normal)
$0.setImage(UIImage(named: "share_press"), for: .highlighted)
$0.tintColor = .warmBlue
}
self.addSubview(shareButton)
shareButton.snp.makeConstraints {
$0.trailing.equalToSuperview().inset(30)
$0.bottom.equalToSuperview().inset(25)
$0.width.equalTo(30)
$0.height.equalTo(25)
}
}
func bind() {

self.nameLabel.do {
$0.text = "Judy"
$0.font = .boldSystemFont(ofSize: 16)
$0.textColor = .warmBlue
}
self.addSubview(self.nameLabel)
self.nameLabel.snp.makeConstraints {
$0.top.equalTo(emojiView.snp.top)
$0.leading.equalTo(emojiView.snp.trailing).offset(10)
$0.trailing.greaterThanOrEqualToSuperview().inset(30)
}

self.countryLabel.do {
$0.text = "🇰🇷 South Korea"
$0.font = .boldSystemFont(ofSize: 12)
$0.textColor = .grayWhite
}
self.addSubview(self.countryLabel)
self.countryLabel.snp.makeConstraints {
$0.bottom.equalTo(emojiView.snp.bottom)
$0.leading.equalTo(emojiView.snp.trailing).offset(10)
$0.trailing.greaterThanOrEqualToSuperview().inset(30)
}

self.detailTextView.do {
$0.text = "Hello world, dont worry because you’re strong enough to overcome this corona blue. At the end of the day, trust yourself. more"
$0.font = .systemFont(ofSize: 12)
$0.textColor = .black
$0.textContainerInset = .zero
$0.isScrollEnabled = false
$0.isEditable = false
}
self.addSubview(self.detailTextView)
self.detailTextView.snp.makeConstraints {
$0.leading.trailing.equalToSuperview().inset(30)
$0.top.equalTo(emojiView.snp.bottom).offset(10)
$0.height.equalTo(43)
}

self.likeView.do {
$0.image = UIImage(named: "heart")
}
self.addSubview(likeView)
self.likeView.snp.makeConstraints {
$0.leading.equalToSuperview().inset(30)
$0.bottom.equalToSuperview().inset(29)
$0.height.equalTo(17)
$0.width.equalTo(20)
}

self.likeCountLabel.do {
$0.font = .boldSystemFont(ofSize: 12)
$0.textColor = .grayWhite
$0.text = "32"
}
self.addSubview(self.likeCountLabel)
self.likeCountLabel.snp.makeConstraints {
$0.centerY.equalTo(likeView.snp.centerY)
$0.width.equalTo(16)
$0.height.equalTo(14)
$0.leading.equalTo(likeView.snp.trailing).offset(5)
}

self.shareButton.do {
$0.backgroundColor = .refreshingWhite
$0.layer.masksToBounds = true
$0.layer.cornerRadius = 8
$0.setImage(UIImage(named: "share"), for: .normal)
$0.setImage(UIImage(named: "share_press"), for: .highlighted)
$0.tintColor = .warmBlue
}
self.addSubview(shareButton)
shareButton.snp.makeConstraints {
$0.trailing.equalToSuperview().inset(30)
$0.bottom.equalToSuperview().inset(25)
$0.width.equalTo(30)
$0.height.equalTo(25)
}
}

// MARK: 🔗 Bind
func bind() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ final class DiscoverReactor: Reactor {

var initialState: State

// MARK: 🏁 Initialize
init() {
self.initialState = State()
}

// MARK: 🔫 Mutate
func mutate(action: Action) -> Observable<Mutation> {
switch action {
case let .countryDidChanged(country):
Expand All @@ -50,13 +52,15 @@ final class DiscoverReactor: Reactor {
.map { .setMessages(result: $0) },
.just(.setLoading(false))
)

case .refresh:
return .concat([
.just(Mutation.setRefreshing(true)),
APIMock().getMessages(page: 1, country: currentState.country)
.map { .setMessages(result: $0) },
.just(Mutation.setRefreshing(false))
])

case .loadMore:
return Observable<Mutation>.concat([
APIMock().getMessages(page: 2, country: currentState.country)
Expand All @@ -65,6 +69,7 @@ final class DiscoverReactor: Reactor {
}
}

// MARK: ⚡️ Reduce
func reduce(state: State, mutation: Mutation) -> State {
var newState: State = state
switch mutation {
Expand Down
Loading