diff --git a/EhPanda/Models/Manga.swift b/EhPanda/Models/Manga.swift index 40b629ae..4e5dd2ed 100644 --- a/EhPanda/Models/Manga.swift +++ b/EhPanda/Models/Manga.swift @@ -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 @@ -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 @@ -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? @@ -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 } @@ -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 diff --git a/EhPanda/View/Content/ContentView.swift b/EhPanda/View/Content/ContentView.swift index 81f76efe..8d415c68 100644 --- a/EhPanda/View/Content/ContentView.swift +++ b/EhPanda/View/Content/ContentView.swift @@ -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) diff --git a/EhPanda/View/Detail/AssociatedView.swift b/EhPanda/View/Detail/AssociatedView.swift index b591bfdc..240fae32 100644 --- a/EhPanda/View/Detail/AssociatedView.swift +++ b/EhPanda/View/Detail/AssociatedView.swift @@ -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) diff --git a/EhPanda/View/Home/HomeView.swift b/EhPanda/View/Home/HomeView.swift index 95ad9356..50517797 100644 --- a/EhPanda/View/Home/HomeView.swift +++ b/EhPanda/View/Home/HomeView.swift @@ -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) } } } diff --git a/EhPanda/View/Tools/AlertView.swift b/EhPanda/View/Tools/AlertView.swift index 86fb6b6c..9fbd354b 100644 --- a/EhPanda/View/Tools/AlertView.swift +++ b/EhPanda/View/Tools/AlertView.swift @@ -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...") } } @@ -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 {