Skip to content

Commit

Permalink
Add ArchiveCategoryLinkable (#950)
Browse files Browse the repository at this point in the history
It makes a category linkable!
  • Loading branch information
bolsinga authored Oct 6, 2024
1 parent 3ac6491 commit bc9d508
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
17 changes: 17 additions & 0 deletions Sources/Site/Music/UI/ArchiveCategoryLinkable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// ArchiveCategoryLinkable.swift
// site
//
// Created by Greg Bolsinga on 10/5/24.
//

import SwiftUI

struct ArchiveCategoryLinkable: ArchiveSharable, Linkable {
let vault: Vault
let category: ArchiveCategory

var subject: Text { Text(category.title) }
var message: Text { subject }
var url: URL? { vault.categoryURLMap[category] }
}
10 changes: 0 additions & 10 deletions Sources/Site/Music/UI/ArchiveSharable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,3 @@ extension ArtistDigest: ArchiveSharable {
Text(descriptor)
}
}

extension ArchiveCategory: ArchiveSharable {
var subject: Text {
Text(self.title)
}

var message: Text {
Text(self.title)
}
}
11 changes: 3 additions & 8 deletions Sources/Site/Music/UI/ArchiveSharableModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@

import SwiftUI

struct ArchiveSharableModifier<T: ArchiveSharable>: ViewModifier {
struct ArchiveSharableModifier<T: ArchiveSharable & Linkable>: ViewModifier {
let item: T?
let url: URL?

func body(content: Content) -> some View {
#if os(tvOS)
content // ShareLink not available on tvOS
#else
if let url, let item {
if let item, let url = item.url {
content
.toolbar { ArchiveSharableToolbarContent(item: item, url: url) }
} else {
Expand All @@ -27,10 +26,6 @@ struct ArchiveSharableModifier<T: ArchiveSharable>: ViewModifier {

extension View {
func archiveShare<T: ArchiveSharable & Linkable>(_ item: T?) -> some View {
modifier(ArchiveSharableModifier(item: item, url: item?.url))
}

func archiveShare<T: ArchiveSharable>(_ item: T?, url: URL?) -> some View {
modifier(ArchiveSharableModifier(item: item, url: url))
modifier(ArchiveSharableModifier(item: item))
}
}
2 changes: 1 addition & 1 deletion Sources/Site/Music/UI/CategoryDetailModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct CategoryDetailModifier: ViewModifier {
func body(content: Content) -> some View {
NavigationStack(path: $path) {
content
.archiveShare(category, url: vault.categoryURLMap[category])
.archiveShare(ArchiveCategoryLinkable(vault: vault, category: category))
.musicDestinations(vault, path: path)
}
}
Expand Down

0 comments on commit bc9d508

Please sign in to comment.