diff --git a/Particle/Particle/Sources/Data/Network/RecordMapper.swift b/Particle/Particle/Sources/Data/Network/RecordMapper.swift index f4b248c..b208eb4 100644 --- a/Particle/Particle/Sources/Data/Network/RecordMapper.swift +++ b/Particle/Particle/Sources/Data/Network/RecordMapper.swift @@ -15,7 +15,7 @@ protocol RecordMapperProtocol { struct RecordMapper: RecordMapperProtocol { func mapRecords(model: [RecordReadDTO]) -> [SectionOfRecordTag] { - guard let userInterestedTags = UserDefaults.standard.object(forKey: "INTERESTED_TAGS") as? [String] else { + guard let userInterestedTags = UserSingleton.shared.info?.interestedTags else { return [] } guard model.isEmpty == false else { return [] } @@ -24,8 +24,8 @@ struct RecordMapper: RecordMapperProtocol { a.fetchDate().timeIntervalSince1970 > b.fetchDate().timeIntervalSince1970 } var sectionList: [SectionOfRecordTag] = [.init(header: "My", items: sortedModel)] - let tags = userInterestedTags.map { $0.replacingOccurrences(of: "#", with: "")} - for tag in tags { +// let tags = userInterestedTags.map { $0.replacingOccurrences(of: "#", with: "")} + for tag in userInterestedTags { let filteredList = sortedModel.filter { $0.tags.contains(tag) } if filteredList.isEmpty == false { sectionList.append(.init(header: tag, items: filteredList)) diff --git a/Particle/Particle/Sources/Main/HomeTab/AddArticle/SetAdditionalInformation/SetAdditionalInformationViewController.swift b/Particle/Particle/Sources/Main/HomeTab/AddArticle/SetAdditionalInformation/SetAdditionalInformationViewController.swift index 05e183d..d966b5e 100644 --- a/Particle/Particle/Sources/Main/HomeTab/AddArticle/SetAdditionalInformation/SetAdditionalInformationViewController.swift +++ b/Particle/Particle/Sources/Main/HomeTab/AddArticle/SetAdditionalInformation/SetAdditionalInformationViewController.swift @@ -335,8 +335,8 @@ final class SetAdditionalInformationViewController: UIViewController, } private func fetchInterestedTags() { - guard let userInterestedTags = UserDefaults.standard.object(forKey: "INTERESTED_TAGS") as? [String] else { return } - let fetchedTags = userInterestedTags.map { ($0, false) } + guard let userInterestedTags = UserSingleton.shared.info?.interestedTags else { return } + let fetchedTags = userInterestedTags.map { ("#\($0)", false) } tags.accept(fetchedTags) } diff --git a/Particle/Particle/Sources/Main/HomeTab/RecordDetail/RecordDetailViewController.swift b/Particle/Particle/Sources/Main/HomeTab/RecordDetail/RecordDetailViewController.swift index 3bdd3a3..e8bdf47 100644 --- a/Particle/Particle/Sources/Main/HomeTab/RecordDetail/RecordDetailViewController.swift +++ b/Particle/Particle/Sources/Main/HomeTab/RecordDetail/RecordDetailViewController.swift @@ -337,6 +337,11 @@ final class RecordDetailViewController: UIViewController, } .disposed(by: disposeBag) + guard let interestedRecords = UserSingleton.shared.info?.interestedRecords else { return } + let bool = interestedRecords.contains(data.value.id) + isLike.accept(bool) + heartButton.setImage(UIImage(named: bool ? "heartFull" : "heart"), for: .normal) + isLike .skip(1) .bind { [weak self] bool in diff --git a/Particle/Particle/Sources/Root/LoggedOut/SelectTag/View/Accordion.swift b/Particle/Particle/Sources/Root/LoggedOut/SelectTag/View/Accordion.swift index b565fc7..8d6a09a 100644 --- a/Particle/Particle/Sources/Root/LoggedOut/SelectTag/View/Accordion.swift +++ b/Particle/Particle/Sources/Root/LoggedOut/SelectTag/View/Accordion.swift @@ -40,8 +40,8 @@ final class Accordion: UIView { private var disposeBag = DisposeBag() private var interestedTags: [String] { - if let interestedTags = UserDefaults.standard.object(forKey: "INTERESTED_TAGS") as? [String] { - return interestedTags + if let interestedTags = UserSingleton.shared.info?.interestedTags { + return interestedTags.map { "#\($0)" } } else { return [] } diff --git a/Particle/Particle/Sources/Utils/UserSingleton.swift b/Particle/Particle/Sources/Utils/UserSingleton.swift new file mode 100644 index 0000000..a312a17 --- /dev/null +++ b/Particle/Particle/Sources/Utils/UserSingleton.swift @@ -0,0 +1,27 @@ +// +// UserSingleton.swift +// Particle +// +// Created by 이원빈 on 7/13/24. +// + +import Foundation + +final class UserSingleton { + static let shared = UserSingleton() + private let userRepository: UserRepository + + var info: UserReadDTO? { + do { + return try userRepository.getMyProfile() + } catch { + Console.error(error.localizedDescription) + return nil + } + } + + private init() { + let userDataSource = LocalUserDataSource(coreData: .shared) + self.userRepository = DefaultUserRepository(userDataSource: userDataSource) + } +}