Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert Archive Logger to an instance property #763

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}