Skip to content

Commit e6b7798

Browse files
authored
Rewrite OPDS catalogs to use SwiftUI (#671)
1 parent b224f4d commit e6b7798

21 files changed

+684
-1302
lines changed

TestApp/Sources/OPDS/OPDSCatalogs/OPDSCatalog.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import Foundation
88

9-
struct OPDSCatalog: Identifiable, Equatable {
9+
struct OPDSCatalog: Identifiable, Equatable, Hashable {
1010
let id: String
1111
var title: String
1212
var url: URL

TestApp/Sources/OPDS/OPDSCatalogs/OPDSCatalogRow.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ struct OPDSCatalogRow: View {
1414
Image(systemName: "books.vertical.fill")
1515
.foregroundColor(.accentColor)
1616
Text(title)
17-
18-
Spacer()
19-
20-
Image(systemName: "chevron.right")
21-
.foregroundColor(.gray)
2217
}
2318
}
2419
}

TestApp/Sources/OPDS/OPDSCatalogs/OPDSCatalogsView.swift

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,32 @@ import SwiftUI
99
struct OPDSCatalogsView: View {
1010
@State private var viewModel: OPDSCatalogsViewModel
1111

12-
init(viewModel: OPDSCatalogsViewModel) {
12+
private var delegate: OPDSModuleDelegate?
13+
14+
init(viewModel: OPDSCatalogsViewModel, delegate: OPDSModuleDelegate?) {
1315
self.viewModel = viewModel
16+
self.delegate = delegate
1417
}
1518

1619
var body: some View {
1720
List(viewModel.catalogs) { catalog in
18-
OPDSCatalogRow(title: catalog.title)
19-
.contentShape(Rectangle())
20-
.onTapGesture {
21-
viewModel.onCatalogTap(id: catalog.id)
21+
NavigationLink(value: catalog) {
22+
OPDSCatalogRow(title: catalog.title)
23+
}
24+
.contentShape(Rectangle())
25+
.swipeActions(allowsFullSwipe: false) {
26+
Button(role: .destructive) {
27+
viewModel.onDeleteCatalogTap(id: catalog.id)
28+
} label: {
29+
Label("Delete", systemImage: "trash")
2230
}
23-
.swipeActions(allowsFullSwipe: false) {
24-
Button(role: .destructive) {
25-
viewModel.onDeleteCatalogTap(id: catalog.id)
26-
} label: {
27-
Label("Delete", systemImage: "trash")
28-
}
2931

30-
Button {
31-
viewModel.onEditCatalogTap(id: catalog.id)
32-
} label: {
33-
Label("Edit", systemImage: "pencil")
34-
}
32+
Button {
33+
viewModel.onEditCatalogTap(id: catalog.id)
34+
} label: {
35+
Label("Edit", systemImage: "pencil")
3536
}
37+
}
3638
}
3739
.listStyle(.plain)
3840
.onAppear {
@@ -56,5 +58,7 @@ struct OPDSCatalogsView: View {
5658
}
5759

5860
#Preview {
59-
OPDSCatalogsView(viewModel: OPDSCatalogsViewModel())
61+
NavigationStack {
62+
OPDSCatalogsView(viewModel: OPDSCatalogsViewModel(), delegate: nil)
63+
}
6064
}

TestApp/Sources/OPDS/OPDSFacets/Feed+preview.swift

Lines changed: 0 additions & 222 deletions
This file was deleted.

TestApp/Sources/OPDS/OPDSFacets/OPDSFacetLink.swift

Lines changed: 0 additions & 39 deletions
This file was deleted.

TestApp/Sources/OPDS/OPDSFacets/OPDSFacetList.swift

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)