Skip to content

Commit

Permalink
feat: Delete tags from the sidebar (#156)
Browse files Browse the repository at this point in the history
This change also includes a small drive-by fix to improve the layout of the context menus.
  • Loading branch information
jbmorley authored Jul 23, 2021
1 parent 5ebbd9f commit cc7266b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 30 deletions.
17 changes: 15 additions & 2 deletions core/BookmarksCore/Pinboard/Pinboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@ public class Pinboard {
}

fileprivate enum Path: String {

case posts_all = "posts/all"
case posts_delete = "posts/delete"

case tags_delete = "tags/delete"
case tags_rename = "tags/rename"

}

fileprivate let baseUrl = "https://api.pinboard.in/v1/"

let token: String
fileprivate let token: String

public init(token: String) {
self.token = token
Expand Down Expand Up @@ -103,6 +106,16 @@ public class Pinboard {
}
}

public func tags_delete(_ tag: String, completion: @escaping (Result<Bool, Swift.Error>) -> Void) {
let parameters = [
"tag": tag,
]
self.fetch(path: .tags_delete, parameters: parameters, completion: completion) { _ in
return true
}
}


public func tags_rename(_ old: String, to new: String, completion: @escaping (Result<Bool, Swift.Error>) -> Void) {
let parameters = [
"old": old,
Expand Down
43 changes: 21 additions & 22 deletions macos/Bookmarks/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,35 +59,14 @@ struct ContentView: View {
Button("Open") {
NSWorkspace.shared.open(item.url)
}
Divider()
if item.tags.isEmpty {
Button("No Tags") {}.disabled(true)
} else {
Menu("Tags") {
ForEach(Array(item.tags).sorted()) { tag in
Button(tag) {
print(item.tags)
}
}
}
}
Divider()
Button("View on Internet Archive") {
Button("Open on Internet Archive") {
do {
NSWorkspace.shared.open(try item.internetArchiveUrl())
} catch {
print("Failed to open on the Internet Archive with error \(error)")
}
}
Divider()
Button("Edit on Pinboard") {
do {
NSWorkspace.shared.open(try item.pinboardUrl())
} catch {
print("Failed to edit with error \(error)")
}
}
Divider()
Button("Copy") {
NSPasteboard.general.clearContents()
NSPasteboard.general.setString(item.url.absoluteString, forType: .string)
Expand All @@ -102,6 +81,26 @@ struct ContentView: View {
}
}
}
Divider()
if item.tags.isEmpty {
Button("No Tags") {}.disabled(true)
} else {
Menu("Tags") {
ForEach(Array(item.tags).sorted()) { tag in
Button(tag) {
print(item.tags)
}
}
}
}
Divider()
Button("Edit on Pinboard") {
do {
NSWorkspace.shared.open(try item.pinboardUrl())
} catch {
print("Failed to edit with error \(error)")
}
}
}))
.onDrag {
NSItemProvider(object: item.url as NSURL)
Expand Down
17 changes: 11 additions & 6 deletions macos/Bookmarks/Views/Sidebar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ struct Sidebar: View {
settings.favoriteTags = settings.favoriteTags.filter { $0 != tag }
}
Divider()
Button("View on Pinboard") {
Button("Edit on Pinboard") {
do {
guard let user = manager.user else {
return
Expand All @@ -112,17 +112,22 @@ struct Sidebar: View {
}
}
.contextMenu(ContextMenu(menuItems: {
Button("Rename") {
self.sheet = .rename(tag: tag)
}
Button("Delete") {
self.manager.pinboard.tags_delete(tag) { _ in
self.manager.updater.start()
}
}
Divider()
Button("Add to Favourites") {
var favoriteTags = settings.favoriteTags
favoriteTags.append(tag)
settings.favoriteTags = favoriteTags
}
Divider()
Button("Rename tag") {
self.sheet = .rename(tag: tag)
}
Divider()
Button("View on Pinboard") {
Button("Edit on Pinboard") {
do {
guard let user = manager.user else {
return
Expand Down

0 comments on commit cc7266b

Please sign in to comment.