Vervollständigt die Cardecky-Web-Parität für Deck- und Card-Workflows. γ-1+γ-2 (AI-Deck-Generierung) - 4-Modi-Picker im DeckEditorView Create-Sheet: Leer/KI/Bild/CSV - POST /api/v1/decks/generate für Text-Prompt + 10/min Rate-Limit-UI - POST /api/v1/decks/from-image mit PhotosPicker + PDF-Importer (max 5 Files, 10 MiB/Bild, 30 MiB/PDF), Multipart-Body in CardsAPI+Generation - Loading-Overlay mit Task-Cancellation, Error-Mapping für 429/413/502 γ-3 (Card-Edit) - CardEditorView mit Mode .create(deckId:) / .edit(card:) - Image-Occlusion + Audio-Front behalten bestehenden Media-Ref, solange User nicht ersetzt — MediaCache lädt Bild nach - Type-Picker im Edit-Modus aus (Server-immutable) - CardEditorPayload + CardEditorMediaFields als Sub-Views γ-4 (Pull-Update + Duplicate + Archive) - POST /marketplace/private/:id/pull-update mit Smart-Merge-Anzeige - POST /decks/:id/duplicate - Archive-Toggle im Edit-Modus, Server filtert Liste serverseitig - DeckSecondaryActions als eigenes Sub-View γ-6 (CSV-Import) - RFC-4180-ish Parser (Quote-Escape, Header-Detect, BOM-strip) - Preview-Liste + sequentielle Card-Inserts mit Live-Progress - Image-Occlusion/Audio-Front werden geskipped (UI flaggt) γ-7 (Marketplace-Publish) + Follow-up (Report + Block + Re-Publish) - MarketplacePublishView mit lazy Author-Setup + Init + Publish 1.0.0 - Re-Publish-Modus: Picker für eigene Marketplace-Decks + Auto-Semver-Bump (Minor +1) - MarketplaceCardConverter (typing → type-in, audio-front → skipped, image-occlusion → skipped — Server hat keinen MP-Media-Re-Upload) - Toolbar-Menü auf PublicDeckView: „Deck melden …" + Author-Blockieren (App-Store-Guideline 5.1.1(v)) - ReportDeckSheet mit Reason-Picker (6 Kategorien) + optional Message - BlockedAuthorsView in Settings mit Swipe-Entblocken γ-8 (PDF-Export) - DeckPrintView mit SFSafariViewController auf cardecky.mana.how/decks/:id/print — iOS Share-Sheet → PDF speichern Side-Fixes (mid-stream) - StudySessionView: Card-Aspect-Ratio springt nicht mehr beim Flip (Bottom-Bar in ZStack fixer Höhe) - RootView: Glass-Pille für „Neues Deck"-Accessory + .guest- und .twoFactorRequired-Cases nachgezogen - DeckListView: Account-Toolbar-Button entfernt (Account-Tab unten ist alleinige Anlaufstelle) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
284 lines
11 KiB
Swift
284 lines
11 KiB
Swift
import ManaAuthUI
|
|
import ManaCore
|
|
import SwiftData
|
|
import SwiftUI
|
|
|
|
// swiftlint:disable type_body_length
|
|
|
|
/// Detail-View für ein Public-Deck. Subscribe-Button löst Auto-Fork
|
|
/// serverseitig aus und navigiert anschließend zur eigenen Deck-Detail.
|
|
/// Toolbar-Menu („…") hostet Report + Block-Author (App-Review-Pflicht).
|
|
struct PublicDeckView: View {
|
|
let slug: String
|
|
|
|
@Environment(AuthClient.self) private var auth
|
|
@Environment(ManaAuthGate.self) private var authGate
|
|
@Environment(\.modelContext) private var context
|
|
@State private var detail: PublicDeckDetail?
|
|
@State private var isLoading = false
|
|
@State private var isSubscribing = false
|
|
@State private var errorMessage: String?
|
|
@State private var subscribed: SubscribeResponse?
|
|
|
|
// Moderation-State
|
|
@State private var showReportSheet = false
|
|
@State private var showBlockConfirm = false
|
|
@State private var moderationToast: String?
|
|
|
|
var body: some View {
|
|
ZStack {
|
|
CardsTheme.background.ignoresSafeArea()
|
|
content
|
|
}
|
|
.navigationTitle(detail?.deck.title ?? "Deck")
|
|
#if os(iOS)
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
#endif
|
|
.toolbar {
|
|
if detail != nil {
|
|
ToolbarItem(placement: .topBarTrailing) {
|
|
moderationMenu
|
|
}
|
|
}
|
|
}
|
|
.task(id: slug) {
|
|
await load()
|
|
}
|
|
.sheet(isPresented: $showReportSheet) {
|
|
NavigationStack {
|
|
ReportDeckSheet(slug: slug) { message in
|
|
moderationToast = message
|
|
}
|
|
}
|
|
}
|
|
.confirmationDialog(
|
|
"Author blockieren?",
|
|
isPresented: $showBlockConfirm,
|
|
titleVisibility: .visible,
|
|
presenting: detail?.owner
|
|
) { owner in
|
|
Button("\(owner.displayName) blockieren", role: .destructive) {
|
|
Task { await blockAuthor(slug: owner.slug, name: owner.displayName) }
|
|
}
|
|
Button("Abbrechen", role: .cancel) {}
|
|
} message: { _ in
|
|
Text("Decks dieses Authors erscheinen für dich nicht mehr im Marketplace.")
|
|
}
|
|
.overlay(alignment: .top) {
|
|
if let toast = moderationToast {
|
|
ToastBanner(text: toast)
|
|
.padding(.top, 8)
|
|
.task {
|
|
try? await Task.sleep(for: .seconds(3))
|
|
moderationToast = nil
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private var moderationMenu: some View {
|
|
Menu {
|
|
Button {
|
|
authGate.require(reason: "marketplace-report") {
|
|
showReportSheet = true
|
|
}
|
|
} label: {
|
|
Label("Deck melden …", systemImage: "flag")
|
|
}
|
|
if let owner = detail?.owner {
|
|
Button(role: .destructive) {
|
|
authGate.require(reason: "marketplace-block") {
|
|
showBlockConfirm = true
|
|
}
|
|
} label: {
|
|
Label("\(owner.displayName) blockieren", systemImage: "hand.raised")
|
|
}
|
|
}
|
|
} label: {
|
|
Image(systemName: "ellipsis.circle")
|
|
}
|
|
}
|
|
|
|
@ViewBuilder
|
|
private var content: some View {
|
|
if isLoading, detail == nil {
|
|
ProgressView()
|
|
.tint(CardsTheme.primary)
|
|
} else if let detail {
|
|
ScrollView {
|
|
VStack(alignment: .leading, spacing: 16) {
|
|
header(detail: detail)
|
|
Divider().background(CardsTheme.border)
|
|
metadata(detail: detail)
|
|
Divider().background(CardsTheme.border)
|
|
subscribeSection(detail: detail)
|
|
if let errorMessage {
|
|
Text(errorMessage)
|
|
.font(.caption)
|
|
.foregroundStyle(CardsTheme.error)
|
|
.padding(.horizontal, 16)
|
|
}
|
|
}
|
|
.padding(.vertical, 16)
|
|
}
|
|
} else if let errorMessage {
|
|
ContentUnavailableView(
|
|
"Deck nicht gefunden",
|
|
systemImage: "questionmark.folder",
|
|
description: Text(errorMessage)
|
|
)
|
|
.foregroundStyle(CardsTheme.foreground)
|
|
}
|
|
}
|
|
|
|
private func header(detail: PublicDeckDetail) -> some View {
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
HStack {
|
|
Text(detail.deck.title)
|
|
.font(.title.bold())
|
|
.foregroundStyle(CardsTheme.foreground)
|
|
if detail.deck.isFeatured {
|
|
Image(systemName: "star.fill")
|
|
.foregroundStyle(CardsTheme.warning)
|
|
}
|
|
}
|
|
if let description = detail.deck.description, !description.isEmpty {
|
|
Text(description)
|
|
.foregroundStyle(CardsTheme.mutedForeground)
|
|
}
|
|
}
|
|
.padding(.horizontal, 16)
|
|
}
|
|
|
|
private func metadata(detail: PublicDeckDetail) -> some View {
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
if let owner = detail.owner {
|
|
HStack(spacing: 6) {
|
|
Image(systemName: "person.crop.circle")
|
|
.foregroundStyle(CardsTheme.mutedForeground)
|
|
Text(owner.displayName)
|
|
.foregroundStyle(CardsTheme.foreground)
|
|
if owner.verifiedMana {
|
|
Image(systemName: "checkmark.seal.fill")
|
|
.font(.caption)
|
|
.foregroundStyle(CardsTheme.primary)
|
|
}
|
|
}
|
|
.font(.subheadline)
|
|
}
|
|
HStack(spacing: 16) {
|
|
if let version = detail.latestVersion {
|
|
Label("v\(version.semver)", systemImage: "tag")
|
|
Label("\(version.cardCount) Karten", systemImage: "rectangle.stack")
|
|
}
|
|
Label(detail.deck.license, systemImage: "doc.text")
|
|
if let language = detail.deck.language {
|
|
Label(language.uppercased(), systemImage: "globe")
|
|
}
|
|
}
|
|
.font(.caption)
|
|
.foregroundStyle(CardsTheme.mutedForeground)
|
|
|
|
if let changelog = detail.latestVersion?.changelog, !changelog.isEmpty {
|
|
Text("Changelog")
|
|
.font(.caption.weight(.semibold))
|
|
.foregroundStyle(CardsTheme.mutedForeground)
|
|
.padding(.top, 8)
|
|
Text(changelog)
|
|
.font(.caption)
|
|
.foregroundStyle(CardsTheme.foreground)
|
|
}
|
|
}
|
|
.padding(.horizontal, 16)
|
|
}
|
|
|
|
private func subscribeSection(detail: PublicDeckDetail) -> some View {
|
|
VStack(spacing: 12) {
|
|
if let subscribed {
|
|
Label("Abonniert — dein Fork ist in deiner Bibliothek", systemImage: "checkmark.circle.fill")
|
|
.foregroundStyle(CardsTheme.success)
|
|
.padding()
|
|
.frame(maxWidth: .infinity)
|
|
.background(CardsTheme.success.opacity(0.1), in: RoundedRectangle(cornerRadius: 10))
|
|
NavigationLink(value: subscribed.privateDeckId) {
|
|
Label("Zum eigenen Deck", systemImage: "arrow.right.circle")
|
|
.frame(maxWidth: .infinity)
|
|
.padding(.vertical, 10)
|
|
.background(CardsTheme.primary, in: RoundedRectangle(cornerRadius: 10))
|
|
.foregroundStyle(CardsTheme.primaryForeground)
|
|
}
|
|
.buttonStyle(.plain)
|
|
} else if detail.deck.isTakedown {
|
|
Label("Dieses Deck wurde entfernt", systemImage: "exclamationmark.triangle")
|
|
.foregroundStyle(CardsTheme.error)
|
|
} else if detail.deck.latestVersionId == nil {
|
|
Label("Noch keine Version veröffentlicht", systemImage: "clock")
|
|
.foregroundStyle(CardsTheme.mutedForeground)
|
|
} else {
|
|
Button {
|
|
authGate.require(reason: "marketplace-subscribe") {
|
|
Task { await subscribe(detail: detail) }
|
|
}
|
|
} label: {
|
|
HStack {
|
|
if isSubscribing {
|
|
ProgressView()
|
|
.controlSize(.small)
|
|
.tint(CardsTheme.primaryForeground)
|
|
}
|
|
Text(detail.deck.priceCredits > 0
|
|
? "Abonnieren (\(detail.deck.priceCredits) Credits)"
|
|
: "Abonnieren")
|
|
.fontWeight(.semibold)
|
|
}
|
|
.frame(maxWidth: .infinity)
|
|
.padding(.vertical, 14)
|
|
.background(CardsTheme.primary, in: RoundedRectangle(cornerRadius: 10))
|
|
.foregroundStyle(CardsTheme.primaryForeground)
|
|
}
|
|
.buttonStyle(.plain)
|
|
.disabled(isSubscribing)
|
|
}
|
|
}
|
|
.padding(.horizontal, 16)
|
|
}
|
|
|
|
private func load() async {
|
|
isLoading = true
|
|
defer { isLoading = false }
|
|
let api = CardsAPI(auth: auth)
|
|
do {
|
|
detail = try await api.publicDeck(slug: slug)
|
|
} catch {
|
|
errorMessage = (error as? LocalizedError)?.errorDescription ?? String(describing: error)
|
|
}
|
|
}
|
|
|
|
private func blockAuthor(slug: String, name: String) async {
|
|
let api = CardsAPI(auth: auth)
|
|
do {
|
|
try await api.blockAuthor(slug: slug)
|
|
moderationToast = "\(name) blockiert."
|
|
} catch {
|
|
moderationToast = "Blockieren fehlgeschlagen: \(error.localizedDescription)"
|
|
}
|
|
}
|
|
|
|
private func subscribe(detail _: PublicDeckDetail) async {
|
|
isSubscribing = true
|
|
errorMessage = nil
|
|
defer { isSubscribing = false }
|
|
let api = CardsAPI(auth: auth)
|
|
do {
|
|
let response = try await api.subscribe(slug: slug)
|
|
subscribed = response
|
|
// Cache neu laden, damit der Fork in der Liste auftaucht
|
|
let store = DeckListStore(auth: auth, context: context)
|
|
await store.refresh()
|
|
} catch {
|
|
errorMessage = (error as? LocalizedError)?.errorDescription ?? String(describing: error)
|
|
}
|
|
}
|
|
}
|
|
|
|
// swiftlint:enable type_body_length
|