TeraStorageSettingsSection.swift (1961B)
1 import SwiftUI 2 3 struct TeraStorageSettingsSection: View { 4 @ObservedObject var settingsStore: TeraSettingsStore 5 @ObservedObject var todayStore: TeraTodayStore 6 @EnvironmentObject private var appModel: TeraAppModel 7 8 var body: some View { 9 Section("Local media storage") { 10 Stepper( 11 "Cache: \(settingsStore.mediaCacheMegabytes) MB", 12 value: $settingsStore.mediaCacheMegabytes, 13 in: 16 ... 2048, 14 step: 16 15 ) 16 Stepper( 17 "Artifacts: \(settingsStore.mediaCacheArtifacts)", 18 value: $settingsStore.mediaCacheArtifacts, 19 in: 1 ... 10000, 20 step: 100 21 ) 22 Button("Free cached photos") { 23 guard let context = todayStore.selectedContext else { return } 24 Task { await settingsStore.cleanupMediaCache(context: context) } 25 } 26 .disabled(settingsStore.isWorking || todayStore.selectedContext == nil) 27 .accessibilityIdentifier("tera.settings.cache.cleanup") 28 Text("Clears cached photos from this context. Run again if more remain. Pending drafts and transfer receipts are retained. If storage is completely full, free device space first.") 29 .font(.caption) 30 .foregroundStyle(.secondary) 31 Button("Save network and storage settings") { 32 Task { 33 if await settingsStore.saveSettings() { 34 await appModel.applySettingsReconfiguration() 35 } 36 } 37 } 38 .disabled(settingsStore.isWorking) 39 .accessibilityIdentifier("radroots.settings.save") 40 if let message = settingsStore.message { 41 Text(message).foregroundStyle(.secondary) 42 } 43 if let failureCode = settingsStore.failureCode { 44 Text("Error code \(failureCode)") 45 .font(.caption.monospaced()) 46 .foregroundStyle(.secondary) 47 .accessibilityIdentifier("radroots.settings.failure_code") 48 } 49 } 50 } 51 }