Skip to content

Commit

Permalink
feat: Show private bookmarks in the sidebar (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbmorley authored Jul 29, 2021
1 parent 02ed4f5 commit 674fe73
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 11 deletions.
3 changes: 2 additions & 1 deletion core/BookmarksCore/Common/Updater.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public class Updater {
url: url,
tags: Set(post.tags),
date: date,
toRead: post.toRead)
toRead: post.toRead,
shared: post.shared)
identifiers.insert(item.identifier)
_ = try AsyncOperation({ self.database.insertOrUpdate(item, completion: $0) }).wait()
}
Expand Down
20 changes: 15 additions & 5 deletions core/BookmarksCore/Store/Database.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ extension Item {
url: try row.get(Database.Schema.url).asUrl(),
tags: [],
date: try row.get(Database.Schema.date),
toRead: try row.get(Database.Schema.toRead))
toRead: try row.get(Database.Schema.toRead),
shared: try row.get(Database.Schema.shared))
}

}
Expand Down Expand Up @@ -112,6 +113,7 @@ public class Database {
static let url = Expression<String>("url")
static let date = Expression<Date>("date")
static let toRead = Expression<Bool>("to_read")
static let shared = Expression<Bool>("shared")
static let name = Expression<String>("name")
static let itemId = Expression<Int64>("item_id")
static let tagId = Expression<Int64>("tag_id")
Expand Down Expand Up @@ -169,6 +171,10 @@ public class Database {
print("add the to_read column...")
try db.run(Schema.items.addColumn(Schema.toRead, defaultValue: false))
},
11: { db in
print("add the shared column...")
try db.run(Schema.items.addColumn(Schema.shared, defaultValue: false))
},
]

static var schemaVersion: Int32 = Array(migrations.keys).max() ?? 0
Expand Down Expand Up @@ -257,7 +263,8 @@ public class Database {
url: result.url,
tags: Set(tags),
date: result.date,
toRead: result.toRead)
toRead: result.toRead,
shared: result.shared)
}

fileprivate func syncQueue_fetchOrInsertTag(name: String) throws -> Int64 {
Expand Down Expand Up @@ -325,7 +332,8 @@ public class Database {
Schema.title <- item.title,
Schema.url <- item.url.absoluteString,
Schema.date <- item.date,
Schema.toRead <- item.toRead
Schema.toRead <- item.toRead,
Schema.shared <- item.shared
))
for tagId in tags {
_ = try self.db.run(
Expand Down Expand Up @@ -428,7 +436,8 @@ public class Database {
url,
tags,
date,
to_read
to_read,
shared
FROM
items
LEFT JOIN
Expand Down Expand Up @@ -459,7 +468,8 @@ public class Database {
url: try row.url(2),
tags: try row.set(3),
date: try row.date(4),
toRead: try row.bool(5))
toRead: try row.bool(5),
shared: try row.bool(6))
}

return items
Expand Down
14 changes: 13 additions & 1 deletion core/BookmarksCore/Store/Item.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,24 @@ public class Item: Equatable {
public let tags: Set<String>
public let date: Date
public let toRead: Bool
public let shared: Bool
public let thumbnail: SafeImage?

init(identifier: String, title: String, url: URL, tags: Set<String>, date: Date, toRead: Bool, thumbnail: SafeImage? = nil) {
init(identifier: String,
title: String,
url: URL,
tags: Set<String>,
date: Date,
toRead: Bool,
shared: Bool,
thumbnail: SafeImage? = nil) {
self.identifier = identifier
self.title = title
self.url = url
self.tags = Set(tags.map { $0.lowercased() })
self.date = date
self.toRead = toRead
self.shared = shared
self.thumbnail = thumbnail
}

Expand All @@ -63,6 +72,9 @@ public class Item: Equatable {
guard lhs.toRead == rhs.toRead else {
return false
}
guard lhs.shared == rhs.shared else {
return false
}
return true
}

Expand Down
9 changes: 9 additions & 0 deletions core/BookmarksCore/Store/QueryDescription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ public struct Unread: QueryDescription {

}

public struct Shared: QueryDescription {

public var sql: String { "items.shared = 1" }

public init() { }

}


public struct Tag: QueryDescription {

let name: String
Expand Down
12 changes: 10 additions & 2 deletions core/BookmarksCoreTests/DatabaseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,20 @@ import XCTest

extension Item {

convenience init(title: String, url: URL, tags: Set<String>, date: Date, toRead: Bool = false, thumbnail: SafeImage? = nil) {
convenience init(title: String,
url: URL,
tags: Set<String>,
date: Date,
toRead: Bool = false,
shared: Bool = false,
thumbnail: SafeImage? = nil) {
self.init(identifier: UUID().uuidString,
title: title,
url: url,
tags: tags,
date: date,
toRead: toRead,
shared: shared,
thumbnail: thumbnail)
}

Expand Down Expand Up @@ -308,7 +315,8 @@ class DatabaseTests: XCTestCase {
url: item.url,
tags: tags,
date: item.date,
toRead: item.toRead)
toRead: item.toRead,
shared: item.shared)
})
}

Expand Down
8 changes: 6 additions & 2 deletions macos/Bookmarks/BookmarksApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,18 @@ struct BookmarksApp: App {
selection = .today
}
.keyboardShortcut("2", modifiers: .command)
Button("Public") {
selection = .shared
}
.keyboardShortcut("3", modifiers: .command)
Button("Unread") {
selection = .unread
}
.keyboardShortcut("3", modifiers: .command)
.keyboardShortcut("4", modifiers: .command)
Button("Untagged") {
selection = .untagged
}
.keyboardShortcut("4", modifiers: .command)
.keyboardShortcut("5", modifiers: .command)
}
}
SwiftUI.Settings {
Expand Down
3 changes: 3 additions & 0 deletions macos/Bookmarks/BookmarksSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ enum BookmarksSection {
case untagged
case today
case unread
case shared
case favorite(tag: String)
case tag(tag: String)
}
Expand All @@ -43,6 +44,8 @@ extension BookmarksSection: CustomStringConvertible, Hashable, Identifiable {
return "uk.co.inseven.bookmarks.unread"
case .today:
return "uk.co.inseven.bookmarks.today"
case .shared:
return "uk.co.inseven.bookmarks.shared"
case .favorite(let tag):
return "uk.co.inseven.bookmarks.favorites.\(tag)"
case .tag(let tag):
Expand Down
7 changes: 7 additions & 0 deletions macos/Bookmarks/Views/Sidebar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ struct Sidebar: View {
systemImage: "sun.max.fill",
databaseView: ItemsView(database: manager.database, query: Today()))

SidebarLink(selection: $selection,
tag: .shared,
title: "Public",
systemImage: "globe",
databaseView: ItemsView(database: manager.database, query: Shared()))


SidebarLink(selection: $selection,
tag: .unread,
title: "Unread",
Expand Down

0 comments on commit 674fe73

Please sign in to comment.