From 4542a945a7783a6bdc056efa8a69937892130984 Mon Sep 17 00:00:00 2001 From: Daniel Bady Date: Sat, 25 May 2024 00:10:31 +0200 Subject: [PATCH] feat: added copy to clipboard, fixed pages not showing sometines --- .../PlaylistDetailsFeature.swift | 7 +- .../Features/Settings/Components/Logs.swift | 79 +++++++++++++------ .../Platforms/SettingsFeature+iOS.swift | 4 +- 3 files changed, 60 insertions(+), 30 deletions(-) diff --git a/Sources/Features/PlaylistDetails/PlaylistDetailsFeature.swift b/Sources/Features/PlaylistDetails/PlaylistDetailsFeature.swift index e88d29f..5cb49dc 100644 --- a/Sources/Features/PlaylistDetails/PlaylistDetailsFeature.swift +++ b/Sources/Features/PlaylistDetails/PlaylistDetailsFeature.swift @@ -77,7 +77,12 @@ public struct PlaylistDetailsFeature: Feature { if let group = content.groups.value?.first(where: { $0.default ?? false }) ?? content.groups.value?.first, let variant = group.variants.value?.first { if let epId = playlistHistory.value?.epId { - if let page = variant.pagings.value?.first(where: { ($0.items.value ?? []).contains(where: { $0.id.rawValue == epId }) }), + if let page = variant.pagings.value?.first(where: { + if let output = $0.items.value { + return output.contains(where: { $0.id.rawValue == epId }) + } + return true + }), let item = page.items.value?.first(where: { $0.id.rawValue == epId }) { return .resume(group.id, variant.id, page.id, item.id, item.title ?? "", playlistHistory.value?.timestamp ?? 0.0) } diff --git a/Sources/Features/Settings/Components/Logs.swift b/Sources/Features/Settings/Components/Logs.swift index aaed777..15464d5 100644 --- a/Sources/Features/Settings/Components/Logs.swift +++ b/Sources/Features/Settings/Components/Logs.swift @@ -155,6 +155,8 @@ extension Logs { public let store: StoreOf @Dependency(\.dateFormatter) var dateFormatter + + @SwiftUI.State var showCopyAlert = false @MainActor public init(store: StoreOf) { @@ -162,38 +164,52 @@ extension Logs { } @MainActor public var body: some SwiftUI.View { - ScrollView(.vertical) { - LazyVStack(spacing: 12) { - WithViewStore(store, observe: \.selected) { viewStore in - if viewStore.logsEmpty { - Text("No logs available.") - } else { - _VariadicView.Tree(Layout()) { - switch viewStore.state { - case let .system(events): - ForEach(events, id: \.timestamp) { event in - eventRow( - level: event.level.rawValue, - levelColor: event.level.color, - timeStamp: event.timestamp, - message: event.message - ) - } - case let .module(_, _, events): - ForEach(events, id: \.timestamp) { event in - eventRow( - level: event.level.rawValue, - levelColor: event.level.color, - timeStamp: event.timestamp, - message: event.body - ) + ZStack(alignment: .bottom) { + ScrollView(.vertical) { + LazyVStack(spacing: 12) { + WithViewStore(store, observe: \.selected) { viewStore in + if viewStore.logsEmpty { + Text("No logs available.") + } else { + _VariadicView.Tree(Layout()) { + switch viewStore.state { + case let .system(events): + ForEach(events, id: \.timestamp) { event in + eventRow( + level: event.level.rawValue, + levelColor: event.level.color, + timeStamp: event.timestamp, + message: event.message + ) + } + case let .module(_, _, events): + ForEach(events, id: \.timestamp) { event in + eventRow( + level: event.level.rawValue, + levelColor: event.level.color, + timeStamp: event.timestamp, + message: event.body + ) + } } } } } } + .padding() + } + if showCopyAlert { + VStack { + Text("Copied to clipboard!") + } + .transition(.opacity) + .padding() + .background(Theme.pastelOrange) + .foregroundColor(.white) + .clipShape(RoundedCorners(12)) + .shadow(radius: 10) + .offset(y: -20) } - .padding() } .moduleListsSheet( store.scope( @@ -300,6 +316,17 @@ extension Logs { Text(message) .font(.footnote) .frame(maxWidth: .infinity, alignment: .leading) + .onLongPressGesture { + UIPasteboard.general.setValue(message, forPasteboardType: "public.plain-text") + withAnimation { + showCopyAlert = true + } + DispatchQueue.main.asyncAfter(deadline: .now() + 2) { + withAnimation { + self.showCopyAlert = false + } + } + } } .frame(maxWidth: .infinity) } diff --git a/Sources/Features/Settings/Platforms/SettingsFeature+iOS.swift b/Sources/Features/Settings/Platforms/SettingsFeature+iOS.swift index e7568cd..95fabbc 100644 --- a/Sources/Features/Settings/Platforms/SettingsFeature+iOS.swift +++ b/Sources/Features/Settings/Platforms/SettingsFeature+iOS.swift @@ -44,9 +44,7 @@ private struct VersionView: View { Text( """ Design and developed by \ - [@MochiTeam](https://MochiTeam.dev) \ - & \ - [contributors](https://github.com/Mochi-Team/mochi/contributors) + [the community](https://mochisite.vercel.app) """ ) .multilineTextAlignment(.center)