From 1e9c4e1927e22ff3dfbb40665a59908ff41f99f0 Mon Sep 17 00:00:00 2001 From: jeohong Date: Sun, 4 Dec 2022 11:27:38 +0900 Subject: [PATCH 01/27] =?UTF-8?q?=E2=9C=A8=20=EC=9B=B9=EB=B7=B0=20?= =?UTF-8?q?=ED=98=B8=EC=B6=9C=EB=A1=9C=20License=EC=99=80=20=EA=B0=9C?= =?UTF-8?q?=EC=9D=B8=EC=A0=95=EB=B3=B4=20=EC=B2=98=EB=A6=AC=20=EB=B0=A9?= =?UTF-8?q?=EC=B9=A8=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Setting/SettingViewController.swift | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Workade/Views&ViewModels/MyPage/Setting/SettingViewController.swift b/Workade/Views&ViewModels/MyPage/Setting/SettingViewController.swift index 44d54e2d..5d0de902 100644 --- a/Workade/Views&ViewModels/MyPage/Setting/SettingViewController.swift +++ b/Workade/Views&ViewModels/MyPage/Setting/SettingViewController.swift @@ -5,6 +5,7 @@ // Created by Hyeonsoo Kim on 2022/10/26. // +import SafariServices import FirebaseAuth import UIKit @@ -34,11 +35,12 @@ final class SettingViewController: UIViewController { return label }() - private let dataButton: SettingButton = { - let button = SettingButton(text: "데이터") - button.addAction(UIAction(handler: { _ in - // TODO: 데이터 뷰 이동 - print("데이터 버튼 클릭") + private lazy var dataButton: SettingButton = { + let button = SettingButton(text: "개인정보 처리 방침") + button.addAction(UIAction(handler: { [weak self] _ in + guard let privacyPoliceURL = URL(string: "https://raw.githubusercontent.com/IIION/WorkadeData/main/ILION.md") else { return } + let privacyPoliceSafariView: SFSafariViewController = SFSafariViewController(url: privacyPoliceURL) + self?.present(privacyPoliceSafariView, animated: true, completion: nil) }), for: .touchUpInside) button.translatesAutoresizingMaskIntoConstraints = false @@ -46,11 +48,12 @@ final class SettingViewController: UIViewController { return button }() - private let licenseButton: SettingButton = { + private lazy var licenseButton: SettingButton = { let button = SettingButton(text: "라이센스") - button.addAction(UIAction(handler: { _ in - // TODO: 라이센스 뷰 이동 - print("라이센스 버튼 클릭") + button.addAction(UIAction(handler: { [weak self] _ in + guard let licenseURL = URL(string: "https://raw.githubusercontent.com/IIION/WorkadeData/main/License.md") else { return } + let licenseSafariView: SFSafariViewController = SFSafariViewController(url: licenseURL) + self?.present(licenseSafariView, animated: true, completion: nil) }), for: .touchUpInside) button.translatesAutoresizingMaskIntoConstraints = false From 9f06c3b9f478655d10346cf850010d3872668547 Mon Sep 17 00:00:00 2001 From: jeohong Date: Mon, 5 Dec 2022 17:33:04 +0900 Subject: [PATCH 02/27] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=EC=A4=80=EB=B9=84?= =?UTF-8?q?=EC=A4=91=EC=9D=B8=20=EC=A7=80=EC=97=AD=20Dismiss=20=EB=B2=84?= =?UTF-8?q?=ED=8A=BC=20=ED=99=9C=EC=84=B1=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Explore/ExploreViewController.swift | 13 ++++++++++++ .../Explore/RegionInfoView.swift | 20 +++++++++---------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/Workade/Views&ViewModels/Explore/ExploreViewController.swift b/Workade/Views&ViewModels/Explore/ExploreViewController.swift index 09d07a10..05f08d76 100644 --- a/Workade/Views&ViewModels/Explore/ExploreViewController.swift +++ b/Workade/Views&ViewModels/Explore/ExploreViewController.swift @@ -302,5 +302,18 @@ final class ExploreViewController: UIViewController { } else { self.mainContainerView.image = UIImage(named: "") } + + setupDismissButtonColor() + } + + private func setupDismissButtonColor() { + var image: UIImage? = UIImage() + + if regionInfoView.warningView.isHidden { + image = UIImage.fromSystemImage(name: "xmark", font: .systemFont(ofSize: 15, weight: .bold), color: .theme.primary)?.withRenderingMode(.alwaysOriginal) + } else { + image = UIImage.fromSystemImage(name: "xmark", font: .systemFont(ofSize: 15, weight: .bold), color: .theme.background)?.withRenderingMode(.alwaysOriginal) + } + regionInfoView.dismissButton.setImage(image, for: .normal) } } diff --git a/Workade/Views&ViewModels/Explore/RegionInfoView.swift b/Workade/Views&ViewModels/Explore/RegionInfoView.swift index 7b5304eb..eea3fff4 100644 --- a/Workade/Views&ViewModels/Explore/RegionInfoView.swift +++ b/Workade/Views&ViewModels/Explore/RegionInfoView.swift @@ -71,10 +71,8 @@ final class RegionInfoView: UIView { return button }() - private lazy var dismissButton: UIButton = { + lazy var dismissButton: UIButton = { let button = UIButton(type: .custom) - let image = UIImage.fromSystemImage(name: "xmark", font: .systemFont(ofSize: 15, weight: .bold))?.withRenderingMode(.alwaysOriginal) - button.setImage(image, for: .normal) button.addAction(UIAction(handler: { [weak self] _ in self?.selectedRegion.value = nil }), for: .touchUpInside) @@ -159,14 +157,6 @@ final class RegionInfoView: UIView { completion() }, for: .touchUpInside) - self.addSubview(dismissButton) - NSLayoutConstraint.activate([ - dismissButton.widthAnchor.constraint(equalToConstant: 28), - dismissButton.heightAnchor.constraint(equalToConstant: 28), - dismissButton.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: -20), - dismissButton.topAnchor.constraint(equalTo: self.topAnchor, constant: 20) - ]) - self.addSubview(warningView) warningView.isHidden = true NSLayoutConstraint.activate([ @@ -175,6 +165,14 @@ final class RegionInfoView: UIView { warningView.topAnchor.constraint(equalTo: self.topAnchor), warningView.bottomAnchor.constraint(equalTo: self.bottomAnchor) ]) + + self.addSubview(dismissButton) + NSLayoutConstraint.activate([ + dismissButton.widthAnchor.constraint(equalToConstant: 28), + dismissButton.heightAnchor.constraint(equalToConstant: 28), + dismissButton.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: -20), + dismissButton.topAnchor.constraint(equalTo: self.topAnchor, constant: 20) + ]) } required init?(coder: NSCoder) { From 29129c597722a4be3ec1c583f82f49f94e9494f0 Mon Sep 17 00:00:00 2001 From: jeohong Date: Mon, 5 Dec 2022 17:38:12 +0900 Subject: [PATCH 03/27] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Lint=20=EA=B2=BD?= =?UTF-8?q?=EA=B3=A0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Workade/Managers/FirebaseManager.swift | 1 - .../CheckListDetailCell/CheckListDetailCell.swift | 2 +- .../Login/LoginName/LoginNameViewController.swift | 2 -- Workade/Views&ViewModels/MyPage/MyPageViewController.swift | 2 +- Workade/Views&ViewModels/MyPage/ProfileView.swift | 2 -- 5 files changed, 2 insertions(+), 7 deletions(-) diff --git a/Workade/Managers/FirebaseManager.swift b/Workade/Managers/FirebaseManager.swift index 8c043e3b..9f9fcd02 100644 --- a/Workade/Managers/FirebaseManager.swift +++ b/Workade/Managers/FirebaseManager.swift @@ -28,7 +28,6 @@ final class FirebaseManager: NSObject { authorizationController.presentationContextProvider = self } - func touchUpAppleButton(region: Region?, appleSignupCompletion: @escaping () -> Void, appleSigninCompletion: @escaping () -> Void) { self.region = region self.appleSigninCompletion = appleSigninCompletion diff --git a/Workade/Views&ViewModels/CheckList/CheckListDetail/CheckListDetailCell/CheckListDetailCell.swift b/Workade/Views&ViewModels/CheckList/CheckListDetail/CheckListDetailCell/CheckListDetailCell.swift index a65a49c5..19a92244 100644 --- a/Workade/Views&ViewModels/CheckList/CheckListDetail/CheckListDetailCell/CheckListDetailCell.swift +++ b/Workade/Views&ViewModels/CheckList/CheckListDetail/CheckListDetailCell/CheckListDetailCell.swift @@ -48,7 +48,7 @@ class CheckListDetailCell: UITableViewCell { func setupCell(todo: Todo) { checkButton.setImage(todo.done ? UIImage(systemName: "checkmark.circle.fill") : UIImage(systemName: "circle"), for: .normal) - checkButton.tintColor = todo.done ? .theme.workadeBlue : .theme.primary + checkButton.tintColor = todo.done ? .theme.workadeBlue : .theme.primary contentText.text = todo.content } } diff --git a/Workade/Views&ViewModels/Login/LoginName/LoginNameViewController.swift b/Workade/Views&ViewModels/Login/LoginName/LoginNameViewController.swift index 24a2fc81..9c6b698a 100644 --- a/Workade/Views&ViewModels/Login/LoginName/LoginNameViewController.swift +++ b/Workade/Views&ViewModels/Login/LoginName/LoginNameViewController.swift @@ -54,8 +54,6 @@ final class LoginNameViewController: UIViewController, UITextFieldDelegate { fatalError("init(coder:) has not been implemented") } - - override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .white diff --git a/Workade/Views&ViewModels/MyPage/MyPageViewController.swift b/Workade/Views&ViewModels/MyPage/MyPageViewController.swift index 93afb30d..1d46be3e 100644 --- a/Workade/Views&ViewModels/MyPage/MyPageViewController.swift +++ b/Workade/Views&ViewModels/MyPage/MyPageViewController.swift @@ -8,7 +8,7 @@ import Combine import UIKit -final class MyPageViewController: UIViewController { +final class MyPageViewController: UIViewController { // 특정 모서리만 둥글게 처리 참고 사이트 : https://swieeft.github.io/2020/03/05/UIViewRoundCorners.html private let profileView: ProfileView = { let profileView = ProfileView() diff --git a/Workade/Views&ViewModels/MyPage/ProfileView.swift b/Workade/Views&ViewModels/MyPage/ProfileView.swift index cb84ef86..ed53bbea 100644 --- a/Workade/Views&ViewModels/MyPage/ProfileView.swift +++ b/Workade/Views&ViewModels/MyPage/ProfileView.swift @@ -8,8 +8,6 @@ import UIKit class ProfileView: UIView { - // TODO: Login User 정보 ViewModel 사용 - let containerView: UIView = { let containerView = UIView() containerView.backgroundColor = .clear From 46f732d5c449ce022776e09836bf8336bee6823d Mon Sep 17 00:00:00 2001 From: jeohong Date: Mon, 5 Dec 2022 18:02:03 +0900 Subject: [PATCH 04/27] =?UTF-8?q?=E2=9C=A8=20=EC=8A=A4=ED=8B=B0=EC=BB=A4?= =?UTF-8?q?=20=EB=B9=84=EC=96=B4=EC=9E=88=EC=9D=84=EB=95=8C=20=ED=91=9C?= =?UTF-8?q?=EC=8B=9C=ED=95=98=EB=8A=94=20=EB=B7=B0=20=ED=8C=8C=EC=9D=BC?= =?UTF-8?q?=EC=9D=84=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Workade.xcodeproj/project.pbxproj | 8 ++++---- .../MyPage/EmptyStickeView.swift | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 Workade/Views&ViewModels/MyPage/EmptyStickeView.swift diff --git a/Workade.xcodeproj/project.pbxproj b/Workade.xcodeproj/project.pbxproj index 89fe260f..f4e23b8a 100644 --- a/Workade.xcodeproj/project.pbxproj +++ b/Workade.xcodeproj/project.pbxproj @@ -53,7 +53,6 @@ 2170C28F292BB0BC005146C3 /* ExploreViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2170C28E292BB0BC005146C3 /* ExploreViewController.swift */; }; 2170C291292C974B005146C3 /* ExploreViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2170C290292C974B005146C3 /* ExploreViewModel.swift */; }; 2170C293292CA689005146C3 /* RegionInfoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2170C292292CA689005146C3 /* RegionInfoView.swift */; }; - 21723FB8293BA3800064255C /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 21723FB7293BA3800064255C /* GoogleService-Info.plist */; }; 21862A912902675600518EBC /* GalleryDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21862A902902675500518EBC /* GalleryDetailViewController.swift */; }; 21862A93290280BD00518EBC /* CardTransitionManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21862A92290280BD00518EBC /* CardTransitionManager.swift */; }; 218DA403290B1AA90089F896 /* LaunchScreenAnimationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 218DA402290B1AA90089F896 /* LaunchScreenAnimationView.swift */; }; @@ -156,6 +155,7 @@ A35A982F290ADE1F00220755 /* MagazineViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A35A982E290ADE1F00220755 /* MagazineViewModel.swift */; }; A35B7096292CF6EE0083E0A2 /* RegionButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = A35B7095292CF6EE0083E0A2 /* RegionButton.swift */; }; A35BD48228FE85B200D1FA7C /* MagazineViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A35BD48128FE85B200D1FA7C /* MagazineViewController.swift */; }; + A3690FAE293DEAFF004B79F2 /* EmptyStickeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3690FAD293DEAFF004B79F2 /* EmptyStickeView.swift */; }; A37D28402923BC8F009F0ED6 /* NearbyPlaceImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A37D283F2923BC8F009F0ED6 /* NearbyPlaceImageView.swift */; }; A37D28422923BD53009F0ED6 /* NearbyPlaceDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A37D28412923BD53009F0ED6 /* NearbyPlaceDetailView.swift */; }; A37D28442923C62E009F0ED6 /* GalleryResource.swift in Sources */ = {isa = PBXBuildFile; fileRef = A37D28432923C62E009F0ED6 /* GalleryResource.swift */; }; @@ -218,7 +218,6 @@ 2170C28E292BB0BC005146C3 /* ExploreViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExploreViewController.swift; sourceTree = ""; }; 2170C290292C974B005146C3 /* ExploreViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExploreViewModel.swift; sourceTree = ""; }; 2170C292292CA689005146C3 /* RegionInfoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegionInfoView.swift; sourceTree = ""; }; - 21723FB7293BA3800064255C /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "GoogleService-Info.plist"; path = "../../Desktop/GoogleService-Info.plist"; sourceTree = ""; }; 21862A902902675500518EBC /* GalleryDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GalleryDetailViewController.swift; sourceTree = ""; }; 21862A92290280BD00518EBC /* CardTransitionManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardTransitionManager.swift; sourceTree = ""; }; 218DA402290B1AA90089F896 /* LaunchScreenAnimationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LaunchScreenAnimationView.swift; sourceTree = ""; }; @@ -316,6 +315,7 @@ A35A982E290ADE1F00220755 /* MagazineViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MagazineViewModel.swift; sourceTree = ""; }; A35B7095292CF6EE0083E0A2 /* RegionButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegionButton.swift; sourceTree = ""; }; A35BD48128FE85B200D1FA7C /* MagazineViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MagazineViewController.swift; sourceTree = ""; }; + A3690FAD293DEAFF004B79F2 /* EmptyStickeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyStickeView.swift; sourceTree = ""; }; A37D283F2923BC8F009F0ED6 /* NearbyPlaceImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NearbyPlaceImageView.swift; sourceTree = ""; }; A37D28412923BD53009F0ED6 /* NearbyPlaceDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NearbyPlaceDetailView.swift; sourceTree = ""; }; A37D28432923C62E009F0ED6 /* GalleryResource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GalleryResource.swift; sourceTree = ""; }; @@ -599,7 +599,6 @@ isa = PBXGroup; children = ( 5FDC17D228FE7A900060DBB7 /* .swiftlint.yml */, - 21723FB7293BA3800064255C /* GoogleService-Info.plist */, 5FDC17B928FE799C0060DBB7 /* Workade */, 5FDC17B828FE799C0060DBB7 /* Products */, B7DE360250B0A3F5EC254C91 /* Pods */, @@ -740,6 +739,7 @@ A354F476292625F5003E601A /* ProfileView.swift */, A354F47829262615003E601A /* StickerView.swift */, A354F47A29263C52003E601A /* StickerCollectionViewCell.swift */, + A3690FAD293DEAFF004B79F2 /* EmptyStickeView.swift */, A3BB02BB2926A7C8000DE275 /* EditProfile */, 9646763D2909346A0047ED34 /* Setting */, ); @@ -925,7 +925,6 @@ 5FDC17D328FE7A900060DBB7 /* .swiftlint.yml in Resources */, 21F6DE5D28FFED5D00ED72C6 /* Pretendard-Regular.otf in Resources */, 2103BBA929261F4D00BBCB2C /* Satoshi-Medium.otf in Resources */, - 21723FB8293BA3800064255C /* GoogleService-Info.plist in Resources */, 21F6DE5E28FFED5D00ED72C6 /* Pretendard-Bold.otf in Resources */, 5FDC17CA28FE799D0060DBB7 /* LaunchScreen.storyboard in Resources */, 21F6DE5C28FFED5D00ED72C6 /* Pretendard-SemiBold.otf in Resources */, @@ -1128,6 +1127,7 @@ 5FDC17BB28FE799C0060DBB7 /* AppDelegate.swift in Sources */, 21DF04BC2907E9BE007B6270 /* EmojiPickerController.swift in Sources */, A3CBB16629275F97009AD4E1 /* UITextField+.swift in Sources */, + A3690FAE293DEAFF004B79F2 /* EmptyStickeView.swift in Sources */, A3479C96292BA84800AE1528 /* LoginInformationView.swift in Sources */, A35A982F290ADE1F00220755 /* MagazineViewModel.swift in Sources */, 96B1836E290148D4009F2BC6 /* OfficeCollectionViewCell.swift in Sources */, diff --git a/Workade/Views&ViewModels/MyPage/EmptyStickeView.swift b/Workade/Views&ViewModels/MyPage/EmptyStickeView.swift new file mode 100644 index 00000000..990a78f3 --- /dev/null +++ b/Workade/Views&ViewModels/MyPage/EmptyStickeView.swift @@ -0,0 +1,20 @@ +// +// EmptyStickeView.swift +// Workade +// +// Created by Hong jeongmin on 2022/12/05. +// + +import UIKit + +class EmptyStickeView: UIView { + + /* + // Only override draw() if you perform custom drawing. + // An empty implementation adversely affects performance during animation. + override func draw(_ rect: CGRect) { + // Drawing code + } + */ + +} From b35080ee3fa5aab911ceb554886d5194f245fae2 Mon Sep 17 00:00:00 2001 From: jeohong Date: Mon, 5 Dec 2022 18:10:11 +0900 Subject: [PATCH 05/27] =?UTF-8?q?=E2=9C=A8=20=EB=B9=84=EC=96=B4=EC=9E=88?= =?UTF-8?q?=EB=8A=94=20=EC=8A=A4=ED=8B=B0=EC=BB=A4=20=EB=B7=B0=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MyPage/EmptyStickeView.swift | 49 ++++++++++++++++--- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/Workade/Views&ViewModels/MyPage/EmptyStickeView.swift b/Workade/Views&ViewModels/MyPage/EmptyStickeView.swift index 990a78f3..58d1c7b6 100644 --- a/Workade/Views&ViewModels/MyPage/EmptyStickeView.swift +++ b/Workade/Views&ViewModels/MyPage/EmptyStickeView.swift @@ -8,13 +8,46 @@ import UIKit class EmptyStickeView: UIView { - - /* - // Only override draw() if you perform custom drawing. - // An empty implementation adversely affects performance during animation. - override func draw(_ rect: CGRect) { - // Drawing code + private let emptyStickerImageView: UIImageView = { + let imageView = UIImageView(image: UIImage(named: "blank")) + imageView.contentMode = .scaleAspectFit + imageView.translatesAutoresizingMaskIntoConstraints = false + + return imageView + }() + + private let emptyStickerLabel: UILabel = { + let label = UILabel() + label.text = "워케이션을 해서 스티커를 획득하세요!" + label.font = .customFont(for: .captionHeadline) + label.textColor = .theme.primary + label.numberOfLines = 1 + label.translatesAutoresizingMaskIntoConstraints = false + + return label + }() + + override init(frame: CGRect) { + super.init(frame: frame) + + setupLayout() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + private func setupLayout() { + addSubview(emptyStickerImageView) + NSLayoutConstraint.activate([ + emptyStickerImageView.centerXAnchor.constraint(equalTo: centerXAnchor), + emptyStickerImageView.centerYAnchor.constraint(equalTo: centerYAnchor) + ]) + + addSubview(emptyStickerLabel) + NSLayoutConstraint.activate([ + emptyStickerLabel.centerXAnchor.constraint(equalTo: centerXAnchor), + emptyStickerLabel.topAnchor.constraint(equalTo: emptyStickerImageView.bottomAnchor, constant: 20) + ]) } - */ - } From cde01edc96b1dea033521a3affb2583c5b9744af Mon Sep 17 00:00:00 2001 From: jeohong Date: Mon, 5 Dec 2022 18:13:57 +0900 Subject: [PATCH 06/27] =?UTF-8?q?=E2=9C=A8=20=EA=B0=80=EC=A7=80=EA=B3=A0?= =?UTF-8?q?=20=EC=9E=88=EB=8A=94=20=EC=8A=A4=ED=8B=B0=EC=BB=A4=EA=B0=80=20?= =?UTF-8?q?=EC=97=86=EC=9D=84=EB=95=8C=20emptyStickerView=20=ED=98=B8?= =?UTF-8?q?=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MyPage/MyPageViewController.swift | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Workade/Views&ViewModels/MyPage/MyPageViewController.swift b/Workade/Views&ViewModels/MyPage/MyPageViewController.swift index 1d46be3e..046f82f6 100644 --- a/Workade/Views&ViewModels/MyPage/MyPageViewController.swift +++ b/Workade/Views&ViewModels/MyPage/MyPageViewController.swift @@ -30,10 +30,21 @@ final class MyPageViewController: UIViewController { return stickerView }() + private let emptyStickerView: EmptyStickeView = { + let emptyStickerView = EmptyStickeView() + emptyStickerView.translatesAutoresizingMaskIntoConstraints = false + emptyStickerView.layer.cornerRadius = 30 + emptyStickerView.layer.maskedCorners = CACornerMask(arrayLiteral: .layerMinXMinYCorner, .layerMaxXMinYCorner) + emptyStickerView.backgroundColor = .theme.background + + return emptyStickerView + }() + override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .theme.primary + setupStickerView() editProfileButtonTapped() setupNavigationBar() setupLayout() @@ -60,6 +71,22 @@ final class MyPageViewController: UIViewController { // TODO: Combine이던, Binder던 콜렉션뷰 reload해야할것 같음 } + + func setupStickerView() { + guard let stickersArray = UserManager.shared.user.value?.stickers else { + emptyStickerView.isHidden = false + stickerView.isHidden = true + return + } + + if stickersArray.count == 0 { + emptyStickerView.isHidden = false + stickerView.isHidden = true + } else { + emptyStickerView.isHidden = true + stickerView.isHidden = false + } + } } // MARK: UI setup 관련 Methods @@ -101,5 +128,13 @@ private extension MyPageViewController { stickerView.leadingAnchor.constraint(equalTo: view.leadingAnchor), stickerView.trailingAnchor.constraint(equalTo: view.trailingAnchor) ]) + + view.addSubview(emptyStickerView) + NSLayoutConstraint.activate([ + emptyStickerView.topAnchor.constraint(equalTo: profileView.bottomAnchor, constant: 4), + emptyStickerView.bottomAnchor.constraint(equalTo: view.bottomAnchor), + emptyStickerView.leadingAnchor.constraint(equalTo: view.leadingAnchor), + emptyStickerView.trailingAnchor.constraint(equalTo: view.trailingAnchor) + ]) } } From 9361197d854da1c6642877f6dcf52cdd5429a72f Mon Sep 17 00:00:00 2001 From: jeohong Date: Mon, 5 Dec 2022 18:14:25 +0900 Subject: [PATCH 07/27] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=EB=AC=B8=EA=B5=AC?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Workade/Views&ViewModels/MyPage/EmptyStickeView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Workade/Views&ViewModels/MyPage/EmptyStickeView.swift b/Workade/Views&ViewModels/MyPage/EmptyStickeView.swift index 58d1c7b6..c6c94c7c 100644 --- a/Workade/Views&ViewModels/MyPage/EmptyStickeView.swift +++ b/Workade/Views&ViewModels/MyPage/EmptyStickeView.swift @@ -18,7 +18,7 @@ class EmptyStickeView: UIView { private let emptyStickerLabel: UILabel = { let label = UILabel() - label.text = "워케이션을 해서 스티커를 획득하세요!" + label.text = "각 지역별 워케이션을 통해 스티커를 획득하세요!" label.font = .customFont(for: .captionHeadline) label.textColor = .theme.primary label.numberOfLines = 1 From 7841f06b9c52b7b92addf40759efcbfd2761c0dc Mon Sep 17 00:00:00 2001 From: jeohong Date: Mon, 5 Dec 2022 18:20:59 +0900 Subject: [PATCH 08/27] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=ED=85=8D=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BB=AC=EB=9F=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Workade/Views&ViewModels/MyPage/EmptyStickeView.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Workade/Views&ViewModels/MyPage/EmptyStickeView.swift b/Workade/Views&ViewModels/MyPage/EmptyStickeView.swift index c6c94c7c..d0bca076 100644 --- a/Workade/Views&ViewModels/MyPage/EmptyStickeView.swift +++ b/Workade/Views&ViewModels/MyPage/EmptyStickeView.swift @@ -18,10 +18,11 @@ class EmptyStickeView: UIView { private let emptyStickerLabel: UILabel = { let label = UILabel() - label.text = "각 지역별 워케이션을 통해 스티커를 획득하세요!" + label.text = "각 지역별 워케이션을 통해\n스티커를 획득하세요!" label.font = .customFont(for: .captionHeadline) - label.textColor = .theme.primary - label.numberOfLines = 1 + label.textColor = .theme.tertiary + label.numberOfLines = 0 + label.textAlignment = .center label.translatesAutoresizingMaskIntoConstraints = false return label From d840e51b7e25d6068a75f9963ac73d3fa7ccada4 Mon Sep 17 00:00:00 2001 From: ryu Date: Wed, 7 Dec 2022 23:09:33 +0900 Subject: [PATCH 09/27] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=20=EC=A7=81?= =?UTF-8?q?=EC=97=85=20=EB=9D=BC=EB=B2=A8=20=EC=83=89=EA=B9=94=20=ED=98=84?= =?UTF-8?q?=EC=9E=AC=20=EC=A7=81=EC=97=85=EC=97=90=20=EB=A7=9E=EA=B2=8C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WorkerStatusSheetViewController.swift | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Workade/Views&ViewModels/Workation/WorkerStatusSheet/WorkerStatusSheetViewController.swift b/Workade/Views&ViewModels/Workation/WorkerStatusSheet/WorkerStatusSheetViewController.swift index d042cf7a..9660cf63 100644 --- a/Workade/Views&ViewModels/Workation/WorkerStatusSheet/WorkerStatusSheetViewController.swift +++ b/Workade/Views&ViewModels/Workation/WorkerStatusSheet/WorkerStatusSheetViewController.swift @@ -86,8 +86,8 @@ class WorkerStatusSheetViewController: UIViewController { private lazy var numberOfWorkersStack: UIStackView = { let firstStack = UIStackView(arrangedSubviews: [ - jobLabel(job: Job.designer, number: 0, isMyJob: true), - jobLabel(job: Job.developer, number: 0, isMyJob: false) + jobLabel(job: Job.designer, number: 0, isMyJob: UserManager.shared.activeMyInfo?.job == Job.designer), + jobLabel(job: Job.developer, number: 0, isMyJob: UserManager.shared.activeMyInfo?.job == Job.developer) ]) firstStack.axis = .horizontal @@ -95,31 +95,31 @@ class WorkerStatusSheetViewController: UIViewController { firstStack.spacing = 30 let secondStack = UIStackView(arrangedSubviews: [ - jobLabel(job: Job.writer, number: 0, isMyJob: false), - jobLabel(job: Job.PM, number: 0, isMyJob: false) + jobLabel(job: Job.writer, number: 0, isMyJob: UserManager.shared.activeMyInfo?.job == Job.writer), + jobLabel(job: Job.PM, number: 0, isMyJob: UserManager.shared.activeMyInfo?.job == Job.PM) ]) secondStack.axis = .horizontal secondStack.distribution = .fillEqually secondStack.spacing = 30 let thirdStack = UIStackView(arrangedSubviews: [ - jobLabel(job: Job.creater, number: 0, isMyJob: false), - jobLabel(job: Job.marketer, number: 0, isMyJob: false) + jobLabel(job: Job.creater, number: 0, isMyJob: UserManager.shared.activeMyInfo?.job == Job.creater), + jobLabel(job: Job.marketer, number: 0, isMyJob: UserManager.shared.activeMyInfo?.job == Job.marketer) ]) thirdStack.axis = .horizontal thirdStack.distribution = .fillEqually thirdStack.spacing = 30 let fourthStack = UIStackView(arrangedSubviews: [ - jobLabel(job: Job.artist, number: 0, isMyJob: false), - jobLabel(job: Job.freelancer, number: 0, isMyJob: false) + jobLabel(job: Job.artist, number: 0, isMyJob: UserManager.shared.activeMyInfo?.job == Job.artist), + jobLabel(job: Job.freelancer, number: 0, isMyJob: UserManager.shared.activeMyInfo?.job == Job.freelancer) ]) fourthStack.axis = .horizontal fourthStack.distribution = .fillEqually fourthStack.spacing = 30 let fifthStack = UIStackView(arrangedSubviews: [ - jobLabel(job: Job.etc, number: 0, isMyJob: false), + jobLabel(job: Job.etc, number: 0, isMyJob: UserManager.shared.activeMyInfo?.job == Job.etc), UIView() ]) fifthStack.axis = .horizontal From a19d3514753722fa7238082096d9bd3366b96319 Mon Sep 17 00:00:00 2001 From: Wonhyuk Choi Date: Wed, 28 Dec 2022 22:10:15 +0900 Subject: [PATCH 10/27] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20activeUser=20?= =?UTF-8?q?=EC=93=B0=EA=B8=B0=20=EB=B0=98=EB=B3=B5=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Workade/AppDelegate.swift | 3 ++- Workade/Assets.xcassets/Sticker/Contents.json | 6 ----- .../Sticker/halLaBong.imageset/Contents.json | 12 ---------- .../sticker/horse.imageset/Contents.json | 12 ---------- .../sticker/horse.imageset/horse.svg | 24 ------------------- 5 files changed, 2 insertions(+), 55 deletions(-) delete mode 100644 Workade/Assets.xcassets/Sticker/Contents.json delete mode 100644 Workade/Assets.xcassets/Sticker/halLaBong.imageset/Contents.json delete mode 100644 Workade/Assets.xcassets/sticker/horse.imageset/Contents.json delete mode 100644 Workade/Assets.xcassets/sticker/horse.imageset/horse.svg diff --git a/Workade/AppDelegate.swift b/Workade/AppDelegate.swift index e47247ca..3f6d74f0 100644 --- a/Workade/AppDelegate.swift +++ b/Workade/AppDelegate.swift @@ -18,7 +18,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. - NMFAuthManager.shared().clientId = "KEY" + NMFAuthManager.shared().clientId = "73fuvr2j6i" + KakaoSDK.initSDK(appKey: "beed144107e0a7f9f2886481b17872ff") FirebaseApp.configure() return true } diff --git a/Workade/Assets.xcassets/Sticker/Contents.json b/Workade/Assets.xcassets/Sticker/Contents.json deleted file mode 100644 index 73c00596..00000000 --- a/Workade/Assets.xcassets/Sticker/Contents.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "info" : { - "author" : "xcode", - "version" : 1 - } -} diff --git a/Workade/Assets.xcassets/Sticker/halLaBong.imageset/Contents.json b/Workade/Assets.xcassets/Sticker/halLaBong.imageset/Contents.json deleted file mode 100644 index c8c41604..00000000 --- a/Workade/Assets.xcassets/Sticker/halLaBong.imageset/Contents.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "images" : [ - { - "filename" : "halLaBong.svg", - "idiom" : "universal" - } - ], - "info" : { - "author" : "xcode", - "version" : 1 - } -} diff --git a/Workade/Assets.xcassets/sticker/horse.imageset/Contents.json b/Workade/Assets.xcassets/sticker/horse.imageset/Contents.json deleted file mode 100644 index 62d66297..00000000 --- a/Workade/Assets.xcassets/sticker/horse.imageset/Contents.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "images" : [ - { - "filename" : "horse.svg", - "idiom" : "universal" - } - ], - "info" : { - "author" : "xcode", - "version" : 1 - } -} diff --git a/Workade/Assets.xcassets/sticker/horse.imageset/horse.svg b/Workade/Assets.xcassets/sticker/horse.imageset/horse.svg deleted file mode 100644 index ee299982..00000000 --- a/Workade/Assets.xcassets/sticker/horse.imageset/horse.svg +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - From 481e6017ac4041139b92a63c552c4e1da41f9149 Mon Sep 17 00:00:00 2001 From: Wonhyuk Choi Date: Wed, 28 Dec 2022 22:19:16 +0900 Subject: [PATCH 11/27] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20activeUser=20?= =?UTF-8?q?=EC=93=B0=EA=B8=B0=20=EB=B0=98=EB=B3=B5=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Workation/WorkationViewController.swift | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/Workade/Views&ViewModels/Workation/WorkationViewController.swift b/Workade/Views&ViewModels/Workation/WorkationViewController.swift index 54662e6c..979353df 100644 --- a/Workade/Views&ViewModels/Workation/WorkationViewController.swift +++ b/Workade/Views&ViewModels/Workation/WorkationViewController.swift @@ -15,7 +15,6 @@ final class WorkationViewController: UIViewController { var dismissAction: (() -> Void)? var cancellable = Set() - var activeUserCancellable: AnyCancellable? = nil let canGetStickers: [StickerTitle] = [ .halLaBong, .dolHaReuBang, .horse, .halLaSan @@ -201,7 +200,6 @@ final class WorkationViewController: UIViewController { alert.addAction(UIAlertAction(title: "종료", style: .destructive, handler: { [weak self] _ in Task { [weak self] in guard let self = self, var user = UserManager.shared.user.value else { return } - self.activeUserCancellable?.cancel() try? await FirestoreDAO.shared.deleteActiveUser(userID: user.id, region: self.region) try? await FirestoreDAO.shared.createUser(user: User(id: user.id, name: user.name, email: user.email, job: user.job, stickers: user.stickers, activeRegion: nil)) } @@ -323,6 +321,7 @@ final class WorkationViewController: UIViewController { setupLayout() setupNavigationBar() + setupProgressDay() bind() } @@ -430,6 +429,19 @@ private extension WorkationViewController { bottomBottomStack.bottomAnchor.constraint(equalTo: bottomPaneView.bottomAnchor, constant: -34) ]) } + + private func setupProgressDay() { + guard var user = UserManager.shared.activeMyInfo else { return } + let offsetDate = Date().timeIntervalSince(user.startDate) + let day = Int(offsetDate/86400) + print(user.progressDay!, day) + if let storedDay = user.progressDay, storedDay != day { + self.compareProgressDay(presentDay: day, storedDay: storedDay) + user.progressDay = day + self.updateActiveUser(user: user) + } + self.dayLabel.text = "\(day)일째" + } } extension WorkationViewController { @@ -455,33 +467,25 @@ extension WorkationViewController { DispatchQueue.main.async { let offsetDate = Date().timeIntervalSince(user.startDate) let day = Int(ceil(offsetDate/86400)) - if let storedDay = user.progressDay { + if let storedDay = user.progressDay, storedDay != day { self.compareProgressDay(presentDay: day, storedDay: storedDay) + user.progressDay = day + self.updateActiveUser(user: user) } - user.progressDay = day - self.updateActiveUser(user: user) self.dayLabel.text = "\(day)일째" } } .store(in: &cancellable) - activeUserCancellable = UserManager.shared.$activeMyInfo + UserManager.shared.$activeMyInfo .sink { [weak self] user in guard let self = self, var user = user else { return } DispatchQueue.main.async { - let offsetDate = Date().timeIntervalSince(user.startDate) - let day = Int(offsetDate/86400) - if let storedDay = user.progressDay { - self.compareProgressDay(presentDay: day, storedDay: storedDay) - } - user.progressDay = day - self.updateActiveUser(user: user) - self.dayLabel.text = "\(day)일째" - self.bottomPaneView.isHidden = false self.loginPaneView.isHidden = true } } + .store(in: &cancellable) } private func updateActiveUser(user: ActiveUser) { From 37e6ac1038cde95fc5753623e7430132dcdfddf3 Mon Sep 17 00:00:00 2001 From: Wonhyuk Choi Date: Wed, 28 Dec 2022 22:10:15 +0900 Subject: [PATCH 12/27] =?UTF-8?q?Revert=20"=E2=99=BB=EF=B8=8F=20activeUser?= =?UTF-8?q?=20=EC=93=B0=EA=B8=B0=20=EB=B0=98=EB=B3=B5=20=EC=98=A4=EB=A5=98?= =?UTF-8?q?=20=EC=88=98=EC=A0=95"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit a19d3514753722fa7238082096d9bd3366b96319. --- Workade/AppDelegate.swift | 3 +-- .../{Sticker => sticker}/horse.imageset/Contents.json | 0 .../{Sticker => sticker}/horse.imageset/horse.svg | 0 3 files changed, 1 insertion(+), 2 deletions(-) rename Workade/Assets.xcassets/{Sticker => sticker}/horse.imageset/Contents.json (100%) rename Workade/Assets.xcassets/{Sticker => sticker}/horse.imageset/horse.svg (100%) diff --git a/Workade/AppDelegate.swift b/Workade/AppDelegate.swift index 3f6d74f0..e47247ca 100644 --- a/Workade/AppDelegate.swift +++ b/Workade/AppDelegate.swift @@ -18,8 +18,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. - NMFAuthManager.shared().clientId = "73fuvr2j6i" - KakaoSDK.initSDK(appKey: "beed144107e0a7f9f2886481b17872ff") + NMFAuthManager.shared().clientId = "KEY" FirebaseApp.configure() return true } diff --git a/Workade/Assets.xcassets/Sticker/horse.imageset/Contents.json b/Workade/Assets.xcassets/sticker/horse.imageset/Contents.json similarity index 100% rename from Workade/Assets.xcassets/Sticker/horse.imageset/Contents.json rename to Workade/Assets.xcassets/sticker/horse.imageset/Contents.json diff --git a/Workade/Assets.xcassets/Sticker/horse.imageset/horse.svg b/Workade/Assets.xcassets/sticker/horse.imageset/horse.svg similarity index 100% rename from Workade/Assets.xcassets/Sticker/horse.imageset/horse.svg rename to Workade/Assets.xcassets/sticker/horse.imageset/horse.svg From 054db4cb6517d28f3580a870612e339b052a6a44 Mon Sep 17 00:00:00 2001 From: Inho Choi Date: Thu, 8 Dec 2022 00:45:42 +0900 Subject: [PATCH 13/27] =?UTF-8?q?:bug:=20WorkerStatusView=20=EB=8F=99?= =?UTF-8?q?=EA=B8=B0=ED=99=94=20=EB=AC=B8=EC=A0=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Workade.xcodeproj/project.pbxproj | 4 -- Workade/Managers/FirebaseManager.swift | 2 +- Workade/Managers/FirestoreManager.swift | 25 ++++++------ Workade/Managers/UserManager.swift | 4 +- .../Workation/WorkationViewController.swift | 2 +- .../WorkerStatusSheetViewController.swift | 10 +++-- .../WorkerStatusSheetViewModel.swift | 38 ------------------- 7 files changed, 21 insertions(+), 64 deletions(-) delete mode 100644 Workade/Views&ViewModels/Workation/WorkerStatusSheet/WorkerStatusSheetViewModel.swift diff --git a/Workade.xcodeproj/project.pbxproj b/Workade.xcodeproj/project.pbxproj index f4e23b8a..cad200f4 100644 --- a/Workade.xcodeproj/project.pbxproj +++ b/Workade.xcodeproj/project.pbxproj @@ -99,7 +99,6 @@ 5FBADE5029056811008CCC58 /* MapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FBADE4F29056811008CCC58 /* MapViewController.swift */; }; 5FD1F5D2290A6BCB00744CCC /* MapPinModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FD1F5D1290A6BCB00744CCC /* MapPinModel.swift */; }; 5FD22E90290B17E2003CF909 /* MapViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FD22E8E290B17E2003CF909 /* MapViewModel.swift */; }; - 5FDC11D729388D9F00CDA4EC /* WorkerStatusSheetViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FDC11D629388D9F00CDA4EC /* WorkerStatusSheetViewModel.swift */; }; 5FDC17BB28FE799C0060DBB7 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FDC17BA28FE799C0060DBB7 /* AppDelegate.swift */; }; 5FDC17BD28FE799C0060DBB7 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FDC17BC28FE799C0060DBB7 /* SceneDelegate.swift */; }; 5FDC17BF28FE799C0060DBB7 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FDC17BE28FE799C0060DBB7 /* ViewController.swift */; }; @@ -256,7 +255,6 @@ 5FBADE4F29056811008CCC58 /* MapViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapViewController.swift; sourceTree = ""; }; 5FD1F5D1290A6BCB00744CCC /* MapPinModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapPinModel.swift; sourceTree = ""; }; 5FD22E8E290B17E2003CF909 /* MapViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapViewModel.swift; sourceTree = ""; }; - 5FDC11D629388D9F00CDA4EC /* WorkerStatusSheetViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorkerStatusSheetViewModel.swift; sourceTree = ""; }; 5FDC17B728FE799C0060DBB7 /* Workade.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Workade.app; sourceTree = BUILT_PRODUCTS_DIR; }; 5FDC17BA28FE799C0060DBB7 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 5FDC17BC28FE799C0060DBB7 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; @@ -431,7 +429,6 @@ isa = PBXGroup; children = ( 169E1F03292A7F3D007F9E0A /* WorkerStatusSheetViewController.swift */, - 5FDC11D629388D9F00CDA4EC /* WorkerStatusSheetViewModel.swift */, ); path = WorkerStatusSheet; sourceTree = ""; @@ -1120,7 +1117,6 @@ 21862A93290280BD00518EBC /* CardTransitionManager.swift in Sources */, 961CC485290AF80500921F24 /* BookmarkManager.swift in Sources */, 21862A912902675600518EBC /* GalleryDetailViewController.swift in Sources */, - 5FDC11D729388D9F00CDA4EC /* WorkerStatusSheetViewModel.swift in Sources */, 16CBD46E29040D960056A641 /* CheckListViewModel.swift in Sources */, 2163F30B290958A0007CB6DC /* CheckListTemplateResource.swift in Sources */, 21F6DE6228FFEE2100ED72C6 /* DesignSystem.swift in Sources */, diff --git a/Workade/Managers/FirebaseManager.swift b/Workade/Managers/FirebaseManager.swift index 9f9fcd02..fa6f0954 100644 --- a/Workade/Managers/FirebaseManager.swift +++ b/Workade/Managers/FirebaseManager.swift @@ -53,7 +53,7 @@ final class FirebaseManager: NSObject { do { try Auth.auth().signOut() if UserManager.shared.user.value?.activeRegion != nil, - let region = UserManager.shared.activeRegion, + let region = UserManager.shared.user.value?.activeRegion, let id = UserManager.shared.user.value?.id { Task { try await FirestoreDAO.shared.deleteActiveUser(userID: id, region: region) diff --git a/Workade/Managers/FirestoreManager.swift b/Workade/Managers/FirestoreManager.swift index 886be0c2..4c01dc88 100644 --- a/Workade/Managers/FirestoreManager.swift +++ b/Workade/Managers/FirestoreManager.swift @@ -35,20 +35,20 @@ class FirestoreDAO { guard let data = user.asDictionary else { return } try await dto.createDocument(collectionName: allUserCollectionName, documentName: user.id, data: data) UserManager.shared.user.value = user - UserManager.shared.isActive = (user.activeRegion != nil) +// UserManager.shared.isActive = (user.activeRegion != nil) } func updateUser(user: User) async throws { guard let data = user.asDictionary else { return } try await dto.updateDocument(collectionName: allUserCollectionName, documentName: user.id, data: data) UserManager.shared.user.value = user - UserManager.shared.isActive = (user.activeRegion != nil) +// UserManager.shared.isActive = (user.activeRegion != nil) } func deleteUser(userid: String) async throws { try await dto.deleteDocument(collectionName: allUserCollectionName, documentName: userid) UserManager.shared.user.value = nil - UserManager.shared.isActive = false +// UserManager.shared.isActive = false } func getUser(userID: String) async throws -> User? { @@ -61,7 +61,7 @@ class FirestoreDAO { let user = try decoder.decode(User.self, from: jsonData) UserManager.shared.user.value = user if user.id == userID { - UserManager.shared.isActive = (user.activeRegion != nil) +// UserManager.shared.isActive = (user.activeRegion != nil) return user } } @@ -71,8 +71,8 @@ class FirestoreDAO { func createActiveUser(user: ActiveUser) async throws { guard let data = user.asDictionary else { return } try await dto.createDocument(collectionName: user.region.rawValue, documentName: user.id, data: data) - UserManager.shared.isActive = true - UserManager.shared.activeRegion = user.region +// UserManager.shared.isActive = true +// UserManager.shared.activeRegion = user.region UserManager.shared.activeMyInfo = user } @@ -83,9 +83,9 @@ class FirestoreDAO { func deleteActiveUser(userID: String, region: Region) async throws { try await dto.deleteDocument(collectionName: region.rawValue, documentName: userID) - UserManager.shared.activeRegion = nil +// UserManager.shared.activeRegion = nil UserManager.shared.activeMyInfo = nil - UserManager.shared.isActive = false +// UserManager.shared.isActive = false } func getActiveUsersNumber(region: Region) async throws -> Int { @@ -101,19 +101,16 @@ class FirestoreDAO { UserManager.shared.activeMyInfo = activeUser } - func getActiveUsers(region: Region) async throws -> [Job: [ActiveUser]]? { + func getActiveUsers(region: Region) async throws -> [ActiveUser]? { let documents = try await dto.getDocuments(collectionName: region.rawValue) let decoder = JSONDecoder() - var users = [Job: [ActiveUser]]() - for job in Job.allCases { - users[job] = [] - } + var users = [ActiveUser]() for document in documents { let data = document.data() let jsonData = try JSONSerialization.data(withJSONObject: data) let activeUser = try decoder.decode(ActiveUser.self, from: jsonData) - users[activeUser.job]?.append(activeUser) + users.append(activeUser) } return users } diff --git a/Workade/Managers/UserManager.swift b/Workade/Managers/UserManager.swift index 4168f56f..6d46b6c1 100644 --- a/Workade/Managers/UserManager.swift +++ b/Workade/Managers/UserManager.swift @@ -21,9 +21,7 @@ class UserManager { var user = CurrentValueSubject(nil) - var activeUsers = [Region: [Job: [ActiveUser]]]() - @Published var isActive = false - var activeRegion: Region? = nil + var activeUsers = [Region: [ActiveUser]]() @Published var activeMyInfo: ActiveUser? = nil diff --git a/Workade/Views&ViewModels/Workation/WorkationViewController.swift b/Workade/Views&ViewModels/Workation/WorkationViewController.swift index 979353df..8f5abc93 100644 --- a/Workade/Views&ViewModels/Workation/WorkationViewController.swift +++ b/Workade/Views&ViewModels/Workation/WorkationViewController.swift @@ -351,7 +351,7 @@ private extension WorkationViewController { private func setupLayout() { let guide = view.safeAreaLayoutGuide - if UserManager.shared.isActive { + if UserManager.shared.user.value?.activeRegion != nil { bottomPaneView.isHidden = false loginPaneView.isHidden = true } diff --git a/Workade/Views&ViewModels/Workation/WorkerStatusSheet/WorkerStatusSheetViewController.swift b/Workade/Views&ViewModels/Workation/WorkerStatusSheet/WorkerStatusSheetViewController.swift index 9660cf63..e05d9ee2 100644 --- a/Workade/Views&ViewModels/Workation/WorkerStatusSheet/WorkerStatusSheetViewController.swift +++ b/Workade/Views&ViewModels/Workation/WorkerStatusSheet/WorkerStatusSheetViewController.swift @@ -13,8 +13,6 @@ class WorkerStatusSheetViewController: UIViewController { private let region: Region var viewDidDissmiss: (() -> Void)? - private lazy var workerStatusSheetViewModel = WorkerStatusSheetViewModel(region: region) - private lazy var backgroundView = UIView(frame: view.frame) private lazy var containerView: UIView = { @@ -73,7 +71,13 @@ class WorkerStatusSheetViewController: UIViewController { label.font = .customFont(for: .footnote) label.textColor = isMyJob ? .theme.workadeBlue : .theme.secondary - if let count = UserManager.shared.activeUsers[region]?[job]?.count { + if let users = UserManager.shared.activeUsers[region] { + var count = 0 + for user in users { + if user.job == job { + count += 1 + } + } let fullText = "\(job.rawValue) \(count)명" let attributedString = NSMutableAttributedString(string: fullText) let range = (fullText as NSString).range(of: "\(count)명") diff --git a/Workade/Views&ViewModels/Workation/WorkerStatusSheet/WorkerStatusSheetViewModel.swift b/Workade/Views&ViewModels/Workation/WorkerStatusSheet/WorkerStatusSheetViewModel.swift deleted file mode 100644 index e5b52168..00000000 --- a/Workade/Views&ViewModels/Workation/WorkerStatusSheet/WorkerStatusSheetViewModel.swift +++ /dev/null @@ -1,38 +0,0 @@ -// -// WorkerStatusSheetViewModel.swift -// Workade -// -// Created by Inho Choi on 2022/12/01. -// - -import Combine -import Foundation - -@MainActor -class WorkerStatusSheetViewModel { - var numberOfDesigner = CurrentValueSubject(0) - var numberOfDeveloper = CurrentValueSubject(0) - var numberOfWriter = CurrentValueSubject(0) - var numberOfPM = CurrentValueSubject(0) - var numberOfCreator = CurrentValueSubject(0) - var numberOfMarketer = CurrentValueSubject(0) - var numberOfArtist = CurrentValueSubject(0) - var numberOfFreelancer = CurrentValueSubject(0) - var numberOfEtc = CurrentValueSubject(0) - - init(region: Region) { - Task { - let activeUsers = UserManager.shared.activeUsers[region] - numberOfPM.value = activeUsers?[Job.PM]?.count ?? 0 - numberOfDesigner.value = activeUsers?[Job.designer]?.count ?? 0 - numberOfDeveloper.value = activeUsers?[Job.developer]?.count ?? 0 - print(numberOfDeveloper.value) - numberOfWriter.value = activeUsers?[Job.writer]?.count ?? 0 - numberOfCreator.value = activeUsers?[Job.creater]?.count ?? 0 - numberOfMarketer.value = activeUsers?[Job.marketer]?.count ?? 0 - numberOfArtist.value = activeUsers?[Job.artist]?.count ?? 0 - numberOfFreelancer.value = activeUsers?[Job.freelancer]?.count ?? 0 - numberOfEtc.value = activeUsers?[Job.etc]?.count ?? 0 - } - } -} From 65de6977146e11b3f1e843d80c5530928878adab Mon Sep 17 00:00:00 2001 From: Inho Choi Date: Thu, 8 Dec 2022 01:06:47 +0900 Subject: [PATCH 14/27] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20=EB=A6=B0=ED=8A=B8?= =?UTF-8?q?=20Warning=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Workation/WorkationViewController.swift | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Workade/Views&ViewModels/Workation/WorkationViewController.swift b/Workade/Views&ViewModels/Workation/WorkationViewController.swift index 8f5abc93..86baf881 100644 --- a/Workade/Views&ViewModels/Workation/WorkationViewController.swift +++ b/Workade/Views&ViewModels/Workation/WorkationViewController.swift @@ -479,10 +479,12 @@ extension WorkationViewController { UserManager.shared.$activeMyInfo .sink { [weak self] user in - guard let self = self, var user = user else { return } - DispatchQueue.main.async { - self.bottomPaneView.isHidden = false - self.loginPaneView.isHidden = true + guard let self = self else { return } + if user != nil { + DispatchQueue.main.async { + self.bottomPaneView.isHidden = false + self.loginPaneView.isHidden = true + } } } .store(in: &cancellable) From a113630c1d0fa661d8f3900b463d34391df25bec Mon Sep 17 00:00:00 2001 From: Inho Choi Date: Thu, 8 Dec 2022 01:36:16 +0900 Subject: [PATCH 15/27] =?UTF-8?q?:recycle:=20RegionButtons=20Array=20?= =?UTF-8?q?=EC=97=90=EC=84=9C=20Dictionary=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Explore/ExploreViewController.swift | 60 +++++++++---------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/Workade/Views&ViewModels/Explore/ExploreViewController.swift b/Workade/Views&ViewModels/Explore/ExploreViewController.swift index 05f08d76..e1e7e2db 100644 --- a/Workade/Views&ViewModels/Explore/ExploreViewController.swift +++ b/Workade/Views&ViewModels/Explore/ExploreViewController.swift @@ -5,6 +5,7 @@ // Created by 김예훈 on 2022/11/21. // +import Combine import FirebaseAuth import SafariServices import UIKit @@ -15,6 +16,7 @@ final class ExploreViewController: UIViewController { private var regionInfoViewBottomConstraint: NSLayoutConstraint? private var buttonConstraints: [RegionButton: [NSLayoutConstraint]] = [:] private let sectionPadding: CGFloat = 4 + private var anyCancellable = Set() let regionInfoViewHeight: CGFloat = 140 + CGFloat.bottomSafeArea private let animator: UIViewPropertyAnimator = { @@ -22,8 +24,6 @@ final class ExploreViewController: UIViewController { return UIViewPropertyAnimator(duration: 0.4, timingParameters: springTiming) }() - private lazy var regionPeopleCounts = [Region: Int]() - override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .black @@ -32,25 +32,21 @@ final class ExploreViewController: UIViewController { setupLayout() for region in Region.allCases { - Task { [weak self] in - self?.regionPeopleCounts[region] = try await FirestoreDAO.shared.getActiveUsersNumber(region: region) - } - } - - for button in regionButtons { - guard let count = regionPeopleCounts[button.region] else { continue } - button.peopleCount = count + regionButtons[region]?.peopleCount = UserManager.shared.activeUsers[region]?.count ?? -2 + print(UserManager.shared.activeUsers[.jeJuDo]?.count) + print() } viewModel.selectedRegion.bind { [weak self] region in guard let self = self else { return } // 선택된 Region에 따라 RegionButton 업데이트 - self.regionButtons.forEach { button in + for region in Region.allCases { self.animator.addAnimations { - button.changeLayout() + self.regionButtons[region]?.changeLayout() } self.animator.startAnimation() } + self.changeLayout(by: region) self.animator.addAnimations { self.view.layoutIfNeeded() @@ -58,15 +54,13 @@ final class ExploreViewController: UIViewController { } self.animator.startAnimation() } - } - - override func viewWillAppear(_ animated: Bool) { - super.viewWillAppear(animated) - self.regionButtons.forEach { button in - Task { @MainActor [weak self] in - button.peopleCount = await self?.viewModel.getUserCount(region: button.region) ?? 0 - } - } + +// UserManager.shared.$activeUsers.sink { [weak self] activeUsers in +// guard let self = self else { return } +// for region in Region.allCases { +// } +// } +// .store(in: &anyCancellable) } override func viewDidAppear(_ animated: Bool) { @@ -74,14 +68,14 @@ final class ExploreViewController: UIViewController { setupButtonLayout() } - private lazy var regionButtons: [RegionButton] = { - var regionButtons: [RegionButton] = [] + private lazy var regionButtons: [Region: RegionButton] = { + var regionButtons = [Region: RegionButton]() for region in Region.allCases { let newButton = RegionButton(region: region, selectedRegion: viewModel.selectedRegion, peopleCount: 0) newButton.translatesAutoresizingMaskIntoConstraints = false - regionButtons.append(newButton) + regionButtons[region] = newButton } return regionButtons @@ -101,9 +95,11 @@ final class ExploreViewController: UIViewController { }() lazy var regionInfoView: RegionInfoView = { - let view = RegionInfoView(frame: .zero, peopleCount: 0, - selectedRegion: viewModel.selectedRegion) { [weak self] in - guard let region = self?.viewModel.selectedRegion.value, let count = self?.regionPeopleCounts[region] else { return } + let view = RegionInfoView(frame: .zero, + peopleCount: 0, + selectedRegion: viewModel.selectedRegion + ) { [weak self] in + guard let region = self?.viewModel.selectedRegion.value, let count = UserManager.shared.activeUsers[region]?.count else { return } let navigationController = UINavigationController(rootViewController: WorkationViewController(region: region, peopleCount: count)) navigationController.transitioningDelegate = self?.transitionManager navigationController.modalPresentationStyle = .custom @@ -262,13 +258,15 @@ final class ExploreViewController: UIViewController { regionInfoViewBottomConstraint!, regionInfoView.topAnchor.constraint(equalTo: mainContainerView.bottomAnchor, constant: sectionPadding) ]) - regionButtons.forEach { regionButton in - view.addSubview(regionButton) + for region in Region.allCases { + guard let button = regionButtons[region] else { continue } + view.addSubview(button) } } private func setupButtonLayout() { - regionButtons.forEach { regionButton in + for region in Region.allCases { + guard let regionButton = regionButtons[region] else { continue } buttonConstraints[regionButton]?.forEach({ constraint in self.view.removeConstraint(constraint) }) @@ -292,7 +290,7 @@ final class ExploreViewController: UIViewController { mapImageView.tintColor = isRegionNil ? .theme.workadeBlue : .white if let region = region { - regionInfoView.peopleCount = regionPeopleCounts[region] ?? 0 + regionInfoView.peopleCount = UserManager.shared.activeUsers[region]?.count ?? -1 UIView.transition(with: mainContainerView, duration: 0.25, options: .transitionCrossDissolve, From 0d1f668bec44e012113779e71962737ecfd71692 Mon Sep 17 00:00:00 2001 From: ryu Date: Thu, 8 Dec 2022 02:12:33 +0900 Subject: [PATCH 16/27] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=20=EC=A0=9C?= =?UTF-8?q?=EB=AA=A9=EC=97=86=EC=9D=8C,=20=EB=82=B4=EC=9A=A9=EC=97=86?= =?UTF-8?q?=EC=9D=8C=EC=9D=84=20placeholder=EB=A1=9C=20=EA=B5=90=EC=B2=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CheckListDetailCell.swift | 1 + .../CheckListDetailViewController.swift | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/Workade/Views&ViewModels/CheckList/CheckListDetail/CheckListDetailCell/CheckListDetailCell.swift b/Workade/Views&ViewModels/CheckList/CheckListDetail/CheckListDetailCell/CheckListDetailCell.swift index 19a92244..563b3266 100644 --- a/Workade/Views&ViewModels/CheckList/CheckListDetail/CheckListDetailCell/CheckListDetailCell.swift +++ b/Workade/Views&ViewModels/CheckList/CheckListDetail/CheckListDetailCell/CheckListDetailCell.swift @@ -50,6 +50,7 @@ class CheckListDetailCell: UITableViewCell { checkButton.setImage(todo.done ? UIImage(systemName: "checkmark.circle.fill") : UIImage(systemName: "circle"), for: .normal) checkButton.tintColor = todo.done ? .theme.workadeBlue : .theme.primary contentText.text = todo.content + contentText.textColor = todo.content != Optional("내용없음") ? .theme.primary : .lightGray } } diff --git a/Workade/Views&ViewModels/CheckList/CheckListDetail/CheckListDetailViewController.swift b/Workade/Views&ViewModels/CheckList/CheckListDetail/CheckListDetailViewController.swift index b3f83d28..55859e22 100644 --- a/Workade/Views&ViewModels/CheckList/CheckListDetail/CheckListDetailViewController.swift +++ b/Workade/Views&ViewModels/CheckList/CheckListDetail/CheckListDetailViewController.swift @@ -59,6 +59,7 @@ class CheckListDetailViewController: UIViewController { private lazy var titleLabel: UITextField = { let textField = UITextField() + textField.textColor = selectedCheckList?.title != Optional("제목없음") ? .theme.primary : .lightGray textField.text = selectedCheckList?.title ?? "제목없음" textField.font = .customFont(for: .title2) textField.tintColor = .theme.primary @@ -367,11 +368,26 @@ extension CheckListDetailViewController: UITableViewDataSource { } extension CheckListDetailViewController: UITextFieldDelegate { + func textFieldDidBeginEditing(_ textField: UITextField) { + if textField == titleLabel { + if textField.textColor == .lightGray { + textField.text = "" + textField.textColor = .theme.primary + } + } else { + if textField.textColor == .lightGray { + textField.text = "" + textField.textColor = .theme.primary + } + } + } + func textFieldDidEndEditing(_ textField: UITextField) { if textField == titleLabel { guard let targetCheckList = selectedCheckList else { return } if textField.text == "" { textField.text = "제목없음" + textField.textColor = .lightGray } targetCheckList.title = textField.text editCheckListPublisher?.send(targetCheckList) @@ -379,6 +395,7 @@ extension CheckListDetailViewController: UITextFieldDelegate { let todo = checkListDetailViewModel.todos[textField.tag] if textField.text == "" { textField.text = "내용없음" + textField.textColor = .lightGray } todo.content = textField.text checkListDetailViewModel.updateTodo(at: textField.tag, todo: todo) From 4529def4b2898ec631bd646bc50104976fb996e4 Mon Sep 17 00:00:00 2001 From: Inho Choi Date: Thu, 8 Dec 2022 02:51:14 +0900 Subject: [PATCH 17/27] =?UTF-8?q?:bug:=20MainQueue=20=EB=B2=84=EA=B7=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Workade/Share/RegionButton.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Workade/Share/RegionButton.swift b/Workade/Share/RegionButton.swift index fc082747..13fae2f1 100644 --- a/Workade/Share/RegionButton.swift +++ b/Workade/Share/RegionButton.swift @@ -12,7 +12,9 @@ final class RegionButton: UIButton { weak var selectedRegion: Binder? var peopleCount: Int { didSet { - peopleCountLabel.text = "\(peopleCount)" + DispatchQueue.main.async { [weak self] in + self?.peopleCountLabel.text = "\(self!.peopleCount)" + } } } From d1a34c192a7b7f14e43764aa4021b5e48dbd5aa6 Mon Sep 17 00:00:00 2001 From: Inho Choi Date: Thu, 8 Dec 2022 02:51:51 +0900 Subject: [PATCH 18/27] =?UTF-8?q?:sparkles:=20Listener=20=EB=B0=8F=20init?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=A7=80=EC=97=AD=20=EC=9D=B8=EA=B5=AC=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Workade/Managers/FirestoreManager.swift | 38 +++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/Workade/Managers/FirestoreManager.swift b/Workade/Managers/FirestoreManager.swift index 4c01dc88..1afaa50d 100644 --- a/Workade/Managers/FirestoreManager.swift +++ b/Workade/Managers/FirestoreManager.swift @@ -9,12 +9,19 @@ import FirebaseFirestore import Foundation class FirestoreDAO { - private init() { } + private init() { + for region in Region.allCases { + + regionListener[region] = setRegionListener(region: region) + } + } + static let shared = FirestoreDAO() private let dto = FirestoreDTO() private let activeUserCollectionName = "ActiveUser" private let allUserCollectionName = "AllUser" + private var regionListener = [Region: ListenerRegistration]() func getUsers() async throws -> [User] { let documents = try await dto.getDocuments(collectionName: allUserCollectionName) @@ -115,8 +122,33 @@ class FirestoreDAO { return users } - func setRegionListener(region: Region, listenerAction: @escaping (QuerySnapshot?, Error?) -> Void) -> ListenerRegistration { - return dto.setListener(collectionName: region.rawValue, listenderAction: listenerAction) + func setRegionListener(region: Region) -> ListenerRegistration { + return dto.setListener(collectionName: region.rawValue, listenderAction: { query, error in + if error != nil { + print(error, "Set Region Listener Error") + return + } + + guard let query = query else { return } + + let decoder = JSONDecoder() + for documentChange in query.documentChanges { + let document = documentChange.document + let data = document.data() + do { + let jsonData = try JSONSerialization.data(withJSONObject: data) + let activeUser = try decoder.decode(ActiveUser.self, from: jsonData) + if UserManager.shared.activeUsers[activeUser.region] == nil { + UserManager.shared.activeUsers[activeUser.region] = [activeUser] + } else { + UserManager.shared.activeUsers[activeUser.region]?.append(activeUser) + } + } catch { + print("Active User Decode Fail") + } + } + + }) } } From 9094f5c86b4deabbe05373239097339cdf423ae5 Mon Sep 17 00:00:00 2001 From: Inho Choi Date: Thu, 8 Dec 2022 02:52:30 +0900 Subject: [PATCH 19/27] =?UTF-8?q?:sparkles:=20Listener=EB=A1=9C=20?= =?UTF-8?q?=EC=A7=80=EC=97=AD=EC=9D=B8=EA=B5=AC=20=EB=8F=99=EA=B8=B0?= =?UTF-8?q?=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Workade/Managers/UserManager.swift | 2 +- .../Explore/ExploreViewController.swift | 20 +++++++++++-------- .../LoginJob/LoginJobViewController.swift | 9 ++++++--- .../Workation/WorkationViewController.swift | 4 ++-- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/Workade/Managers/UserManager.swift b/Workade/Managers/UserManager.swift index 6d46b6c1..48004c35 100644 --- a/Workade/Managers/UserManager.swift +++ b/Workade/Managers/UserManager.swift @@ -21,7 +21,7 @@ class UserManager { var user = CurrentValueSubject(nil) - var activeUsers = [Region: [ActiveUser]]() + @Published var activeUsers = [Region: [ActiveUser]]() @Published var activeMyInfo: ActiveUser? = nil diff --git a/Workade/Views&ViewModels/Explore/ExploreViewController.swift b/Workade/Views&ViewModels/Explore/ExploreViewController.swift index e1e7e2db..a854ba91 100644 --- a/Workade/Views&ViewModels/Explore/ExploreViewController.swift +++ b/Workade/Views&ViewModels/Explore/ExploreViewController.swift @@ -33,8 +33,6 @@ final class ExploreViewController: UIViewController { for region in Region.allCases { regionButtons[region]?.peopleCount = UserManager.shared.activeUsers[region]?.count ?? -2 - print(UserManager.shared.activeUsers[.jeJuDo]?.count) - print() } viewModel.selectedRegion.bind { [weak self] region in @@ -55,12 +53,18 @@ final class ExploreViewController: UIViewController { self.animator.startAnimation() } -// UserManager.shared.$activeUsers.sink { [weak self] activeUsers in -// guard let self = self else { return } -// for region in Region.allCases { -// } -// } -// .store(in: &anyCancellable) + UserManager.shared.$activeUsers.sink { [weak self] activeUsers in + guard let self = self else { return } + for region in Region.allCases { + guard let users = activeUsers[region] else { continue } + self.regionButtons[region]?.peopleCount = users.count + + if self.viewModel.selectedRegion.value == region { + self.regionInfoView.peopleCount = users.count + } + } + } + .store(in: &anyCancellable) } override func viewDidAppear(_ animated: Bool) { diff --git a/Workade/Views&ViewModels/Login/LoginJob/LoginJobViewController.swift b/Workade/Views&ViewModels/Login/LoginJob/LoginJobViewController.swift index d9b06fa1..c3274a65 100644 --- a/Workade/Views&ViewModels/Login/LoginJob/LoginJobViewController.swift +++ b/Workade/Views&ViewModels/Login/LoginJob/LoginJobViewController.swift @@ -88,9 +88,12 @@ class LoginJobViewController: UIViewController { guard let self = self else { return } Task { [weak self] in guard let loginInfo = FirebaseManager.shared.getUser(), let job = self?.viewModel.selectedJob else { return } - let user = User(id: loginInfo.uid, name: self?.viewModel.name, email: loginInfo.email, job: job, activeRegion: self?.region) // Toby - try await FirestoreDAO.shared.createUser(user: user) - + let user = User(id: loginInfo.uid, name: self?.viewModel.name, email: loginInfo.email, job: job, activeRegion: self?.region) + do { + try await FirestoreDAO.shared.createUser(user: user) + } catch { + print(error.localizedDescription) + } guard let region = self?.region else { return } try await FirestoreDAO.shared.createActiveUser(user: ActiveUser(id: user.id, job: job, region: region, startDate: .now)) } diff --git a/Workade/Views&ViewModels/Workation/WorkationViewController.swift b/Workade/Views&ViewModels/Workation/WorkationViewController.swift index 86baf881..11f6c338 100644 --- a/Workade/Views&ViewModels/Workation/WorkationViewController.swift +++ b/Workade/Views&ViewModels/Workation/WorkationViewController.swift @@ -148,7 +148,7 @@ final class WorkationViewController: UIViewController { let alert = UIAlertController(title: nil, message: "정말로 워케이션을 시작하시겠어요?", preferredStyle: .actionSheet) alert.addAction(UIAlertAction(title: "시작하기", style: .default, handler: { [weak self] _ in - if Auth.auth().currentUser == nil { + if UserManager.shared.user.value == nil { let loginInitViewController = LoginInitViewController(region: self?.region) let loginNavigation = UINavigationController(rootViewController: loginInitViewController) loginNavigation.modalPresentationStyle = .overFullScreen @@ -208,6 +208,7 @@ final class WorkationViewController: UIViewController { self?.loginPaneView.isHidden = false self?.bottomPaneView.isHidden = true } + })) alert.addAction(UIAlertAction(title: "취소", style: .cancel)) @@ -434,7 +435,6 @@ private extension WorkationViewController { guard var user = UserManager.shared.activeMyInfo else { return } let offsetDate = Date().timeIntervalSince(user.startDate) let day = Int(offsetDate/86400) - print(user.progressDay!, day) if let storedDay = user.progressDay, storedDay != day { self.compareProgressDay(presentDay: day, storedDay: storedDay) user.progressDay = day From 8ba1cbbdc7b16397cf78f40ab0343dac6e3e6cf0 Mon Sep 17 00:00:00 2001 From: ryu Date: Thu, 8 Dec 2022 02:55:00 +0900 Subject: [PATCH 20/27] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=20=EC=B2=B4?= =?UTF-8?q?=ED=81=AC=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=A0=9C=EB=AA=A9=20?= =?UTF-8?q?=EC=98=81=EC=97=AD=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CheckListDetail/CheckListDetailViewController.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Workade/Views&ViewModels/CheckList/CheckListDetail/CheckListDetailViewController.swift b/Workade/Views&ViewModels/CheckList/CheckListDetail/CheckListDetailViewController.swift index 55859e22..64c44166 100644 --- a/Workade/Views&ViewModels/CheckList/CheckListDetail/CheckListDetailViewController.swift +++ b/Workade/Views&ViewModels/CheckList/CheckListDetail/CheckListDetailViewController.swift @@ -291,7 +291,8 @@ extension CheckListDetailViewController { NSLayoutConstraint.activate([ titleLabel.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor), - titleLabel.topAnchor.constraint(equalTo: scrollView.topAnchor) + titleLabel.topAnchor.constraint(equalTo: scrollView.topAnchor), + titleLabel.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor) ]) NSLayoutConstraint.activate([ From ad9364f99ba53677acaed0f98e74cf85e2364207 Mon Sep 17 00:00:00 2001 From: Inho Choi Date: Thu, 8 Dec 2022 17:49:34 +0900 Subject: [PATCH 21/27] =?UTF-8?q?:bug:=20=EC=9D=B4=EB=A6=84=EC=9D=B4=20?= =?UTF-8?q?=EB=8F=99=EA=B8=B0=ED=99=94=20=EB=90=98=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EB=8A=94=20=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EditProfile/EditProfileViewController.swift | 12 +++++++----- Workade/Views&ViewModels/MyPage/ProfileView.swift | 13 +++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Workade/Views&ViewModels/MyPage/EditProfile/EditProfileViewController.swift b/Workade/Views&ViewModels/MyPage/EditProfile/EditProfileViewController.swift index 4f14211b..360c4786 100644 --- a/Workade/Views&ViewModels/MyPage/EditProfile/EditProfileViewController.swift +++ b/Workade/Views&ViewModels/MyPage/EditProfile/EditProfileViewController.swift @@ -187,14 +187,16 @@ final class EditProfileViewController: UIViewController { func updateUser() { Task { - guard let loginInfo = FirebaseManager.shared.getUser() else { return } if self.nameTextField.text == "" { self.nameTextField.text = UserManager.shared.user.value?.name } - guard let job = Job(rawValue: self.pickerLabel.text ?? "") else { return } - let user = User(id: loginInfo.uid, name: self.nameTextField.text, email: loginInfo.email, job: job) - try await FirestoreDAO.shared.createUser(user: user) - + guard let job = Job(rawValue: self.pickerLabel.text ?? "") , let userInfo = UserManager.shared.user.value else { return } + let user = User(id: userInfo.id, name: self.nameTextField.text, email: userInfo.email, job: job) + if userInfo.name != self.nameTextField.text || job.rawValue != userInfo.job.rawValue { + print(userInfo.name, self.nameTextField.text) + print(userInfo.job.rawValue, job.rawValue) + try await FirestoreDAO.shared.createUser(user: user) + } navigationController?.popViewController(animated: true) } } diff --git a/Workade/Views&ViewModels/MyPage/ProfileView.swift b/Workade/Views&ViewModels/MyPage/ProfileView.swift index ed53bbea..6017d76f 100644 --- a/Workade/Views&ViewModels/MyPage/ProfileView.swift +++ b/Workade/Views&ViewModels/MyPage/ProfileView.swift @@ -5,9 +5,12 @@ // Created by Hong jeongmin on 2022/11/16. // +import Combine import UIKit class ProfileView: UIView { + private var anyCancellable = Set() + let containerView: UIView = { let containerView = UIView() containerView.backgroundColor = .clear @@ -40,6 +43,7 @@ class ProfileView: UIView { let nameLabel: UILabel = { let label = UILabel() label.font = .customFont(for: .title3) + label.text = UserManager.shared.user.value?.name ?? "" label.translatesAutoresizingMaskIntoConstraints = false return label @@ -48,6 +52,7 @@ class ProfileView: UIView { let jobLabel: UILabel = { let label = UILabel() label.font = .customFont(for: .footnote) + label.text = UserManager.shared.user.value?.job.rawValue ?? "" label.translatesAutoresizingMaskIntoConstraints = false return label @@ -57,6 +62,14 @@ class ProfileView: UIView { super.init(frame: frame) setupLayout() + + UserManager.shared.user.sink(receiveValue: { [weak self] user in + guard let user = user, let self = self else { return } + DispatchQueue.main.async { + self.jobLabel.text = user.job.rawValue + self.nameLabel.text = user.name ?? "" + } + }).store(in: &anyCancellable) } required init?(coder: NSCoder) { From c4ab22e4c5c5890ff84d4dbdf5f809faf41915eb Mon Sep 17 00:00:00 2001 From: Inho Choi Date: Thu, 8 Dec 2022 18:37:42 +0900 Subject: [PATCH 22/27] =?UTF-8?q?:bug:=20=EC=A7=80=EC=97=AD=EB=B3=84=20?= =?UTF-8?q?=EC=88=AB=EC=9E=90=20=EB=8F=99=EA=B8=B0=ED=99=94=20=EB=B2=84?= =?UTF-8?q?=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Workade/Managers/FirebaseManager.swift | 6 +-- Workade/Managers/FirestoreManager.swift | 50 ++++++------------- Workade/SceneDelegate.swift | 1 - .../Explore/RegionInfoView.swift | 11 ++-- .../MyPage/MyPageViewController.swift | 20 +++----- .../Workation/WorkationViewController.swift | 22 ++++++-- 6 files changed, 49 insertions(+), 61 deletions(-) diff --git a/Workade/Managers/FirebaseManager.swift b/Workade/Managers/FirebaseManager.swift index fa6f0954..79097ea3 100644 --- a/Workade/Managers/FirebaseManager.swift +++ b/Workade/Managers/FirebaseManager.swift @@ -128,9 +128,9 @@ final class FirebaseManager: NSObject { if let user = result?.user { Task { [weak self] in - if var userInfo = try await FirestoreDAO.shared.getUser(userID: user.uid) { - if let region = self?.region { - try await FirestoreDAO.shared.createActiveUser(user: ActiveUser(id: userInfo.id, job: userInfo.job, region: region, startDate: .now)) + if UserManager.shared.user.value != nil { + if let region = self?.region, let userInfo = UserManager.shared.user.value { + try await FirestoreDAO.shared.createActiveUser(user: ActiveUser(id: userInfo .id, job: userInfo.job, region: region, startDate: .now)) try await FirestoreDAO.shared.updateUser(user: User(id: userInfo.id, name: userInfo.name, email: userInfo.email, job: userInfo.job, activeRegion: region)) } DispatchQueue.main.async { diff --git a/Workade/Managers/FirestoreManager.swift b/Workade/Managers/FirestoreManager.swift index 1afaa50d..1576e6d2 100644 --- a/Workade/Managers/FirestoreManager.swift +++ b/Workade/Managers/FirestoreManager.swift @@ -23,76 +23,55 @@ class FirestoreDAO { private let allUserCollectionName = "AllUser" private var regionListener = [Region: ListenerRegistration]() - func getUsers() async throws -> [User] { - let documents = try await dto.getDocuments(collectionName: allUserCollectionName) - let decoder = JSONDecoder() - var users = [User]() - - for document in documents { - let data = document.data() - let jsonData = try JSONSerialization.data(withJSONObject: data) - let user = try decoder.decode(User.self, from: jsonData) - users.append(user) - } - - return users - } - func createUser(user: User) async throws { guard let data = user.asDictionary else { return } - try await dto.createDocument(collectionName: allUserCollectionName, documentName: user.id, data: data) + do { + try await dto.createDocument(collectionName: allUserCollectionName, documentName: user.id, data: data) + } catch { + print("LOG", error.localizedDescription) + } UserManager.shared.user.value = user -// UserManager.shared.isActive = (user.activeRegion != nil) } func updateUser(user: User) async throws { guard let data = user.asDictionary else { return } try await dto.updateDocument(collectionName: allUserCollectionName, documentName: user.id, data: data) UserManager.shared.user.value = user -// UserManager.shared.isActive = (user.activeRegion != nil) } func deleteUser(userid: String) async throws { try await dto.deleteDocument(collectionName: allUserCollectionName, documentName: userid) UserManager.shared.user.value = nil -// UserManager.shared.isActive = false } func getUser(userID: String) async throws -> User? { - let documents = try await dto.getDocuments(collectionName: allUserCollectionName) + let document = try await dto.getDocument(collectionName: allUserCollectionName, documentName: userID) let decoder = JSONDecoder() - for document in documents { - let data = document.data() - let jsonData = try JSONSerialization.data(withJSONObject: data) - let user = try decoder.decode(User.self, from: jsonData) - UserManager.shared.user.value = user - if user.id == userID { -// UserManager.shared.isActive = (user.activeRegion != nil) - return user - } - } + let data = document.data() + guard let data = data else { return nil } + let jsonData = try JSONSerialization.data(withJSONObject: data) + let user = try decoder.decode(User.self, from: jsonData) + UserManager.shared.user.value = user + return nil - } +} func createActiveUser(user: ActiveUser) async throws { guard let data = user.asDictionary else { return } try await dto.createDocument(collectionName: user.region.rawValue, documentName: user.id, data: data) -// UserManager.shared.isActive = true -// UserManager.shared.activeRegion = user.region UserManager.shared.activeMyInfo = user } func updateActiveUser(user: ActiveUser) async throws { guard let data = user.asDictionary else { return } try await dto.updateDocument(collectionName: user.region.rawValue, documentName: user.id, data: data) + UserManager.shared.activeMyInfo = user } func deleteActiveUser(userID: String, region: Region) async throws { try await dto.deleteDocument(collectionName: region.rawValue, documentName: userID) -// UserManager.shared.activeRegion = nil UserManager.shared.activeMyInfo = nil -// UserManager.shared.isActive = false } func getActiveUsersNumber(region: Region) async throws -> Int { @@ -103,6 +82,7 @@ class FirestoreDAO { let document = try await dto.getDocument(collectionName: region.rawValue, documentName: uid) let data = document.data() let decoder = JSONDecoder() + guard let data = data else { return } let jsonData = try JSONSerialization.data(withJSONObject: data) let activeUser = try decoder.decode(ActiveUser.self, from: jsonData) UserManager.shared.activeMyInfo = activeUser diff --git a/Workade/SceneDelegate.swift b/Workade/SceneDelegate.swift index c2e7a4d1..7f39b234 100644 --- a/Workade/SceneDelegate.swift +++ b/Workade/SceneDelegate.swift @@ -23,7 +23,6 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { window?.rootViewController = UINavigationController(rootViewController: ExploreViewController()) window?.makeKeyAndVisible() Task { - // try Auth.auth().signOut() guard let uid = Auth.auth().currentUser?.uid, let user = try await FirestoreDAO.shared.getUser(userID: uid), let region = user.activeRegion diff --git a/Workade/Views&ViewModels/Explore/RegionInfoView.swift b/Workade/Views&ViewModels/Explore/RegionInfoView.swift index eea3fff4..77879fc8 100644 --- a/Workade/Views&ViewModels/Explore/RegionInfoView.swift +++ b/Workade/Views&ViewModels/Explore/RegionInfoView.swift @@ -10,10 +10,13 @@ import UIKit final class RegionInfoView: UIView { var peopleCount: Int { didSet { - let text = "지금 \(peopleCount)명의 사람들이\n워케이션 중이에요" - let attributedString = NSMutableAttributedString(string: text) - attributedString.addAttribute(.foregroundColor, value: UIColor.theme.workadeBlue, range: (text as NSString).range(of: "\(peopleCount)")) - desciptionLabel.attributedText = attributedString + DispatchQueue.main.async { [weak self] in + guard let self = self else { return } + let text = "지금 \(self.peopleCount)명의 사람들이\n워케이션 중이에요" + let attributedString = NSMutableAttributedString(string: text) + attributedString.addAttribute(.foregroundColor, value: UIColor.theme.workadeBlue, range: (text as NSString).range(of: "\(self.peopleCount)")) + self.desciptionLabel.attributedText = attributedString + } } } let selectedRegion: Binder diff --git a/Workade/Views&ViewModels/MyPage/MyPageViewController.swift b/Workade/Views&ViewModels/MyPage/MyPageViewController.swift index 046f82f6..d5a0adf7 100644 --- a/Workade/Views&ViewModels/MyPage/MyPageViewController.swift +++ b/Workade/Views&ViewModels/MyPage/MyPageViewController.swift @@ -50,12 +50,6 @@ final class MyPageViewController: UIViewController { setupLayout() } - override func viewWillAppear(_ animated: Bool) { - super.viewWillAppear(animated) - - setData() - } - private func editProfileButtonTapped() { profileView.editProfileButton.addAction(UIAction(handler: { [weak self] _ in guard let self = self else { return } @@ -64,13 +58,13 @@ final class MyPageViewController: UIViewController { }), for: .touchUpInside) } - func setData() { - guard let user = UserManager.shared.user.value else { return } - profileView.nameLabel.text = user.name - profileView.jobLabel.text = user.job.rawValue - - // TODO: Combine이던, Binder던 콜렉션뷰 reload해야할것 같음 - } +// func setData() { +// guard let user = UserManager.shared.user.value else { return } +// profileView.nameLabel.text = user.name +// profileView.jobLabel.text = user.job.rawValue +// +// // TODO: Combine이던, Binder던 콜렉션뷰 reload해야할것 같음 +// } func setupStickerView() { guard let stickersArray = UserManager.shared.user.value?.stickers else { diff --git a/Workade/Views&ViewModels/Workation/WorkationViewController.swift b/Workade/Views&ViewModels/Workation/WorkationViewController.swift index 11f6c338..9a98819c 100644 --- a/Workade/Views&ViewModels/Workation/WorkationViewController.swift +++ b/Workade/Views&ViewModels/Workation/WorkationViewController.swift @@ -156,12 +156,11 @@ final class WorkationViewController: UIViewController { } else { Task { [weak self] in guard let self = self, - let uid = Auth.auth().currentUser?.uid, - var user = try await FirestoreDAO.shared.getUser(userID: uid) + var user = UserManager.shared.user.value else { return } try await FirestoreDAO.shared.createActiveUser(user: ActiveUser(id: user.id, job: user.job, region: self.region, startDate: .now)) - try await FirestoreDAO.shared.updateUser(user: User(id: user.id, name: user.name, email: user.email, job: user.job, activeRegion: self.region)) - try await UserManager.shared.reloadActiveUser(region: self.region) + user.activeRegion = self.region + try await FirestoreDAO.shared.updateUser(user: user) } self?.loginPaneView.isHidden = true @@ -312,7 +311,14 @@ final class WorkationViewController: UIViewController { return stackView }() - private let peopleCount: Int + private var peopleCount: Int { + didSet { + DispatchQueue.main.async { [weak self] in + guard let count = self?.peopleCount else { return } + self?.numberOfWorkers.text = "\(count)명이 일하고 있어요" + } + } + } override func viewDidLoad() { super.viewDidLoad() @@ -488,6 +494,12 @@ extension WorkationViewController { } } .store(in: &cancellable) + + UserManager.shared.$activeUsers.sink { [weak self] users in + guard let self = self else { return } + self.peopleCount = users[self.region]?.count ?? 0 + } + .store(in: &cancellable) } private func updateActiveUser(user: ActiveUser) { From 4f3a493d3466a96c2d96eeb2b6f81c8bdd3edaf4 Mon Sep 17 00:00:00 2001 From: Inho Choi Date: Thu, 8 Dec 2022 18:52:59 +0900 Subject: [PATCH 23/27] =?UTF-8?q?:bug:=20=ED=9A=8C=EC=9B=90=ED=83=88?= =?UTF-8?q?=ED=87=B4=20=EC=95=88=EB=90=98=EB=8A=94=20=EB=B2=84=EA=B7=B8=20?= =?UTF-8?q?=EB=B0=8F=20=ED=9A=8C=EC=9B=90=ED=83=88=ED=87=B4=20=ED=9B=84=20?= =?UTF-8?q?=EC=88=AB=EC=9E=90=20=EB=8F=99=EA=B8=B0=ED=99=94=20=EB=B2=84?= =?UTF-8?q?=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Workade/Managers/FirestoreManager.swift | 12 ++++------ .../Setting/SettingViewController.swift | 22 +++++++++++-------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Workade/Managers/FirestoreManager.swift b/Workade/Managers/FirestoreManager.swift index 1576e6d2..6618709c 100644 --- a/Workade/Managers/FirestoreManager.swift +++ b/Workade/Managers/FirestoreManager.swift @@ -112,22 +112,18 @@ class FirestoreDAO { guard let query = query else { return } let decoder = JSONDecoder() - for documentChange in query.documentChanges { - let document = documentChange.document + var users = [ActiveUser]() + for document in query.documents { let data = document.data() do { let jsonData = try JSONSerialization.data(withJSONObject: data) let activeUser = try decoder.decode(ActiveUser.self, from: jsonData) - if UserManager.shared.activeUsers[activeUser.region] == nil { - UserManager.shared.activeUsers[activeUser.region] = [activeUser] - } else { - UserManager.shared.activeUsers[activeUser.region]?.append(activeUser) - } + users.append(activeUser) } catch { print("Active User Decode Fail") } } - + UserManager.shared.activeUsers[region] = users }) } } diff --git a/Workade/Views&ViewModels/MyPage/Setting/SettingViewController.swift b/Workade/Views&ViewModels/MyPage/Setting/SettingViewController.swift index 5d0de902..4cc80538 100644 --- a/Workade/Views&ViewModels/MyPage/Setting/SettingViewController.swift +++ b/Workade/Views&ViewModels/MyPage/Setting/SettingViewController.swift @@ -74,16 +74,20 @@ final class SettingViewController: UIViewController { button.addAction(UIAction(handler: { [weak self] _ in Task { [weak self] in - guard let currentUser = Auth.auth().currentUser else { return } - if var user = try await FirestoreDAO.shared.getUser(userID: currentUser.uid) { - if let region = user.activeRegion { - try await FirestoreDAO.shared.deleteActiveUser(userID: user.id, region: region) - } - try await FirestoreDAO.shared.deleteUser(userid: user.id) + guard let self = self, let user = UserManager.shared.user.value else { return } + let uid = user.id + + // 활동 중이면 활동중인 유저를 삭제 + if let activeUser = UserManager.shared.activeMyInfo { + try await FirestoreDAO.shared.deleteActiveUser(userID: uid, region: activeUser.region) } - try Auth.auth().signOut() - try await currentUser.delete() - self?.navigationController?.popToRootViewController(animated: true) + + // 먼저 계정 삭제 (로그 아웃 자동) + try await Auth.auth().currentUser?.delete() + // DB에서 계정 삭제 + try await FirestoreDAO.shared.deleteUser(userid: uid) + + self.navigationController?.popToRootViewController(animated: true) } }), for: .touchUpInside) From a7a6b2ad73d61a4af824806dafaa669a4d388c80 Mon Sep 17 00:00:00 2001 From: Inho Choi Date: Fri, 9 Dec 2022 01:57:30 +0900 Subject: [PATCH 24/27] =?UTF-8?q?:recycle:=20=EC=A4=91=EB=B3=B5=EB=90=9C?= =?UTF-8?q?=20=EC=BD=94=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Workade/Managers/FirebaseManager.swift | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Workade/Managers/FirebaseManager.swift b/Workade/Managers/FirebaseManager.swift index 79097ea3..12254534 100644 --- a/Workade/Managers/FirebaseManager.swift +++ b/Workade/Managers/FirebaseManager.swift @@ -52,8 +52,7 @@ final class FirebaseManager: NSObject { func signout() { do { try Auth.auth().signOut() - if UserManager.shared.user.value?.activeRegion != nil, - let region = UserManager.shared.user.value?.activeRegion, + if let region = UserManager.shared.user.value?.activeRegion, let id = UserManager.shared.user.value?.id { Task { try await FirestoreDAO.shared.deleteActiveUser(userID: id, region: region) @@ -126,7 +125,7 @@ final class FirebaseManager: NSObject { return } - if let user = result?.user { + if result?.user != nil { Task { [weak self] in if UserManager.shared.user.value != nil { if let region = self?.region, let userInfo = UserManager.shared.user.value { From bf475da803f111de695bcef9a601e51b7fb09add Mon Sep 17 00:00:00 2001 From: Inho Choi Date: Fri, 9 Dec 2022 02:00:52 +0900 Subject: [PATCH 25/27] =?UTF-8?q?:bug:=20=20View=20=EB=B3=80=EA=B2=BD?= =?UTF-8?q?=EC=9D=84=20Main=20Thread=EC=97=90=EC=84=9C=20=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Workade/Views&ViewModels/Explore/ExploreViewController.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Workade/Views&ViewModels/Explore/ExploreViewController.swift b/Workade/Views&ViewModels/Explore/ExploreViewController.swift index a854ba91..7f336951 100644 --- a/Workade/Views&ViewModels/Explore/ExploreViewController.swift +++ b/Workade/Views&ViewModels/Explore/ExploreViewController.swift @@ -57,8 +57,9 @@ final class ExploreViewController: UIViewController { guard let self = self else { return } for region in Region.allCases { guard let users = activeUsers[region] else { continue } - self.regionButtons[region]?.peopleCount = users.count - + DispatchQueue.main.async { + self.regionButtons[region]?.peopleCount = users.count + } if self.viewModel.selectedRegion.value == region { self.regionInfoView.peopleCount = users.count } From 5065c7197c3ff732e5c376c0f7ef4c850f3100b9 Mon Sep 17 00:00:00 2001 From: Inho Choi Date: Fri, 9 Dec 2022 02:01:06 +0900 Subject: [PATCH 26/27] =?UTF-8?q?:pencil2:=20=ED=95=84=EC=9A=94=20?= =?UTF-8?q?=EC=97=86=EB=8A=94=20=EC=A3=BC=EC=84=9D=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Views&ViewModels/MyPage/MyPageViewController.swift | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Workade/Views&ViewModels/MyPage/MyPageViewController.swift b/Workade/Views&ViewModels/MyPage/MyPageViewController.swift index d5a0adf7..ca4c6ce7 100644 --- a/Workade/Views&ViewModels/MyPage/MyPageViewController.swift +++ b/Workade/Views&ViewModels/MyPage/MyPageViewController.swift @@ -58,14 +58,6 @@ final class MyPageViewController: UIViewController { }), for: .touchUpInside) } -// func setData() { -// guard let user = UserManager.shared.user.value else { return } -// profileView.nameLabel.text = user.name -// profileView.jobLabel.text = user.job.rawValue -// -// // TODO: Combine이던, Binder던 콜렉션뷰 reload해야할것 같음 -// } - func setupStickerView() { guard let stickersArray = UserManager.shared.user.value?.stickers else { emptyStickerView.isHidden = false From cf801ae3b759a8ae1a02f7d5235973608d17eaf8 Mon Sep 17 00:00:00 2001 From: Inho Choi Date: Fri, 9 Dec 2022 02:01:52 +0900 Subject: [PATCH 27/27] =?UTF-8?q?:recycle:=20=EC=B4=88=EA=B8=B0=20?= =?UTF-8?q?=EA=B0=92=EC=9D=B4=200=EC=9C=BC=EB=A1=9C=20=ED=91=9C=EC=8B=9C?= =?UTF-8?q?=EB=90=98=EA=B2=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Workade/Views&ViewModels/Explore/ExploreViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Workade/Views&ViewModels/Explore/ExploreViewController.swift b/Workade/Views&ViewModels/Explore/ExploreViewController.swift index 7f336951..68ed018f 100644 --- a/Workade/Views&ViewModels/Explore/ExploreViewController.swift +++ b/Workade/Views&ViewModels/Explore/ExploreViewController.swift @@ -32,7 +32,7 @@ final class ExploreViewController: UIViewController { setupLayout() for region in Region.allCases { - regionButtons[region]?.peopleCount = UserManager.shared.activeUsers[region]?.count ?? -2 + regionButtons[region]?.peopleCount = UserManager.shared.activeUsers[region]?.count ?? 0 } viewModel.selectedRegion.bind { [weak self] region in