Combine initial and storage view

This commit is contained in:
Christoph Hagen
2025-02-23 20:34:02 +01:00
parent cdcbe21c0d
commit cf17b513d0
5 changed files with 132 additions and 63 deletions

View File

@ -33,7 +33,7 @@ struct MainView: App {
private var showInitialSetupSheet = false
@State
private var showStorageErrorSheet = false
private var showStorageStatusSheet = false
@State
private var showSettingsSheet = false
@ -176,7 +176,7 @@ struct MainView: App {
}
}
ToolbarItem {
Button(action: saveButtonPressed) {
Button(action: { showStorageStatusSheet = true }) {
Image(systemSymbol: content.saveState.symbol)
.foregroundStyle(content.saveState.color)
}
@ -199,8 +199,8 @@ struct MainView: App {
.environmentObject(content)
.environmentObject(selection)
}
.sheet(isPresented: $showStorageErrorSheet) {
StorageErrorView(isPresented: $showStorageErrorSheet)
.sheet(isPresented: $showStorageStatusSheet) {
StorageStatusView(isPresented: $showStorageStatusSheet)
.environmentObject(content)
}
.sheet(isPresented: $showSettingsSheet) {
@ -230,28 +230,15 @@ struct MainView: App {
}
}
private func saveButtonPressed() {
switch content.saveState {
case .storageNotInitialized:
showInitialSheet()
case .isSaved, .needsSave:
content.saveUnconditionally()
case .isSaving:
break
case .failedToSave, .savingPausedDueToLoadErrors:
showStorageErrorSheet = true
}
}
private func loadContent() {
guard content.storage.contentScope != nil else {
showInitialSheet()
showStorageStatusSheet = true
return
}
content.loadFromDisk {
prepareAfterLoad()
if !content.storageErrors.isEmpty {
self.showStorageErrorSheet = true
self.showStorageStatusSheet = true
}
}
}
@ -270,11 +257,5 @@ struct MainView: App {
selection.file = content.files.first
}
}
private func showInitialSheet() {
DispatchQueue.main.async {
showInitialSetupSheet = true
}
}
}