From c038c91808c4f458e82cac560f5625c57e081454 Mon Sep 17 00:00:00 2001 From: oolxg Date: Wed, 12 Jul 2023 21:40:07 +0200 Subject: [PATCH] Fixed #6 + some imporvements --- .../Core/Search/Filter/FiltersFeature.swift | 35 ++++++++++++------- Hanami/Tools/Defaults.swift | 4 +-- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/Hanami/App/Core/Search/Filter/FiltersFeature.swift b/Hanami/App/Core/Search/Filter/FiltersFeature.swift index 564b0ab..d485b14 100644 --- a/Hanami/App/Core/Search/Filter/FiltersFeature.swift +++ b/Hanami/App/Core/Search/Filter/FiltersFeature.swift @@ -115,29 +115,40 @@ struct FiltersFeature: ReducerProtocol { return .none - case .mangaStatusButtonTapped(let tag): - if tag.state == .selected { - state.mangaStatuses[id: tag.id]!.state = .notSelected + case .mangaStatusButtonTapped(let tagContainer): + if tagContainer.state == .selected { + state.mangaStatuses[id: tagContainer.id]!.state = .notSelected } else { - state.mangaStatuses[id: tag.id]!.state = .selected + state.mangaStatuses[id: tagContainer.id]!.state = .selected } return hapticClient.generateFeedback(.light).fireAndForget() - case .contentRatingButtonTapped(let tag): - if tag.state == .selected { - state.contentRatings[id: tag.id]!.state = .notSelected + case .contentRatingButtonTapped(let tagContainer): + if tagContainer.state == .selected { + state.contentRatings[id: tagContainer.id]!.state = .notSelected } else { - state.contentRatings[id: tag.id]!.state = .selected + state.contentRatings[id: tagContainer.id]!.state = .selected + } + + // setting all tags to notSelected when user tapped on `safe` + if tagContainer.tag == .safe && tagContainer.state != .selected { + for tagID in state.contentRatings.ids { + state.contentRatings[id: tagID]!.state = .notSelected + } + state.contentRatings[id: tagContainer.id]!.state = .selected + } else { + let safeTagID = state.contentRatings.first(where: { $0.tag == .safe })!.id + state.contentRatings[id: safeTagID]!.state = .notSelected } return hapticClient.generateFeedback(.light).fireAndForget() - case .publicationDemographicButtonTapped(let tag): - if tag.state == .selected { - state.publicationDemographics[id: tag.id]!.state = .notSelected + case .publicationDemographicButtonTapped(let tagContainer): + if tagContainer.state == .selected { + state.publicationDemographics[id: tagContainer.id]!.state = .notSelected } else { - state.publicationDemographics[id: tag.id]!.state = .selected + state.publicationDemographics[id: tagContainer.id]!.state = .selected } return hapticClient.generateFeedback(.light).fireAndForget() diff --git a/Hanami/Tools/Defaults.swift b/Hanami/Tools/Defaults.swift index 733f618..ac6cd4d 100644 --- a/Hanami/Tools/Defaults.swift +++ b/Hanami/Tools/Defaults.swift @@ -41,13 +41,13 @@ enum Defaults { } enum Feedback { - static var feedbackDomain: URL? { + static let apiURL: URL? = { if AppUtil.appConfiguration != .debug, var urlString = Bundle.main.infoDictionary?["API_URL"] as? String { urlString = "https://" + urlString return URL(string: urlString) } return nil - } + }() } }