Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenzeck committed Jul 4, 2024
1 parent 310cbb2 commit da57a56
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 1 deletion.
1 change: 0 additions & 1 deletion TestApp/Sources/Bookshelf/Views/Bookshelf.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ struct Bookshelf: View {
.sheet(isPresented: $showingSheet) {
AddBookSheet { url in
// TODO: validate the URL and import the book
print(url)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions TestApp/Sources/Catalogs/Views/AddFeedSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import SwiftUI

/// Sheet to add a new OPDS catalog via a URL
struct AddFeedSheet: View {
typealias ActionCallback = ((title: String, url: String)) -> Void

Expand Down
2 changes: 2 additions & 0 deletions TestApp/Sources/Catalogs/Views/CatalogFeed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ReadiumOPDS
import ReadiumShared
import SwiftUI

/// Screen of an actual catalog feed, second to x number in the stack since it can keep going to another catalog
struct CatalogFeed: View {
var catalog: Catalog
@State private var parseData: ParseData?
Expand All @@ -19,6 +20,7 @@ struct CatalogFeed: View {
if !feed.navigation.isEmpty {
ForEach(feed.navigation, id: \.self) { link in
let navigationLink = Catalog(title: link.title ?? "Catalog", url: link.href)
/// We don't need to define the navigationDestination for this again because it will use the one in CatalogList
NavigationLink(value: navigationLink) {
ListRowItem(title: link.title!)
}
Expand Down
6 changes: 6 additions & 0 deletions TestApp/Sources/Catalogs/Views/CatalogList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ReadiumOPDS
import SwiftUI

/// Screen of list of catalog feeds, first in the stack
struct CatalogList: View {
let catalogRepository: CatalogRepository
let catalogFeed: (Catalog) -> CatalogFeed
Expand All @@ -21,6 +22,8 @@ struct CatalogList: View {
VStack {
List {
ForEach(catalogs, id: \.id) { catalog in
/// Use the `value` argument for navigationDestination to use.
/// In this case, it is a catalog of type `Catalog`. See below navigationDestination comment.
NavigationLink(value: catalog) {
ListRowItem(title: catalog.title)
}
Expand All @@ -44,6 +47,9 @@ struct CatalogList: View {
.listStyle(DefaultListStyle())
}
.navigationTitle("Catalogs")
/// We define the different destinations here, which are applicable to everywhere in the stack.
/// Use the `for` argument to pass the type of data. This should match what is being passed in NavigationLink.
/// In the first case below, it is of type `Catalog`, the same as NavigationLink above.
.navigationDestination(for: Catalog.self) { catalog in
catalogFeed(catalog)
}
Expand Down
1 change: 1 addition & 0 deletions TestApp/Sources/Catalogs/Views/PublicationDetail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ReadiumShared
import SwiftUI

/// Screen of the publication detail, last in the stack
struct PublicationDetail: View {
@State var opdsPublication: OPDSPublication

Expand Down
3 changes: 3 additions & 0 deletions TestApp/Sources/Data/Catalog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,21 @@ final class CatalogRepository {
self.db = db
}

/// Get all saved OPDS catalogs
func all() -> AnyPublisher<[Catalog]?, Error> {
db.observe {
try Catalog.order(Catalog.Columns.title).fetchAll($0)
}
}

/// Save an OPDS catalog
func save(_ catalog: inout Catalog) async throws {
catalog = try await db.write { [catalog] db in
try catalog.saved(db)
}
}

/// Delete an OPDS catalog
func delete(ids: [Catalog.Id]) async throws {
try await db.write { db in
try Catalog.deleteAll(db, ids: ids)
Expand Down
1 change: 1 addition & 0 deletions TestApp/Sources/TestApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import GRDB
import SwiftUI

// @main
/// The main function and serves as the app's entry
struct TestApp: App {
let container = try! Container()

Expand Down

0 comments on commit da57a56

Please sign in to comment.