From bbf77117035f00dcc00eebddf9853e3e5503bf5a Mon Sep 17 00:00:00 2001 From: Xin Liu Date: Fri, 21 Jul 2023 03:47:32 -0700 Subject: [PATCH] Show pinned status --- Planet/Entities/MyPlanetModel.swift | 12 ++++++++++++ Planet/Views/My/MyPlanetEditView.swift | 12 +++++++++++- Planet/Views/Sidebar/MyPlanetSidebarItem.swift | 13 +++++++++++-- Planet/versioning.xcconfig | 2 +- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/Planet/Entities/MyPlanetModel.swift b/Planet/Entities/MyPlanetModel.swift index a292ca72..4e92fb92 100644 --- a/Planet/Entities/MyPlanetModel.swift +++ b/Planet/Entities/MyPlanetModel.swift @@ -1778,6 +1778,18 @@ extension MyPlanetModel { navigation.sort(by: { $0.weight < $1.weight }) return navigation } + + var isPinned: Bool { + // TODO: Is this the best way to check if a planet is pinned? + if let localCID = lastPublishedCID, localCID.count > 0, + let remoteCID = pinnablePinCID, remoteCID.count > 0 + { + if localCID == remoteCID { + return true + } + } + return false + } } struct PublicPlanetModel: Codable { diff --git a/Planet/Views/My/MyPlanetEditView.swift b/Planet/Views/My/MyPlanetEditView.swift index ddea5a4f..254457e5 100644 --- a/Planet/Views/My/MyPlanetEditView.swift +++ b/Planet/Views/My/MyPlanetEditView.swift @@ -224,7 +224,13 @@ struct MyPlanetEditView: View { if let status = pinnablePinStatus { Button { - + if let url = planet.browserURL { + debugPrint("Pinnable: Open preview URL \(url)") + NSWorkspace.shared.open(url) + } + else { + debugPrint("Pinnable: Preview URL is not available") + } } label: { if let cid = pinnablePinCID { if cid == planet.lastPublishedCID { @@ -251,6 +257,10 @@ struct MyPlanetEditView: View { pinnablePinStatus = status if let cid = status.last_known_cid { pinnablePinCID = cid + if cid != planet.pinnablePinCID { + planet.pinnablePinCID = cid + try? await planet.save() + } } } } diff --git a/Planet/Views/Sidebar/MyPlanetSidebarItem.swift b/Planet/Views/Sidebar/MyPlanetSidebarItem.swift index 0c375402..7287ab42 100644 --- a/Planet/Views/Sidebar/MyPlanetSidebarItem.swift +++ b/Planet/Views/Sidebar/MyPlanetSidebarItem.swift @@ -15,8 +15,17 @@ struct MyPlanetSidebarItem: View { .font(.body) .foregroundColor(.primary) Spacer() - LoadingIndicatorView() - .opacity(planet.isPublishing ? 1.0 : 0.0) + if planet.isPublishing { + LoadingIndicatorView() + } else { + if planet.isPinned { + Image(systemName: "externaldrive.fill.badge.checkmark") + .foregroundColor(.secondary) + .opacity(0.5) + .help("Pinned with Pinnable") + } + } + } .contextMenu { Group { diff --git a/Planet/versioning.xcconfig b/Planet/versioning.xcconfig index 69c13e98..e2e7ddd6 100644 --- a/Planet/versioning.xcconfig +++ b/Planet/versioning.xcconfig @@ -1 +1 @@ -CURRENT_PROJECT_VERSION = 1531 +CURRENT_PROJECT_VERSION = 1532