Skip to content

Commit

Permalink
fix: Introduce folder metadata and show URLs in a footer (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbmorley authored Feb 10, 2024
1 parent e8168e0 commit 444cce7
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 4 deletions.
1 change: 1 addition & 0 deletions Folders/FoldersApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct FoldersApp: App {

WindowGroup {
LibraryView(applicationModel: applicationModel)
.environmentObject(applicationModel)
}

}
Expand Down
2 changes: 1 addition & 1 deletion Folders/Utilities/Store.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Store {
static let subtype = Expression<String?>("subtype")
}

static let majorVersion = 17
static let majorVersion = 18

var observers: [StoreObserver] = []

Expand Down
7 changes: 6 additions & 1 deletion Folders/Views/GridView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,12 @@ extension InnerGridView: DirectoryWatcherDelegate {
// TODO: Insert in the correct place.
// TODO: We may need to rate-limit these updates.
var snapshot = dataSource.snapshot()
snapshot.appendItems([url])

if snapshot.numberOfSections < 1 {
snapshot.appendSections([.none])
}

snapshot.appendItems([url], toSection: Section.none)
dataSource.apply(snapshot, animatingDifferences: true)
}

Expand Down
84 changes: 82 additions & 2 deletions Folders/Views/LibraryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,87 @@

import SwiftUI

struct FolderSettings: Codable {

let url: URL

}


class FolderModel: ObservableObject {

let url: URL

@Published var settings: FolderSettings?

init(url: URL) {
self.url = url
}

func start() {
let settingsURL = url.appendingPathComponent("folders-settings.json") // TODO: Could I get macOS to hide these for me?
guard FileManager.default.fileExists(atPath: settingsURL.path) else {
return
}
do {
let data = try Data(contentsOf: settingsURL)
let decoder = JSONDecoder()
let settings = try decoder.decode(FolderSettings.self, from: data)
self.settings = settings
} catch {
print("Failed to load folder settings with error \(error).")
}
}

func stop() {

}

}

struct FolderView: View {

@EnvironmentObject var applicationModel: ApplicationModel

@Environment(\.openURL) var openURL

@StateObject var folderModel: FolderModel

let url: URL

init(url: URL) {
self.url = url
_folderModel = StateObject(wrappedValue: FolderModel(url: url))
}

var body: some View {
VStack(alignment: .leading, spacing: 0) {
GridView(store: applicationModel.store, directoryURL: url)
if let url = folderModel.settings?.url {
Divider()
HStack {
Button {
openURL(url)
} label: {
Text(url.absoluteString)
}
.buttonStyle(.link)
}
.padding(8)
.background(.thinMaterial)
}
}
.navigationTitle(url.displayName)
.onAppear {
folderModel.start()
}
.onDisappear {
folderModel.stop()
}
}

}

struct LibraryView: View {

@ObservedObject var applicationModel: ApplicationModel
Expand All @@ -38,8 +119,7 @@ struct LibraryView: View {
Sidebar(applicationModel: applicationModel, sceneModel: sceneModel)
} detail: {
if let folderURL = sceneModel.selection?.folderURL {
GridView(store: applicationModel.store, directoryURL: folderURL)
.navigationTitle(folderURL.displayName)
FolderView(url: folderURL)
.id(folderURL)
}
}
Expand Down

0 comments on commit 444cce7

Please sign in to comment.