Skip to content

Commit 3ec6f3e

Browse files
committed
Format
1 parent 2a4ce7c commit 3ec6f3e

22 files changed

+113
-132
lines changed

TestApp/Sources/AppDelegate.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import Combine
88
import UIKit
99

10-
//@UIApplicationMain
10+
// @UIApplicationMain
1111
class AppDelegate: UIResponder, UIApplicationDelegate {
1212
var window: UIWindow?
1313

TestApp/Sources/Bookshelf/Views/AddBookSheet.swift

+5-6
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77
import SwiftUI
88

99
struct AddBookSheet: View {
10-
1110
// For iOS 15, we can use @Environment(\.dismiss)
1211
@Binding var showingSheet: Bool
1312
var action: (String) -> Void
14-
13+
1514
@State var url: String = ""
16-
15+
1716
var body: some View {
1817
NavigationView {
1918
Form {
@@ -25,7 +24,7 @@ struct AddBookSheet: View {
2524
.toolbar(content: toolbarContent)
2625
}
2726
}
28-
27+
2928
@ToolbarContentBuilder
3029
private func toolbarContent() -> some ToolbarContent {
3130
ToolbarItem(placement: .navigationBarLeading) {
@@ -43,8 +42,8 @@ struct AddBookSheet: View {
4342
}
4443
}
4544

46-
//struct AddBookSheet_Previews: PreviewProvider {
45+
// struct AddBookSheet_Previews: PreviewProvider {
4746
// static var previews: some View {
4847
// AddBookSheet(showingSheet: true)
4948
// }
50-
//}
49+
// }

TestApp/Sources/Bookshelf/Views/Bookshelf.swift

+6-9
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,37 @@
77
import SwiftUI
88

99
struct Bookshelf: View {
10-
1110
let bookRepository: BookRepository
12-
11+
1312
@State private var showingSheet = false
1413
@State private var books: [Book] = []
15-
14+
1615
var body: some View {
1716
NavigationView {
1817
VStack {
19-
// TODO figure out what the best column layout is for phones and tablets
18+
// TODO: figure out what the best column layout is for phones and tablets
2019
let columns: [GridItem] = [GridItem(.adaptive(minimum: 150 + 8))]
2120
ScrollView {
2221
LazyVGrid(columns: columns, spacing: 20) {
2322
ForEach(books, id: \.self) { book in
2423
BookCover(title: book.title, authors: book.authors, url: book.cover)
2524
}
2625
}
27-
//TODO handle error
26+
// TODO: handle error
2827
.onReceive(bookRepository.all()
2928
.replaceError(with: [])
3029
) { books in
3130
self.books = books
3231
}
3332
}
34-
3533
}
3634
.navigationTitle("Bookshelf")
3735
.toolbar(content: toolbarContent)
3836
}
3937
.navigationViewStyle(.stack)
4038
.sheet(isPresented: $showingSheet) {
41-
AddBookSheet(showingSheet: $showingSheet) { url in
42-
// TODO validate the URL and import the book
39+
AddBookSheet(showingSheet: $showingSheet) { _ in
40+
// TODO: validate the URL and import the book
4341
}
4442
}
4543
}
@@ -55,4 +53,3 @@ extension Bookshelf {
5553
}
5654
}
5755
}
58-

TestApp/Sources/Catalogs/Views/AddFeedSheet.swift

+6-7
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@
77
import SwiftUI
88

99
struct AddFeedSheet: View {
10-
1110
typealias ActionCallback = ((title: String, url: String)) -> Void
12-
11+
1312
// For iOS 15, we can use @Environment(\.dismiss)
1413
@Binding var showingSheet: Bool
1514
var action: ActionCallback
16-
15+
1716
@State var title: String = ""
1817
@State var url: String = ""
19-
18+
2019
var body: some View {
2120
NavigationView {
2221
Form {
@@ -31,7 +30,7 @@ struct AddFeedSheet: View {
3130
.toolbar(content: toolbarContent)
3231
}
3332
}
34-
33+
3534
@ToolbarContentBuilder
3635
private func toolbarContent() -> some ToolbarContent {
3736
ToolbarItem(placement: .navigationBarLeading) {
@@ -49,8 +48,8 @@ struct AddFeedSheet: View {
4948
}
5049
}
5150

52-
//struct AddFeedSheet_Previews: PreviewProvider {
51+
// struct AddFeedSheet_Previews: PreviewProvider {
5352
// static var previews: some View {
5453
// AddFeedSheet()
5554
// }
56-
//}
55+
// }

TestApp/Sources/Catalogs/Views/CatalogFeed.swift

+12-16
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,18 @@
44
// available in the top-level LICENSE file of the project.
55
//
66

7-
import SwiftUI
87
import R2Shared
98
import ReadiumOPDS
9+
import SwiftUI
1010

1111
struct CatalogFeed: View {
12-
1312
var catalog: Catalog
1413
@State private var parseData: ParseData?
15-
14+
1615
let catalogFeed: (Catalog) -> CatalogFeed
1716
let publicationDetail: (Publication) -> PublicationDetail
18-
17+
1918
var body: some View {
20-
2119
ScrollView {
2220
VStack(alignment: .leading) {
2321
if let feed = parseData?.feed {
@@ -30,14 +28,14 @@ struct CatalogFeed: View {
3028
}
3129
Divider().frame(height: 50)
3230
}
33-
34-
// TODO This probably needs its own file
31+
32+
// TODO: This probably needs its own file
3533
if !feed.publications.isEmpty {
3634
let columns: [GridItem] = [GridItem(.adaptive(minimum: 150 + 8))]
3735
LazyVGrid(columns: columns) {
3836
ForEach(feed.publications) { publication in
3937
let authors = publication.metadata.authors
40-
.map { $0.name }
38+
.map(\.name)
4139
.joined(separator: ", ")
4240
NavigationLink(destination: publicationDetail(publication)) {
4341
BookCover(
@@ -52,7 +50,7 @@ struct CatalogFeed: View {
5250
}
5351
Divider().frame(height: 50)
5452
}
55-
53+
5654
if !feed.groups.isEmpty {
5755
ForEach(feed.groups as [R2Shared.Group]) { group in
5856
CatalogGroup(group: group, publicationDetail: publicationDetail, catalogFeed: catalogFeed)
@@ -74,31 +72,29 @@ struct CatalogFeed: View {
7472
}
7573

7674
extension CatalogFeed {
77-
7875
func parseFeed() async {
7976
if let url = URL(string: catalog.url) {
80-
OPDSParser.parseURL(url: url) { data, error in
77+
OPDSParser.parseURL(url: url) { data, _ in
8178
self.parseData = data
8279
}
8380
}
8481
}
8582
}
8683

87-
// FIXME this causes a Swift compiler error segmentation fault 11
84+
// FIXME: this causes a Swift compiler error segmentation fault 11
8885

89-
//struct CatalogDetail_Previews: PreviewProvider {
86+
// struct CatalogDetail_Previews: PreviewProvider {
9087
// static var previews: some View {
9188
// let catalog = Catalog(title: "Test", url: "https://www.test.com")
9289
// let catalogDetail: (Catalog) -> CatalogDetail = { CatalogDetail(CatalogDetailViewModel(catalog: catalog)) }
9390
// CatalogDetail(viewModel: CatalogDetailViewModel(catalog: catalog), catalogDetail: catalogDetail)
9491
// }
95-
//}
92+
// }
9693

9794
struct CatalogDetail_Previews: PreviewProvider {
9895
static var previews: some View {
9996
let catalog = Catalog(title: "Test", url: "https://www.test.com")
10097
CatalogFeed(catalog: catalog, catalogFeed: { _ in fatalError() },
101-
publicationDetail: { _ in fatalError() }
102-
)
98+
publicationDetail: { _ in fatalError() })
10399
}
104100
}

TestApp/Sources/Catalogs/Views/CatalogGroup.swift

+6-7
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
// available in the top-level LICENSE file of the project.
55
//
66

7-
import SwiftUI
87
import R2Shared
8+
import SwiftUI
99

1010
struct CatalogGroup: View {
11-
1211
var group: R2Shared.Group
1312
let publicationDetail: (Publication) -> PublicationDetail
1413
let catalogFeed: (Catalog) -> CatalogFeed
15-
14+
1615
var body: some View {
1716
VStack(alignment: .leading) {
1817
let rows = [GridItem(.flexible(), alignment: .top)]
@@ -30,10 +29,10 @@ struct CatalogGroup: View {
3029
LazyHGrid(rows: rows, spacing: 30) {
3130
ForEach(group.publications) { publication in
3231
let authors = publication.metadata.authors
33-
.map { $0.name }
32+
.map(\.name)
3433
.joined(separator: ", ")
3534
NavigationLink(destination: publicationDetail(publication)) {
36-
// FIXME Ideally the title and author should not be truncated
35+
// FIXME: Ideally the title and author should not be truncated
3736
BookCover(
3837
title: publication.metadata.title,
3938
authors: authors,
@@ -56,8 +55,8 @@ struct CatalogGroup: View {
5655
}
5756
}
5857

59-
//struct CatalogGroup_Previews: PreviewProvider {
58+
// struct CatalogGroup_Previews: PreviewProvider {
6059
// static var previews: some View {
6160
// CatalogGroup()
6261
// }
63-
//}
62+
// }

TestApp/Sources/Catalogs/Views/CatalogList.swift

+14-17
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,21 @@
44
// available in the top-level LICENSE file of the project.
55
//
66

7-
import SwiftUI
87
import ReadiumOPDS
8+
import SwiftUI
99

1010
struct CatalogList: View {
11-
1211
let catalogRepository: CatalogRepository
1312
let catalogFeed: (Catalog) -> CatalogFeed
14-
13+
1514
@State private var showingSheet = false
1615
@State private var showingAlert = false
1716
@State private var catalogs: [Catalog] = []
18-
17+
1918
var body: some View {
2019
NavigationView {
2120
VStack {
22-
List() {
21+
List {
2322
ForEach(catalogs, id: \.id) { catalog in
2423
NavigationLink(destination: catalogFeed(catalog)) {
2524
ListRowItem(title: catalog.title)
@@ -33,15 +32,15 @@ struct CatalogList: View {
3332
}
3433
}
3534
.onReceive(catalogRepository.all()
36-
.replaceError(with: nil)) { catalogsOrNil in
37-
if let catalogs = catalogsOrNil {
38-
self.catalogs = catalogs
39-
} else {
40-
print("Error fetching catalogs")
41-
}
35+
.replaceError(with: nil))
36+
{ catalogsOrNil in
37+
if let catalogs = catalogsOrNil {
38+
self.catalogs = catalogs
39+
} else {
40+
print("Error fetching catalogs")
41+
}
4242
}
4343
.listStyle(DefaultListStyle())
44-
4544
}
4645
.navigationTitle("Catalogs")
4746
.toolbar(content: toolbarContent)
@@ -51,8 +50,7 @@ struct CatalogList: View {
5150
AddFeedSheet(showingSheet: $showingSheet) { title, url in
5251
Task {
5352
do {
54-
OPDSParser.parseURL(url: URL(string: url)!) { data, error in
55-
53+
OPDSParser.parseURL(url: URL(string: url)!) { _, _ in
5654
}
5755
try await addCatalog(catalog: Catalog(title: title, url: url))
5856
} catch {
@@ -67,7 +65,7 @@ struct CatalogList: View {
6765
Text("Feed is not valid, please try again.")
6866
})
6967
}
70-
68+
7169
@ToolbarContentBuilder
7270
private func toolbarContent() -> some ToolbarContent {
7371
ToolbarItem(placement: .navigationBarTrailing) {
@@ -79,12 +77,11 @@ struct CatalogList: View {
7977
}
8078

8179
extension CatalogList {
82-
8380
func addCatalog(catalog: Catalog) async throws {
8481
var savedCatalog = catalog
8582
try? await catalogRepository.save(&savedCatalog)
8683
}
87-
84+
8885
func deleteCatalogs(ids: [Catalog.Id]) async throws {
8986
try? await catalogRepository.delete(ids: ids)
9087
}

TestApp/Sources/Catalogs/Views/PublicationDetail.swift

+7-8
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@
44
// available in the top-level LICENSE file of the project.
55
//
66

7-
import SwiftUI
87
import R2Shared
8+
import SwiftUI
99

1010
struct PublicationDetail: View {
11-
1211
@State var publication: Publication
13-
12+
1413
var body: some View {
1514
let authors = publication.metadata.authors
16-
.map { $0.name }
15+
.map(\.name)
1716
.joined(separator: ", ")
1817
ScrollView {
1918
VStack {
@@ -36,19 +35,19 @@ struct PublicationDetail: View {
3635
.padding()
3736
.toolbar(content: toolbarContent)
3837
}
39-
38+
4039
@ToolbarContentBuilder
4140
private func toolbarContent() -> some ToolbarContent {
4241
ToolbarItem(placement: .navigationBarTrailing) {
4342
Button(.download) {
44-
// TODO download the publication
43+
// TODO: download the publication
4544
}
4645
}
4746
}
4847
}
4948

50-
//struct PublicationDetail_Previews: PreviewProvider {
49+
// struct PublicationDetail_Previews: PreviewProvider {
5150
// static var previews: some View {
5251
// PublicationDetail()
5352
// }
54-
//}
53+
// }

TestApp/Sources/Common/Toolkit/Extensions/R2Shared.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
import R2Shared
88

99
extension R2Shared.Publication: Identifiable {}
10-
extension R2Shared.Group : Identifiable {}
10+
extension R2Shared.Group: Identifiable {}

0 commit comments

Comments
 (0)