Rework storage structs, link preview

This commit is contained in:
Christoph Hagen
2025-01-08 14:59:04 +01:00
parent b99c064d10
commit a7197b9628
75 changed files with 1365 additions and 1454 deletions

View File

@ -69,6 +69,12 @@ struct MainView: App {
@State
private var showInitialSetupSheet = false
@State
private var showLoadErrorSheet = false
@State
private var loadErrors: [String] = []
@ViewBuilder
var sidebar: some View {
switch selectedTab {
@ -202,14 +208,30 @@ struct MainView: App {
.environment(\.language, language)
.environmentObject(content)
}
.sheet(isPresented: $showLoadErrorSheet) {
VStack {
Text("Failed to load database")
.font(.headline)
List(loadErrors, id: \.self) { error in
HStack {
Text(error)
Spacer()
}
}
.frame(minHeight: 200)
Button("Dismiss", action: { showLoadErrorSheet = false })
.padding()
}
.padding()
}
}
}
private func save() {
do {
try content.saveToDisk()
} catch {
print("Failed to save content: \(error.localizedDescription)")
guard content.saveToDisk() else {
print("Failed to save content")
#warning("Show error message")
return
}
}
@ -218,10 +240,12 @@ struct MainView: App {
showInitialSheet()
return
}
do {
try content.loadFromDisk()
} catch {
print("Failed to load content: \(error.localizedDescription)")
content.loadFromDisk { errors in
guard !errors.isEmpty else {
return
}
self.loadErrors = errors
self.showLoadErrorSheet = true
}
}