Implement loading spinner when fetching current settings (IOS-168)

This commit is contained in:
Marcus Kida 2024-05-29 17:36:47 +02:00
parent 5b50e24b80
commit 79d8d8d508
No known key found for this signature in database
GPG Key ID: 19FF64E08013CA40
3 changed files with 55 additions and 31 deletions

View File

@ -31,38 +31,44 @@ struct PrivacySafetyView: View {
@StateObject var viewModel: PrivacySafetyViewModel
var body: some View {
Form {
Section(L10n.Scene.Settings.PrivacySafety.Preset.title) {
CheckableButton(text: L10n.Scene.Settings.PrivacySafety.Preset.openAndPublic, isChecked: viewModel.preset == .openPublic, action: {
viewModel.preset = .openPublic
})
CheckableButton(text: L10n.Scene.Settings.PrivacySafety.Preset.privateAndRestricted, isChecked: viewModel.preset == .privateRestricted, action: {
viewModel.preset = .privateRestricted
})
if viewModel.preset == .custom {
CheckableButton(text: L10n.Scene.Settings.PrivacySafety.Preset.custom, isChecked: viewModel.preset == .custom, action: {
viewModel.preset = .custom
})
}
}
Section {
Picker(selection: $viewModel.visibility) {
ForEach(PrivacySafetyViewModel.Visibility.allCases, id: \.self) {
Text($0.title)
Group {
if !viewModel.isInitialized {
ProgressView()
} else {
Form {
Section(L10n.Scene.Settings.PrivacySafety.Preset.title) {
CheckableButton(text: L10n.Scene.Settings.PrivacySafety.Preset.openAndPublic, isChecked: viewModel.preset == .openPublic, action: {
viewModel.preset = .openPublic
})
CheckableButton(text: L10n.Scene.Settings.PrivacySafety.Preset.privateAndRestricted, isChecked: viewModel.preset == .privateRestricted, action: {
viewModel.preset = .privateRestricted
})
if viewModel.preset == .custom {
CheckableButton(text: L10n.Scene.Settings.PrivacySafety.Preset.custom, isChecked: viewModel.preset == .custom, action: {
viewModel.preset = .custom
})
}
}
} label: {
Text(L10n.Scene.Settings.PrivacySafety.DefaultPostVisibility.title)
}
Section {
Picker(selection: $viewModel.visibility) {
ForEach(PrivacySafetyViewModel.Visibility.allCases, id: \.self) {
Text($0.title)
}
} label: {
Text(L10n.Scene.Settings.PrivacySafety.DefaultPostVisibility.title)
}
}
Section {
Toggle(L10n.Scene.Settings.PrivacySafety.manuallyApproveFollowRequests, isOn: $viewModel.manuallyApproveFollowRequests)
Toggle(L10n.Scene.Settings.PrivacySafety.showFollowersAndFollowing, isOn: $viewModel.showFollowersAndFollowing)
Toggle(L10n.Scene.Settings.PrivacySafety.suggestMyAccountToOthers, isOn: $viewModel.suggestMyAccountToOthers)
Toggle(L10n.Scene.Settings.PrivacySafety.appearInSearchEngines, isOn: $viewModel.appearInSearches)
}
Section {
Toggle(L10n.Scene.Settings.PrivacySafety.manuallyApproveFollowRequests, isOn: $viewModel.manuallyApproveFollowRequests)
Toggle(L10n.Scene.Settings.PrivacySafety.showFollowersAndFollowing, isOn: $viewModel.showFollowersAndFollowing)
Toggle(L10n.Scene.Settings.PrivacySafety.suggestMyAccountToOthers, isOn: $viewModel.suggestMyAccountToOthers)
Toggle(L10n.Scene.Settings.PrivacySafety.appearInSearchEngines, isOn: $viewModel.appearInSearches)
}
}
}
}
.onAppear(perform: viewModel.viewDidAppear)

View File

@ -2,6 +2,8 @@
import Foundation
import MastodonLocalization
import MastodonCore
import MastodonSDK
class PrivacySafetyViewModel: ObservableObject {
enum Preset {
@ -23,6 +25,8 @@ class PrivacySafetyViewModel: ObservableObject {
}
}
weak var appContext: AppContext?
@Published var preset: Preset = .openPublic {
didSet { applyPreset(preset) }
}
@ -47,9 +51,13 @@ class PrivacySafetyViewModel: ObservableObject {
}
private var doNotEvaluate = true
@Published var isInitialized = false
func viewDidAppear() {
doNotEvaluate = false
if !isInitialized {
loadSettings()
}
}
}
@ -87,8 +95,10 @@ extension PrivacySafetyViewModel {
}
func loadSettings() {
Task {
Task { @MainActor in
isInitialized = true
}
}

View File

@ -0,0 +1,8 @@
//
// File.swift
//
//
// Created by Marcus Kida on 29.05.24.
//
import Foundation