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

@ -23,6 +23,7 @@ struct InitialSetupView: View {
if let message {
Text(message)
.padding(.bottom)
.lineLimit(10)
}
}
.padding()
@ -52,14 +53,25 @@ struct InitialSetupView: View {
set(message: "Failed to set content path")
return
}
DispatchQueue.main.async {
do {
try content.loadFromDisk()
} catch {
set(message: "Failed to load database: \(error)")
DispatchQueue.global().async {
let loader = ModelLoader(content: content, storage: content.storage)
let result = loader.load()
guard result.errors.isEmpty else {
let message = "Failed to load database\n" + result.errors.sorted().joined(separator: "\n")
set(message: message)
return
}
dismiss()
DispatchQueue.main.async {
content.files = result.files
content.posts = result.posts
content.pages = result.pages
content.tags = result.tags
content.settings = result.settings
content.tagOverview = result.tagOverview
dismiss()
}
}
}

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
}
}