Skip to content

Commit

Permalink
Convert Archive Logger to an instance property (#763)
Browse files Browse the repository at this point in the history
  • Loading branch information
bolsinga committed Mar 6, 2024
1 parent 1edd225 commit fd6323a
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions Sources/Site/Music/UI/ArchiveNavigation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,21 @@
import Foundation
import os

extension Logger {
static let archive = Logger(category: "archive")
}

@Observable final class ArchiveNavigation {
var selectedCategory: ArchiveCategory?
var navigationPath: [ArchivePath] = []

@ObservationIgnored internal var pendingNavigationPath: [ArchivePath]?

private let archive = Logger(category: "archive")

func restoreNavigation(selectedCategoryStorage: ArchiveCategory?, pathData: Data?) {
if let selectedCategoryStorage {
if let pathData {
// Hold onto the loading navigationPath for after the selectedCategory changes.
var pending = [ArchivePath]()
pending.jsonData = pathData
Logger.archive.log(
archive.log(
"pending save: \(pending.map { $0.formatted() }.joined(separator: ":"), privacy: .public)"
)
pendingNavigationPath = pending
Expand All @@ -42,23 +40,23 @@ extension Logger {
func restorePendingData() {
// Change the navigationPath after selectedCategory changes.
if let pendingNavigationPath {
Logger.archive.log("pending restore")
archive.log("pending restore")
navigationPath = pendingNavigationPath
self.pendingNavigationPath = nil
}
}

func navigate(to path: ArchivePath) {
guard path != navigationPath.last else {
Logger.archive.log("already presented: \(path.formatted(), privacy: .public)")
archive.log("already presented: \(path.formatted(), privacy: .public)")
return
}
Logger.archive.log("nav to path: \(path.formatted(), privacy: .public)")
archive.log("nav to path: \(path.formatted(), privacy: .public)")
navigationPath.append(path)
}

func navigate(to category: ArchiveCategory?) {
Logger.archive.log("nav to category: \(category?.rawValue ?? "nil", privacy: .public)")
archive.log("nav to category: \(category?.rawValue ?? "nil", privacy: .public)")
selectedCategory = category
}
}

0 comments on commit fd6323a

Please sign in to comment.