Skip to content

Commit

Permalink
feat: More stable id & Less branch
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsuz0u committed Jun 10, 2021
1 parent 03913e2 commit e1d697f
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 64 deletions.
21 changes: 14 additions & 7 deletions EhPanda/Models/Manga.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ struct MangaDetail: Codable {

struct MangaArchive: Codable {
struct HathArchive: Codable, Identifiable {
var id = UUID()
var id: String { resolution.rawValue }

let resolution: ArchiveRes
let fileSize: String
Expand All @@ -129,14 +129,14 @@ struct MangaArchive: Codable {
}

struct MangaTag: Codable, Identifiable {
var id = UUID()
var id: String { category.rawValue }

let category: TagCategory
let content: [String]
}

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

var votedUp: Bool
var votedDown: Bool
Expand All @@ -151,7 +151,14 @@ struct MangaComment: Identifiable, Codable {
}

struct CommentContent: Identifiable, Codable {
var id = UUID()
var id: String {
[
"\(type.rawValue)",
text, link, imgURL,
secondLink, secondImgURL
]
.compactMap({$0}).joined()
}

let type: CommentContentType
var text: String?
Expand All @@ -163,13 +170,13 @@ struct CommentContent: Identifiable, Codable {
}

struct MangaPreview: Identifiable, Codable {
var id = UUID()
var id = UUID().uuidString

let url: String
}

struct MangaAlterData: Identifiable, Codable {
var id = UUID()
var id: Data { data }

let data: Data
}
Expand All @@ -185,7 +192,7 @@ struct MangaContent: Identifiable, Codable, Equatable {
}

struct MangaTorrent: Identifiable, Codable {
var id = UUID()
var id: String { uploader + formattedDateString }

let postedDate: Date
let fileSize: String
Expand Down
21 changes: 10 additions & 11 deletions EhPanda/View/Content/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,17 @@ struct ContentView: View, StoreAccessor {
.edgesIgnoringSafeArea(.horizontal)
}
}
Group {
if moreLoadingFlag {
LoadingView(isCompact: true)
} else if moreLoadFailedFlag {
NetworkErrorView(
isCompact: true,
retryAction: fetchMoreMangaContents
)
}
HStack(alignment: .center) {
Spacer()
ProgressView()
.opacity(moreLoadingFlag ? 1 : 0)
NetworkErrorCompactView(
retryAction: fetchMoreMangaContents
)
.opacity(moreLoadFailedFlag ? 1 : 0)
Spacer()
}
.padding()
.padding(.bottom, 24)
.frame(height: 30)
}
.onAppear {
onLazyVStackAppear(scrollProxy)
Expand Down
15 changes: 8 additions & 7 deletions EhPanda/View/Detail/AssociatedView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,17 @@ struct AssociatedView: View, StoreAccessor {
.opacity
.animation(.default)
)
if moreLoadingFlag {
LoadingView(isCompact: true)
.padding()
} else if moreLoadFailedFlag {
NetworkErrorView(
isCompact: true,
HStack(alignment: .center) {
Spacer()
ProgressView()
.opacity(moreLoadingFlag ? 1 : 0)
NetworkErrorCompactView(
retryAction: fetchMoreAssociatedItems
)
.padding()
.opacity(moreLoadFailedFlag ? 1 : 0)
Spacer()
}
.frame(height: 30)
} else if loadingFlag {
LoadingView()
.padding(.top, 30)
Expand Down
15 changes: 8 additions & 7 deletions EhPanda/View/Home/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -533,16 +533,17 @@ private struct GenericList: View, StoreAccessor {
.opacity
.animation(.default)
)
if moreLoadingFlag {
LoadingView(isCompact: true)
.padding()
} else if moreLoadFailedFlag {
NetworkErrorView(
isCompact: true,
HStack(alignment: .center) {
Spacer()
ProgressView()
.opacity(moreLoadingFlag ? 1 : 0)
NetworkErrorCompactView(
retryAction: loadMoreAction
)
.padding()
.opacity(moreLoadFailedFlag ? 1 : 0)
Spacer()
}
.frame(height: 30)
}
}
}
Expand Down
61 changes: 29 additions & 32 deletions EhPanda/View/Tools/AlertView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,8 @@
import SwiftUI

struct LoadingView: View {
private let isCompact: Bool

init(isCompact: Bool = false) {
self.isCompact = isCompact
}

var body: some View {
switch isCompact {
case true:
ProgressView()
case false:
ProgressView("Loading...")
}
ProgressView("Loading...")
}
}

Expand Down Expand Up @@ -58,34 +47,42 @@ struct NotFoundView: View {
}
}

struct NetworkErrorView: View {
private let isCompact: Bool
struct NetworkErrorCompactView: View {
private let retryAction: (() -> Void)?

init(
isCompact: Bool = false,
retryAction: (() -> Void)?
) {
self.isCompact = isCompact
init(retryAction: (() -> Void)?) {
self.retryAction = retryAction
}

var body: some View {
switch isCompact {
case true:
Button(action: onRetryButtonTap) {
Image(systemName: "exclamationmark.arrow.triangle.2.circlepath")
.imageScale(.large)
}
case false:
GenericRetryView(
symbolName: "wifi.exclamationmark",
message: "A Network error occurred.\nPlease try again later.",
buttonText: "Retry",
retryAction: onRetryButtonTap
)
Button(action: onRetryButtonTap) {
Image(systemName: "exclamationmark.arrow.triangle.2.circlepath")
.imageScale(.large)
}
}

private func onRetryButtonTap() {
if let action = retryAction {
action()
}
}
}

struct NetworkErrorView: View {
private let retryAction: (() -> Void)?

init(retryAction: (() -> Void)?) {
self.retryAction = retryAction
}

var body: some View {
GenericRetryView(
symbolName: "wifi.exclamationmark",
message: "A Network error occurred.\nPlease try again later.",
buttonText: "Retry",
retryAction: onRetryButtonTap
)
}

private func onRetryButtonTap() {
if let action = retryAction {
Expand Down

0 comments on commit e1d697f

Please sign in to comment.