Implement loading spinner when fetching current settings (IOS-168)
This commit is contained in:
parent
5b50e24b80
commit
79d8d8d508
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
//
|
||||
// File.swift
|
||||
//
|
||||
//
|
||||
// Created by Marcus Kida on 29.05.24.
|
||||
//
|
||||
|
||||
import Foundation
|
Loading…
Reference in New Issue