Skip to content

Commit

Permalink
Fix and improve tags view
Browse files Browse the repository at this point in the history
  • Loading branch information
livid committed Jul 9, 2024
1 parent 9763880 commit 32b4bd1
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 4 deletions.
9 changes: 9 additions & 0 deletions Planet/Entities/DraftModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
19 changes: 19 additions & 0 deletions Planet/Entities/MyPlanetModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion Planet/Labs/Wallet/WalletManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import Combine
import CoreImage.CIFilterBuiltins
import CryptoSwift
import Foundation
import HDWalletKit
import Starscream
import WalletConnectNetworking
import WalletConnectPairing
Expand Down
32 changes: 32 additions & 0 deletions Planet/Quick Share/PlanetQuickShareView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ struct PlanetQuickShareView: View {
.padding(.horizontal, 16)
.frame(height: 42)
}
.task {
viewModel.loadAvailableTags()
}
}

// TODO: move this func to MyPlanetModel
Expand Down Expand Up @@ -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)
}
Expand Down
7 changes: 7 additions & 0 deletions Planet/Quick Share/PlanetQuickShareViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []
Expand All @@ -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()
Expand Down
23 changes: 23 additions & 0 deletions Planet/Views/My/MyArticleSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 31 additions & 1 deletion Planet/Writer/WriterTitleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -202,13 +203,42 @@ 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)
}
}

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(""))
}
}
1 change: 1 addition & 0 deletions Planet/Writer/WriterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct WriterView: View {
}

WriterTitleView(
availableTags: draft.planet.getAllAvailableTags(),
tags: $draft.tags,
date: $draft.date,
title: $draft.title,
Expand Down
2 changes: 1 addition & 1 deletion Planet/versioning.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CURRENT_PROJECT_VERSION = 2120
CURRENT_PROJECT_VERSION = 2121
3 changes: 2 additions & 1 deletion Technotes/WalletConnectV2.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 32b4bd1

Please sign in to comment.