From 32b4bd17e0d99c46725effced0bb63059fed0f35 Mon Sep 17 00:00:00 2001 From: Livid Date: Tue, 9 Jul 2024 04:33:07 -0700 Subject: [PATCH] Fix and improve tags view --- Planet/Entities/DraftModel.swift | 9 ++++++ Planet/Entities/MyPlanetModel.swift | 19 +++++++++++ Planet/Labs/Wallet/WalletManager.swift | 1 - Planet/Quick Share/PlanetQuickShareView.swift | 32 +++++++++++++++++++ .../PlanetQuickShareViewModel.swift | 7 ++++ Planet/Views/My/MyArticleSettingsView.swift | 23 +++++++++++++ Planet/Writer/WriterTitleView.swift | 32 ++++++++++++++++++- Planet/Writer/WriterView.swift | 1 + Planet/versioning.xcconfig | 2 +- Technotes/WalletConnectV2.md | 3 +- 10 files changed, 125 insertions(+), 4 deletions(-) diff --git a/Planet/Entities/DraftModel.swift b/Planet/Entities/DraftModel.swift index 9a785657..27e57dd5 100644 --- a/Planet/Entities/DraftModel.swift +++ b/Planet/Entities/DraftModel.swift @@ -49,6 +49,15 @@ class DraftModel: Identifiable, Equatable, Hashable, Codable, ObservableObject { } }() + lazy var planet: MyPlanetModel = { + switch target! { + case .myPlanet(let wrapper): + return wrapper.value + case .article(let wrapper): + return wrapper.value.planet + } + }() + lazy var basePath: URL = { switch target! { case .article(let wrapper): diff --git a/Planet/Entities/MyPlanetModel.swift b/Planet/Entities/MyPlanetModel.swift index 25553c65..1400437c 100644 --- a/Planet/Entities/MyPlanetModel.swift +++ b/Planet/Entities/MyPlanetModel.swift @@ -1990,6 +1990,25 @@ class MyPlanetModel: Equatable, Hashable, Identifiable, ObservableObject, Codabl } } + /// Return all available tags and their counts + func getAllAvailableTags() -> [String : Int] { + var tags: [String : Int] = [:] + for article in articles { + if let articleTags = article.tags { + for (key, value) in articleTags { + if MyPlanetModel.isReservedTag(key) { + continue + } + if tags[value] == nil { + tags[value] = 0 + } + tags[value]! += 1 + } + } + } + return tags + } + func rebuild() async throws { let started = Date() await MainActor.run { diff --git a/Planet/Labs/Wallet/WalletManager.swift b/Planet/Labs/Wallet/WalletManager.swift index cde2246d..e228cf64 100644 --- a/Planet/Labs/Wallet/WalletManager.swift +++ b/Planet/Labs/Wallet/WalletManager.swift @@ -10,7 +10,6 @@ import Combine import CoreImage.CIFilterBuiltins import CryptoSwift import Foundation -import HDWalletKit import Starscream import WalletConnectNetworking import WalletConnectPairing diff --git a/Planet/Quick Share/PlanetQuickShareView.swift b/Planet/Quick Share/PlanetQuickShareView.swift index 2b92f38c..4a44fde7 100644 --- a/Planet/Quick Share/PlanetQuickShareView.swift +++ b/Planet/Quick Share/PlanetQuickShareView.swift @@ -42,6 +42,9 @@ struct PlanetQuickShareView: View { .padding(.horizontal, 16) .frame(height: 42) } + .task { + viewModel.loadAvailableTags() + } } // TODO: move this func to MyPlanetModel @@ -412,6 +415,35 @@ struct PlanetQuickShareView: View { } } .padding(10) + + if viewModel.availableTags.count > 0 { + Divider() + + VStack(spacing: 10) { + HStack { + Text("Previously Used Tags") + .font(.system(size: 11, weight: .regular, design: .default)) + .foregroundColor(.secondary) + } + + // Tag capsules + WrappingHStack( + viewModel.availableTags.keys.sorted(), + id: \.self, + alignment: .leading, + spacing: .constant(2), + lineSpacing: 4 + ) { tag in + TagCountView(tag: tag, count: viewModel.availableTags[tag] ?? 0) + .onTapGesture { + let normalizedTag = tag.normalizedTag() + viewModel.tags[normalizedTag] = tag + } + } + } + .padding(10) + .background(Color(NSColor.textBackgroundColor)) + } } .frame(width: 280) } diff --git a/Planet/Quick Share/PlanetQuickShareViewModel.swift b/Planet/Quick Share/PlanetQuickShareViewModel.swift index 5fcfe683..5aa44e2c 100644 --- a/Planet/Quick Share/PlanetQuickShareViewModel.swift +++ b/Planet/Quick Share/PlanetQuickShareViewModel.swift @@ -27,6 +27,7 @@ class PlanetQuickShareViewModel: ObservableObject { @Published var title: String = "" @Published var content: String = "" @Published var tags: [String: String] = [:] + @Published var availableTags: [String: Int] = [:] @Published var newTag: String = "" @Published var externalLink: String = "" @Published var fileURLs: [URL] = [] @@ -46,6 +47,12 @@ class PlanetQuickShareViewModel: ObservableObject { return myPlanets.filter({ $0.id == selectedPlanetID }).first } + func loadAvailableTags() { + if let targetPlanet = getTargetPlanet() { + availableTags = targetPlanet.getAllAvailableTags() + } + } + @MainActor func prepareFiles(_ files: [URL]) throws { cleanup() diff --git a/Planet/Views/My/MyArticleSettingsView.swift b/Planet/Views/My/MyArticleSettingsView.swift index 272d8185..7c4cdfe6 100644 --- a/Planet/Views/My/MyArticleSettingsView.swift +++ b/Planet/Views/My/MyArticleSettingsView.swift @@ -424,6 +424,29 @@ struct TagView: View { } } +struct TagCountView: View { + let tag: String + let count: Int + + var body: some View { + HStack { + Text(tag) + .font(.footnote) + .foregroundColor(.secondary) + Text("\(count)") + .font(.footnote) + .foregroundColor(.secondary) + .background(Circle().fill(Color("BorderColor")).frame(width: 12, height: 12)) + } + .padding(.top, 4) + .padding(.bottom, 4) + .padding(.leading, 8) + .padding(.trailing, 8) + .background(Color("BorderColor")) + .cornerRadius(8) + } +} + struct MyArticleSettingsView_Previews: PreviewProvider { static var previews: some View { MyArticleSettingsView(article: MyArticleModel.placeholder) diff --git a/Planet/Writer/WriterTitleView.swift b/Planet/Writer/WriterTitleView.swift index 38b0f9cc..bf5f93bd 100644 --- a/Planet/Writer/WriterTitleView.swift +++ b/Planet/Writer/WriterTitleView.swift @@ -15,6 +15,7 @@ struct WriterTitleView: View { @State private var initDate: Date = Date() @State private var newTag: String = "" + var availableTags: [String: Int] = [:] @Binding var tags: [String: String] @Binding var date: Date @Binding var title: String @@ -202,6 +203,35 @@ struct WriterTitleView: View { } } .padding(10) + + if availableTags.count > 0 { + Divider() + + VStack(spacing: 10) { + HStack { + Text("Previously Used Tags") + .font(.system(size: 11, weight: .regular, design: .default)) + .foregroundColor(.secondary) + } + + // Tag capsules + WrappingHStack( + availableTags.keys.sorted(), + id: \.self, + alignment: .leading, + spacing: .constant(2), + lineSpacing: 4 + ) { tag in + TagCountView(tag: tag, count: availableTags[tag] ?? 0) + .onTapGesture { + let normalizedTag = tag.normalizedTag() + tags[normalizedTag] = tag + } + } + } + .padding(10) + .background(Color(NSColor.textBackgroundColor)) + } } .frame(width: 280) } @@ -209,6 +239,6 @@ struct WriterTitleView: View { struct WriterTitleView_Previews: PreviewProvider { static var previews: some View { - WriterTitleView(tags: .constant([:]), date: .constant(Date()), title: .constant("")) + WriterTitleView(availableTags: [:], tags: .constant([:]), date: .constant(Date()), title: .constant("")) } } diff --git a/Planet/Writer/WriterView.swift b/Planet/Writer/WriterView.swift index a88df200..b4beb3c6 100644 --- a/Planet/Writer/WriterView.swift +++ b/Planet/Writer/WriterView.swift @@ -39,6 +39,7 @@ struct WriterView: View { } WriterTitleView( + availableTags: draft.planet.getAllAvailableTags(), tags: $draft.tags, date: $draft.date, title: $draft.title, diff --git a/Planet/versioning.xcconfig b/Planet/versioning.xcconfig index 8cfa3b1f..f2887971 100644 --- a/Planet/versioning.xcconfig +++ b/Planet/versioning.xcconfig @@ -1 +1 @@ -CURRENT_PROJECT_VERSION = 2120 +CURRENT_PROJECT_VERSION = 2121 diff --git a/Technotes/WalletConnectV2.md b/Technotes/WalletConnectV2.md index 64fded62..f34c520b 100644 --- a/Technotes/WalletConnectV2.md +++ b/Technotes/WalletConnectV2.md @@ -4,10 +4,11 @@ Notes about our integration with WalletConnectV2. ## Wallet Apps Tested -- [x] OKX: Supports WC2, can test on Sepolia. +- [x] OKX: Supports WC2, **can test on Sepolia**. - [x] Rainbow: Supports WC2 with Auth, but unable to test on Sepolia. - [x] MetaMask: Supports WC2, but not Auth, unable to test on Sepolia. - [x] OneKey: Supports WC2, but unable to test on Sepolia. +- [x] Uniswap Wallet: Supports WC2, but unable to test on Sepolia. ## To-Do