Skip to content

Commit e1d697f

Browse files
author
たつぞう
committed
feat: More stable id & Less branch
1 parent 03913e2 commit e1d697f

File tree

5 files changed

+69
-64
lines changed

5 files changed

+69
-64
lines changed

EhPanda/Models/Manga.swift

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ struct MangaDetail: Codable {
118118

119119
struct MangaArchive: Codable {
120120
struct HathArchive: Codable, Identifiable {
121-
var id = UUID()
121+
var id: String { resolution.rawValue }
122122

123123
let resolution: ArchiveRes
124124
let fileSize: String
@@ -129,14 +129,14 @@ struct MangaArchive: Codable {
129129
}
130130

131131
struct MangaTag: Codable, Identifiable {
132-
var id = UUID()
132+
var id: String { category.rawValue }
133133

134134
let category: TagCategory
135135
let content: [String]
136136
}
137137

138138
struct MangaComment: Identifiable, Codable {
139-
var id = UUID()
139+
var id: String { author + formattedDateString }
140140

141141
var votedUp: Bool
142142
var votedDown: Bool
@@ -151,7 +151,14 @@ struct MangaComment: Identifiable, Codable {
151151
}
152152

153153
struct CommentContent: Identifiable, Codable {
154-
var id = UUID()
154+
var id: String {
155+
[
156+
"\(type.rawValue)",
157+
text, link, imgURL,
158+
secondLink, secondImgURL
159+
]
160+
.compactMap({$0}).joined()
161+
}
155162

156163
let type: CommentContentType
157164
var text: String?
@@ -163,13 +170,13 @@ struct CommentContent: Identifiable, Codable {
163170
}
164171

165172
struct MangaPreview: Identifiable, Codable {
166-
var id = UUID()
173+
var id = UUID().uuidString
167174

168175
let url: String
169176
}
170177

171178
struct MangaAlterData: Identifiable, Codable {
172-
var id = UUID()
179+
var id: Data { data }
173180

174181
let data: Data
175182
}
@@ -185,7 +192,7 @@ struct MangaContent: Identifiable, Codable, Equatable {
185192
}
186193

187194
struct MangaTorrent: Identifiable, Codable {
188-
var id = UUID()
195+
var id: String { uploader + formattedDateString }
189196

190197
let postedDate: Date
191198
let fileSize: String

EhPanda/View/Content/ContentView.swift

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,17 @@ struct ContentView: View, StoreAccessor {
8181
.edgesIgnoringSafeArea(.horizontal)
8282
}
8383
}
84-
Group {
85-
if moreLoadingFlag {
86-
LoadingView(isCompact: true)
87-
} else if moreLoadFailedFlag {
88-
NetworkErrorView(
89-
isCompact: true,
90-
retryAction: fetchMoreMangaContents
91-
)
92-
}
84+
HStack(alignment: .center) {
85+
Spacer()
86+
ProgressView()
87+
.opacity(moreLoadingFlag ? 1 : 0)
88+
NetworkErrorCompactView(
89+
retryAction: fetchMoreMangaContents
90+
)
91+
.opacity(moreLoadFailedFlag ? 1 : 0)
92+
Spacer()
9393
}
94-
.padding()
95-
.padding(.bottom, 24)
94+
.frame(height: 30)
9695
}
9796
.onAppear {
9897
onLazyVStackAppear(scrollProxy)

EhPanda/View/Detail/AssociatedView.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,17 @@ struct AssociatedView: View, StoreAccessor {
4040
.opacity
4141
.animation(.default)
4242
)
43-
if moreLoadingFlag {
44-
LoadingView(isCompact: true)
45-
.padding()
46-
} else if moreLoadFailedFlag {
47-
NetworkErrorView(
48-
isCompact: true,
43+
HStack(alignment: .center) {
44+
Spacer()
45+
ProgressView()
46+
.opacity(moreLoadingFlag ? 1 : 0)
47+
NetworkErrorCompactView(
4948
retryAction: fetchMoreAssociatedItems
5049
)
51-
.padding()
50+
.opacity(moreLoadFailedFlag ? 1 : 0)
51+
Spacer()
5252
}
53+
.frame(height: 30)
5354
} else if loadingFlag {
5455
LoadingView()
5556
.padding(.top, 30)

EhPanda/View/Home/HomeView.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -533,16 +533,17 @@ private struct GenericList: View, StoreAccessor {
533533
.opacity
534534
.animation(.default)
535535
)
536-
if moreLoadingFlag {
537-
LoadingView(isCompact: true)
538-
.padding()
539-
} else if moreLoadFailedFlag {
540-
NetworkErrorView(
541-
isCompact: true,
536+
HStack(alignment: .center) {
537+
Spacer()
538+
ProgressView()
539+
.opacity(moreLoadingFlag ? 1 : 0)
540+
NetworkErrorCompactView(
542541
retryAction: loadMoreAction
543542
)
544-
.padding()
543+
.opacity(moreLoadFailedFlag ? 1 : 0)
544+
Spacer()
545545
}
546+
.frame(height: 30)
546547
}
547548
}
548549
}

EhPanda/View/Tools/AlertView.swift

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,8 @@
88
import SwiftUI
99

1010
struct LoadingView: View {
11-
private let isCompact: Bool
12-
13-
init(isCompact: Bool = false) {
14-
self.isCompact = isCompact
15-
}
16-
1711
var body: some View {
18-
switch isCompact {
19-
case true:
20-
ProgressView()
21-
case false:
22-
ProgressView("Loading...")
23-
}
12+
ProgressView("Loading...")
2413
}
2514
}
2615

@@ -58,34 +47,42 @@ struct NotFoundView: View {
5847
}
5948
}
6049

61-
struct NetworkErrorView: View {
62-
private let isCompact: Bool
50+
struct NetworkErrorCompactView: View {
6351
private let retryAction: (() -> Void)?
6452

65-
init(
66-
isCompact: Bool = false,
67-
retryAction: (() -> Void)?
68-
) {
69-
self.isCompact = isCompact
53+
init(retryAction: (() -> Void)?) {
7054
self.retryAction = retryAction
7155
}
7256

7357
var body: some View {
74-
switch isCompact {
75-
case true:
76-
Button(action: onRetryButtonTap) {
77-
Image(systemName: "exclamationmark.arrow.triangle.2.circlepath")
78-
.imageScale(.large)
79-
}
80-
case false:
81-
GenericRetryView(
82-
symbolName: "wifi.exclamationmark",
83-
message: "A Network error occurred.\nPlease try again later.",
84-
buttonText: "Retry",
85-
retryAction: onRetryButtonTap
86-
)
58+
Button(action: onRetryButtonTap) {
59+
Image(systemName: "exclamationmark.arrow.triangle.2.circlepath")
60+
.imageScale(.large)
61+
}
62+
}
63+
64+
private func onRetryButtonTap() {
65+
if let action = retryAction {
66+
action()
8767
}
8868
}
69+
}
70+
71+
struct NetworkErrorView: View {
72+
private let retryAction: (() -> Void)?
73+
74+
init(retryAction: (() -> Void)?) {
75+
self.retryAction = retryAction
76+
}
77+
78+
var body: some View {
79+
GenericRetryView(
80+
symbolName: "wifi.exclamationmark",
81+
message: "A Network error occurred.\nPlease try again later.",
82+
buttonText: "Retry",
83+
retryAction: onRetryButtonTap
84+
)
85+
}
8986

9087
private func onRetryButtonTap() {
9188
if let action = retryAction {

0 commit comments

Comments
 (0)