Reset data after folder change
This commit is contained in:
parent
9a53e020a7
commit
9c828ff80a
@ -52,10 +52,8 @@ struct InitialSetupView: View {
|
|||||||
set(message: "Failed to set content path")
|
set(message: "Failed to set content path")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
print("Selected folder, initializing storage")
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
do {
|
do {
|
||||||
print("Loading disk content")
|
|
||||||
try content.loadFromDisk()
|
try content.loadFromDisk()
|
||||||
} catch {
|
} catch {
|
||||||
set(message: "Failed to load database: \(error)")
|
set(message: "Failed to load database: \(error)")
|
||||||
|
@ -203,8 +203,6 @@ struct MainView: App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func loadContent() {
|
private func loadContent() {
|
||||||
#warning("Remove")
|
|
||||||
content.storage.clearContentPath()
|
|
||||||
guard content.storage.hasContentFolders else {
|
guard content.storage.hasContentFolders else {
|
||||||
showInitialSheet()
|
showInitialSheet()
|
||||||
return
|
return
|
||||||
|
@ -47,7 +47,6 @@ extension Content {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let settings = try storage.loadSettings() // Uses defaults if missing
|
let settings = try storage.loadSettings() // Uses defaults if missing
|
||||||
print("Loaded settings")
|
|
||||||
let imageDescriptions = try storage.loadFileDescriptions().reduce(into: [:]) { descriptions, description in
|
let imageDescriptions = try storage.loadFileDescriptions().reduce(into: [:]) { descriptions, description in
|
||||||
descriptions[description.fileId] = description
|
descriptions[description.fileId] = description
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ final class Content: ObservableObject {
|
|||||||
var tagOverview: TagOverviewPage?
|
var tagOverview: TagOverviewPage?
|
||||||
|
|
||||||
@Published
|
@Published
|
||||||
private(set) var results: [ItemId : PageGenerationResults] = [:]
|
private(set) var results: [ItemId : PageGenerationResults]
|
||||||
|
|
||||||
@Published
|
@Published
|
||||||
private(set) var isGeneratingWebsite = false
|
private(set) var isGeneratingWebsite = false
|
||||||
@ -43,15 +43,27 @@ final class Content: ObservableObject {
|
|||||||
self.tags = tags
|
self.tags = tags
|
||||||
self.files = files
|
self.files = files
|
||||||
self.tagOverview = tagOverview
|
self.tagOverview = tagOverview
|
||||||
|
self.results = [:]
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
self.settings = .mock
|
self.settings = .default
|
||||||
self.posts = []
|
self.posts = []
|
||||||
self.pages = []
|
self.pages = []
|
||||||
self.tags = []
|
self.tags = []
|
||||||
self.files = []
|
self.files = []
|
||||||
self.tagOverview = nil
|
self.tagOverview = nil
|
||||||
|
self.results = [:]
|
||||||
|
}
|
||||||
|
|
||||||
|
private func clear() {
|
||||||
|
self.settings = .default
|
||||||
|
self.posts = []
|
||||||
|
self.pages = []
|
||||||
|
self.tags = []
|
||||||
|
self.files = []
|
||||||
|
self.tagOverview = nil
|
||||||
|
self.results = [:]
|
||||||
}
|
}
|
||||||
|
|
||||||
var images: [FileResource] {
|
var images: [FileResource] {
|
||||||
@ -73,4 +85,16 @@ final class Content: ObservableObject {
|
|||||||
// TODO: Insert at correct index?
|
// TODO: Insert at correct index?
|
||||||
pages.insert(page, at: 0)
|
pages.insert(page, at: 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func update(contentPath: URL) {
|
||||||
|
guard storage.save(contentPath: contentPath) else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
clear()
|
||||||
|
do {
|
||||||
|
try loadFromDisk()
|
||||||
|
} catch {
|
||||||
|
print("Failed to reload content: \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ extension Content {
|
|||||||
private static let dbPath = FileManager.default.documentDirectory.appendingPathComponent("db").path()
|
private static let dbPath = FileManager.default.documentDirectory.appendingPathComponent("db").path()
|
||||||
|
|
||||||
static let mock: Content = Content(
|
static let mock: Content = Content(
|
||||||
settings: .mock,
|
settings: .default,
|
||||||
posts: [.empty, .mock, .fullMock],
|
posts: [.empty, .mock, .fullMock],
|
||||||
pages: [.empty],
|
pages: [.empty],
|
||||||
tags: [.hiking, .mountains, .nature, .sports],
|
tags: [.hiking, .mountains, .nature, .sports],
|
||||||
|
@ -2,7 +2,7 @@ import Foundation
|
|||||||
|
|
||||||
extension Settings {
|
extension Settings {
|
||||||
|
|
||||||
static let mock: Settings = .init(
|
static let `default`: Settings = .init(
|
||||||
paths: .default,
|
paths: .default,
|
||||||
navigationItems: [],
|
navigationItems: [],
|
||||||
posts: .default,
|
posts: .default,
|
||||||
|
@ -560,6 +560,7 @@ final class Storage: ObservableObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
func save(outputPath: URL) -> Bool {
|
func save(outputPath: URL) -> Bool {
|
||||||
guard let contentPath else { return false }
|
guard let contentPath else { return false }
|
||||||
guard let bookmarkData = encode(url: outputPath) else { return false }
|
guard let bookmarkData = encode(url: outputPath) else { return false }
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
import SFSafeSymbols
|
||||||
|
|
||||||
struct FolderOnDiskPropertyView: View {
|
struct FolderOnDiskPropertyView: View {
|
||||||
|
|
||||||
@ -7,21 +8,31 @@ struct FolderOnDiskPropertyView: View {
|
|||||||
@Binding
|
@Binding
|
||||||
var folder: URL?
|
var folder: URL?
|
||||||
|
|
||||||
|
@Binding
|
||||||
|
var isStale: Bool
|
||||||
|
|
||||||
let footer: LocalizedStringKey
|
let footer: LocalizedStringKey
|
||||||
|
|
||||||
let update: (URL) -> Void
|
let update: (URL) -> Void
|
||||||
|
|
||||||
init(title: LocalizedStringKey, folder: Binding<URL?>, footer: LocalizedStringKey, update: @escaping (URL) -> Void) {
|
init(title: LocalizedStringKey, folder: Binding<URL?>, isStale: Binding<Bool>, footer: LocalizedStringKey, update: @escaping (URL) -> Void) {
|
||||||
self.title = title
|
self.title = title
|
||||||
self._folder = folder
|
self._folder = folder
|
||||||
|
self._isStale = isStale
|
||||||
self.footer = footer
|
self.footer = footer
|
||||||
self.update = update
|
self.update = update
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
GenericPropertyView(title: title, footer: footer) {
|
VStack(alignment: .leading) {
|
||||||
|
|
||||||
HStack(alignment: .firstTextBaseline) {
|
HStack(alignment: .firstTextBaseline) {
|
||||||
Text(folder?.path() ?? "No folder selected")
|
Text(title)
|
||||||
|
.font(.headline)
|
||||||
|
if isStale {
|
||||||
|
Image(systemSymbol: .exclamationmarkTriangle)
|
||||||
|
.foregroundStyle(.yellow)
|
||||||
|
}
|
||||||
Spacer()
|
Spacer()
|
||||||
Button("Select") {
|
Button("Select") {
|
||||||
guard let url = openFolderSelectionPanel() else {
|
guard let url = openFolderSelectionPanel() else {
|
||||||
@ -32,6 +43,11 @@ struct FolderOnDiskPropertyView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Text(folder?.path() ?? "No folder selected")
|
||||||
|
.padding(.bottom, 5)
|
||||||
|
Text(footer)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
.padding(.bottom)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,16 +18,15 @@ struct PathSettingsView: View {
|
|||||||
FolderOnDiskPropertyView(
|
FolderOnDiskPropertyView(
|
||||||
title: "Content Folder",
|
title: "Content Folder",
|
||||||
folder: $content.storage.contentPath,
|
folder: $content.storage.contentPath,
|
||||||
|
isStale: $content.storage.contentPathUrlIsStale,
|
||||||
footer: "The folder where the raw content of the website is stored") { url in
|
footer: "The folder where the raw content of the website is stored") { url in
|
||||||
guard content.storage.save(contentPath: url) else {
|
content.update(contentPath: url)
|
||||||
return
|
|
||||||
}
|
|
||||||
#warning("Reload database")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FolderOnDiskPropertyView(
|
FolderOnDiskPropertyView(
|
||||||
title: "Output Folder",
|
title: "Output Folder",
|
||||||
folder: $content.storage.outputPath,
|
folder: $content.storage.outputPath,
|
||||||
|
isStale: $content.storage.outputPathUrlIsStale,
|
||||||
footer: "The folder where the generated website is stored") { url in
|
footer: "The folder where the generated website is stored") { url in
|
||||||
content.storage.save(outputPath: url)
|
content.storage.save(outputPath: url)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user