cards-native/Sources/Features/Decks/DeckCoverTile.swift
Till JS 73f9081fa1 feat(decks): γ-1 bis γ-8 — AI/CSV-Import, Card-Edit, Pull-Update, Marketplace-Publish + Moderation + PDF
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>
2026-05-14 02:03:59 +02:00

122 lines
4.1 KiB
Swift

import SwiftUI
/// Gemeinsame Karten-Tile mit Fan-Stack-Hintergrund-Layern.
/// Basis für `DeckStackTile` (eigene Decks) und `PublicDeckCard`
/// (Marketplace-Decks). Web-Vorbild:
/// `cards/apps/web/src/lib/components/DeckStack.svelte` und
/// `MarketplaceDeckStack.svelte` selbe Größe, selbes Stack-Visual,
/// nur der Footer variiert.
struct DeckCoverTile<Footer: View>: View {
let title: String
let description: String?
let category: DeckCategory?
let seed: String
let colorAccentHex: String?
let isFeatured: Bool
@ViewBuilder let footer: () -> Footer
init(
title: String,
description: String? = nil,
category: DeckCategory? = nil,
seed: String,
colorAccentHex: String? = nil,
isFeatured: Bool = false,
@ViewBuilder footer: @escaping () -> Footer
) {
self.title = title
self.description = description
self.category = category
self.seed = seed
self.colorAccentHex = colorAccentHex
self.isFeatured = isFeatured
self.footer = footer
}
var body: some View {
ZStack {
ForEach(Array(layers.enumerated()), id: \.offset) { _, layer in
RoundedRectangle(cornerRadius: 14, style: .continuous)
.fill(CardsTheme.surface)
.overlay(
RoundedRectangle(cornerRadius: 14, style: .continuous)
.stroke(CardsTheme.border, lineWidth: 1)
)
.opacity(layer.opacity)
.rotationEffect(.degrees(layer.tilt))
.offset(x: layer.dx, y: layer.dy)
.shadow(color: CardsTheme.foreground.opacity(0.05), radius: 2, y: 1)
}
CardSurface(size: .md, elevation: .standard, colorAccentHex: colorAccentHex) {
cardContent
}
}
.aspectRatio(5.0 / 7.0, contentMode: .fit)
.frame(maxWidth: 280)
}
private var cardContent: some View {
VStack(alignment: .leading, spacing: 6) {
HStack(alignment: .top) {
if isFeatured {
Image(systemName: "star.fill")
.font(.caption)
.foregroundStyle(CardsTheme.warning)
}
Spacer()
Image(systemName: category?.systemImageName ?? "rectangle.stack")
.font(.title2)
.foregroundStyle(CardsTheme.primary.opacity(0.85))
}
Spacer(minLength: 0)
VStack(alignment: .leading, spacing: 6) {
Text(title)
.font(.system(size: 17, weight: .semibold))
.foregroundStyle(CardsTheme.foreground)
.lineLimit(3)
if let description, !description.isEmpty {
Text(description)
.font(.caption)
.foregroundStyle(CardsTheme.mutedForeground)
.lineLimit(2)
}
}
Spacer(minLength: 0)
footer()
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
}
private var layers: [DeckCoverStackLayer] {
var hash = UInt64(0)
for byte in seed.utf8 {
hash = hash &* 31 &+ UInt64(byte)
}
return (0 ..< 3).map { index in
let seedHash = hash &+ UInt64(index) &* 17
let tiltRaw = Double((seedHash >> 8) & 0xFF) / 255.0 - 0.5
let xRaw = Double((seedHash >> 16) & 0xFF) / 255.0 - 0.5
let yRaw = Double((seedHash >> 24) & 0xFF) / 255.0 - 0.5
let depth = Double(index + 1)
return DeckCoverStackLayer(
tilt: tiltRaw * 4.0,
dx: xRaw * 6.0,
dy: depth * 3.0 + yRaw * 2.0,
opacity: 0.7 - depth * 0.18
)
}
}
}
private struct DeckCoverStackLayer {
let tilt: Double
let dx: Double
let dy: Double
let opacity: Double
}