summaryrefslogtreecommitdiff
path: root/Sora/Views/Settings/Section/SettingsSectionContentRatingsView.swift
diff options
context:
space:
mode:
Diffstat (limited to 'Sora/Views/Settings/Section/SettingsSectionContentRatingsView.swift')
-rw-r--r--Sora/Views/Settings/Section/SettingsSectionContentRatingsView.swift74
1 files changed, 74 insertions, 0 deletions
diff --git a/Sora/Views/Settings/Section/SettingsSectionContentRatingsView.swift b/Sora/Views/Settings/Section/SettingsSectionContentRatingsView.swift
new file mode 100644
index 0000000..85b28af
--- /dev/null
+++ b/Sora/Views/Settings/Section/SettingsSectionContentRatingsView.swift
@@ -0,0 +1,74 @@
+import SwiftUI
+
+struct SettingsSectionContentRatingsView: View {
+ @EnvironmentObject var settings: SettingsManager
+
+ var body: some View {
+ List {
+ Section(header: Text("Display Content Ratings")) {
+ ForEach(BooruRating.allCases, id: \.self) { rating in
+ Toggle(
+ rating.rawValue,
+ isOn: Binding(
+ get: {
+ settings.displayRatings.contains(rating)
+ },
+ set: { isOn in
+ setRating(
+ ratingFor: &settings.displayRatings,
+ isOn: isOn,
+ rating: rating
+ )
+ }
+ )
+ )
+ }
+ }
+
+ Section(header: Text("Blur Content Ratings")) {
+ ForEach(BooruRating.allCases, id: \.self) { rating in
+ Toggle(
+ rating.rawValue,
+ isOn: Binding(
+ get: { settings.blurRatings.contains(rating) },
+ set: { isOn in
+ setRating(
+ ratingFor: &settings.blurRatings,
+ isOn: isOn,
+ rating: rating
+ )
+ }
+ )
+ )
+ }
+ }
+ }
+ .navigationTitle(Text("Content Filtering"))
+ #if !os(macOS)
+ .navigationBarTitleDisplayMode(.inline)
+ #endif
+ }
+
+ func setRating(
+ ratingFor: inout [BooruRating],
+ isOn: Bool,
+ rating: BooruRating
+ ) {
+ var newRatings = ratingFor
+
+ if isOn {
+ if !newRatings.contains(rating) {
+ newRatings.append(rating)
+ }
+ } else {
+ newRatings.removeAll { $0 == rating }
+ }
+
+ ratingFor = newRatings
+ }
+}
+
+#Preview {
+ SettingsSectionContentRatingsView()
+ .environmentObject(SettingsManager())
+}