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>
This commit is contained in:
parent
8ca7bd3636
commit
73f9081fa1
26 changed files with 3419 additions and 442 deletions
122
Sources/Features/Decks/DeckCoverTile.swift
Normal file
122
Sources/Features/Decks/DeckCoverTile.swift
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
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
|
||||
}
|
||||
|
|
@ -2,8 +2,16 @@ import ManaCore
|
|||
import SwiftData
|
||||
import SwiftUI
|
||||
|
||||
// swiftlint:disable file_length
|
||||
// swiftlint:disable type_body_length
|
||||
|
||||
/// Deck-Detail mit Aktionen + Card-Liste. Wird per Tap auf eine Deck-Row
|
||||
/// aus der DeckListView geöffnet.
|
||||
///
|
||||
/// `type_body_length` ist bewusst übersprungen — Detail-View hostet
|
||||
/// 5 verschiedene Sheets (Edit, CardCreate, CardEdit, Publish, Print),
|
||||
/// Confirmation-Dialog + Alerts; aufspalten ginge nur über Multi-State-
|
||||
/// Plumbing zwischen Parent und Children.
|
||||
struct DeckDetailView: View {
|
||||
let deckId: String
|
||||
|
||||
|
|
@ -17,11 +25,19 @@ struct DeckDetailView: View {
|
|||
@State private var showDeleteConfirm = false
|
||||
@State private var navigateToStudy = false
|
||||
@State private var deleteError: String?
|
||||
@State private var editingCard: Card?
|
||||
|
||||
@State private var cards: [Card] = []
|
||||
@State private var isLoadingCards = false
|
||||
@State private var cardsError: String?
|
||||
|
||||
@State private var isPullingUpdate = false
|
||||
@State private var isDuplicating = false
|
||||
@State private var pullAlert: AlertMessage?
|
||||
@State private var actionError: String?
|
||||
@State private var showPublishSheet = false
|
||||
@State private var showPrintSheet = false
|
||||
|
||||
init(deckId: String) {
|
||||
self.deckId = deckId
|
||||
_decks = Query(filter: #Predicate<CachedDeck> { $0.id == deckId })
|
||||
|
|
@ -53,7 +69,7 @@ struct DeckDetailView: View {
|
|||
}
|
||||
.sheet(isPresented: $showCardEditor) {
|
||||
NavigationStack {
|
||||
CardEditorView(deckId: deckId) { _ in
|
||||
CardEditorView(mode: .create(deckId: deckId)) { _ in
|
||||
Task {
|
||||
await refreshAfterEdit()
|
||||
await loadCards()
|
||||
|
|
@ -61,6 +77,36 @@ struct DeckDetailView: View {
|
|||
}
|
||||
}
|
||||
}
|
||||
.sheet(item: $editingCard) { card in
|
||||
NavigationStack {
|
||||
CardEditorView(mode: .edit(card: card)) { _ in
|
||||
Task {
|
||||
await refreshAfterEdit()
|
||||
await loadCards()
|
||||
editingCard = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.sheet(isPresented: $showPublishSheet) {
|
||||
if let deck = decks.first {
|
||||
NavigationStack {
|
||||
MarketplacePublishView(privateDeck: deck) { _ in
|
||||
showPublishSheet = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.sheet(isPresented: $showPrintSheet) {
|
||||
NavigationStack {
|
||||
DeckPrintView(deckId: deckId)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
Button("Fertig") { showPrintSheet = false }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.confirmationDialog(
|
||||
"Deck löschen?",
|
||||
isPresented: $showDeleteConfirm,
|
||||
|
|
@ -71,7 +117,12 @@ struct DeckDetailView: View {
|
|||
}
|
||||
Button("Abbrechen", role: .cancel) {}
|
||||
} message: {
|
||||
Text("Alle Karten und Reviews dieses Decks werden ebenfalls gelöscht. Diese Aktion kann nicht rückgängig gemacht werden.")
|
||||
Text(
|
||||
"""
|
||||
Alle Karten und Reviews dieses Decks werden ebenfalls \
|
||||
gelöscht. Diese Aktion kann nicht rückgängig gemacht werden.
|
||||
"""
|
||||
)
|
||||
}
|
||||
.navigationDestination(isPresented: $navigateToStudy) {
|
||||
if let deck = decks.first {
|
||||
|
|
@ -84,6 +135,21 @@ struct DeckDetailView: View {
|
|||
.refreshable {
|
||||
await loadCards()
|
||||
}
|
||||
.alert(item: $pullAlert) { alert in
|
||||
Alert(title: Text(alert.title), message: Text(alert.message), dismissButton: .default(Text("OK")))
|
||||
}
|
||||
.alert(
|
||||
"Aktion fehlgeschlagen",
|
||||
isPresented: Binding(
|
||||
get: { actionError != nil },
|
||||
set: { if !$0 { actionError = nil } }
|
||||
),
|
||||
presenting: actionError
|
||||
) { _ in
|
||||
Button("OK") { actionError = nil }
|
||||
} message: { message in
|
||||
Text(message)
|
||||
}
|
||||
}
|
||||
|
||||
private func content(deck: CachedDeck) -> some View {
|
||||
|
|
@ -136,65 +202,56 @@ struct DeckDetailView: View {
|
|||
|
||||
private func actions(deck: CachedDeck) -> some View {
|
||||
VStack(spacing: 12) {
|
||||
Button {
|
||||
navigateToStudy = true
|
||||
} label: {
|
||||
Label("Karten lernen", systemImage: "play.fill")
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, 12)
|
||||
.background(CardsTheme.primary, in: RoundedRectangle(cornerRadius: 10))
|
||||
.foregroundStyle(CardsTheme.primaryForeground)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.disabled(deck.dueCount == 0)
|
||||
|
||||
Button {
|
||||
showCardEditor = true
|
||||
} label: {
|
||||
Label("Karte hinzufügen", systemImage: "plus.rectangle.on.rectangle")
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, 12)
|
||||
.background(CardsTheme.surface, in: RoundedRectangle(cornerRadius: 10))
|
||||
.foregroundStyle(CardsTheme.foreground)
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.stroke(CardsTheme.border, lineWidth: 1)
|
||||
)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
|
||||
HStack(spacing: 12) {
|
||||
Button {
|
||||
showEditor = true
|
||||
} label: {
|
||||
Label("Bearbeiten", systemImage: "pencil")
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, 10)
|
||||
.background(CardsTheme.surface, in: RoundedRectangle(cornerRadius: 10))
|
||||
.foregroundStyle(CardsTheme.foreground)
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.stroke(CardsTheme.border, lineWidth: 1)
|
||||
)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
|
||||
Button {
|
||||
showDeleteConfirm = true
|
||||
} label: {
|
||||
Label("Löschen", systemImage: "trash")
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, 10)
|
||||
.background(CardsTheme.error.opacity(0.1), in: RoundedRectangle(cornerRadius: 10))
|
||||
.foregroundStyle(CardsTheme.error)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
primaryActions
|
||||
secondaryActions(deck: deck)
|
||||
}
|
||||
.padding(.horizontal, 16)
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var primaryActions: some View {
|
||||
Button {
|
||||
navigateToStudy = true
|
||||
} label: {
|
||||
Label("Karten lernen", systemImage: "play.fill")
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, 12)
|
||||
.background(CardsTheme.primary, in: RoundedRectangle(cornerRadius: 10))
|
||||
.foregroundStyle(CardsTheme.primaryForeground)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.disabled((decks.first?.dueCount ?? 0) == 0)
|
||||
|
||||
Button {
|
||||
showCardEditor = true
|
||||
} label: {
|
||||
Label("Karte hinzufügen", systemImage: "plus.rectangle.on.rectangle")
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, 12)
|
||||
.background(CardsTheme.surface, in: RoundedRectangle(cornerRadius: 10))
|
||||
.foregroundStyle(CardsTheme.foreground)
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.stroke(CardsTheme.border, lineWidth: 1)
|
||||
)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
|
||||
private func secondaryActions(deck: CachedDeck) -> some View {
|
||||
DeckSecondaryActions(
|
||||
isForkedFromMarketplace: deck.isFromMarketplace,
|
||||
isPullingUpdate: isPullingUpdate,
|
||||
isDuplicating: isDuplicating,
|
||||
onPullUpdate: { Task { await pullUpdate() } },
|
||||
onDuplicate: { Task { await duplicate() } },
|
||||
onPublish: { showPublishSheet = true },
|
||||
onPrint: { showPrintSheet = true },
|
||||
onEdit: { showEditor = true },
|
||||
onDelete: { showDeleteConfirm = true }
|
||||
)
|
||||
}
|
||||
|
||||
private var cardListSection: some View {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
HStack {
|
||||
|
|
@ -233,8 +290,14 @@ struct DeckDetailView: View {
|
|||
} else {
|
||||
LazyVStack(spacing: 8) {
|
||||
ForEach(cards) { card in
|
||||
CardPreviewRow(card: card)
|
||||
.padding(.horizontal, 16)
|
||||
Button {
|
||||
editingCard = card
|
||||
} label: {
|
||||
CardPreviewRow(card: card)
|
||||
.padding(.horizontal, 16)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.accessibilityHint("Tippen zum Bearbeiten")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -246,6 +309,55 @@ struct DeckDetailView: View {
|
|||
await store.refresh()
|
||||
}
|
||||
|
||||
private func pullUpdate() async {
|
||||
isPullingUpdate = true
|
||||
defer { isPullingUpdate = false }
|
||||
let api = CardsAPI(auth: auth)
|
||||
do {
|
||||
let result = try await api.pullUpdate(deckId: deckId)
|
||||
pullAlert = formatPullResult(result)
|
||||
await refreshAfterEdit()
|
||||
await loadCards()
|
||||
} catch let error as AuthError {
|
||||
actionError = error.errorDescription ?? "Update fehlgeschlagen"
|
||||
} catch {
|
||||
actionError = error.localizedDescription
|
||||
}
|
||||
}
|
||||
|
||||
private func formatPullResult(_ result: PullUpdateResponse) -> AlertMessage {
|
||||
if result.upToDate {
|
||||
return AlertMessage(
|
||||
title: "Schon aktuell",
|
||||
message: "Es gibt keine neue Marketplace-Version dieses Decks."
|
||||
)
|
||||
}
|
||||
let inserted = result.cardsInserted ?? 0
|
||||
let parts = [
|
||||
inserted > 0 ? "\(inserted) Karten hinzugefügt" : nil,
|
||||
result.changed > 0 ? "\(result.changed) Karten geändert" : nil,
|
||||
result.removed > 0 ? "\(result.removed) im Marketplace entfernt (lokal behalten)" : nil
|
||||
].compactMap(\.self)
|
||||
let body = parts.isEmpty ? "Update angewendet." : parts.joined(separator: ", ")
|
||||
let versionText = result.to.map { "Version \($0.semver)" } ?? "Update angewendet"
|
||||
return AlertMessage(title: versionText, message: body)
|
||||
}
|
||||
|
||||
private func duplicate() async {
|
||||
isDuplicating = true
|
||||
defer { isDuplicating = false }
|
||||
let api = CardsAPI(auth: auth)
|
||||
do {
|
||||
_ = try await api.duplicateDeck(id: deckId)
|
||||
await refreshAfterEdit()
|
||||
dismiss()
|
||||
} catch let error as AuthError {
|
||||
actionError = error.errorDescription ?? "Duplizieren fehlgeschlagen"
|
||||
} catch {
|
||||
actionError = error.localizedDescription
|
||||
}
|
||||
}
|
||||
|
||||
private func loadCards() async {
|
||||
isLoadingCards = true
|
||||
cardsError = nil
|
||||
|
|
@ -275,6 +387,15 @@ struct DeckDetailView: View {
|
|||
}
|
||||
}
|
||||
|
||||
// swiftlint:enable type_body_length
|
||||
|
||||
/// Einfacher Alert-Body — Title + Message für `.alert(item:)`-Trigger.
|
||||
struct AlertMessage: Identifiable {
|
||||
let id = UUID()
|
||||
let title: String
|
||||
let message: String
|
||||
}
|
||||
|
||||
/// Kompakte Card-Row mit Front-Vorschau und Type-Badge.
|
||||
private struct CardPreviewRow: View {
|
||||
let card: Card
|
||||
|
|
@ -307,15 +428,15 @@ private struct CardPreviewRow: View {
|
|||
private func preview(card: Card) -> String {
|
||||
switch card.type {
|
||||
case .basic, .basicReverse, .typing, .multipleChoice:
|
||||
return card.fields["front"] ?? "—"
|
||||
card.fields["front"] ?? "—"
|
||||
case .cloze:
|
||||
return card.fields["text"] ?? "—"
|
||||
card.fields["text"] ?? "—"
|
||||
case .imageOcclusion:
|
||||
return card.fields["note"]?.isEmpty == false
|
||||
card.fields["note"]?.isEmpty == false
|
||||
? card.fields["note"]!
|
||||
: "Bild-Verdeckung (\(MaskRegions.count(card.fields["mask_regions"] ?? "")) Masken)"
|
||||
case .audioFront:
|
||||
return card.fields["back"] ?? "Audio-Karte"
|
||||
card.fields["back"] ?? "Audio-Karte"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ enum DeckRoute: Hashable {
|
|||
case detail(deckId: String)
|
||||
}
|
||||
|
||||
// swiftlint:disable type_body_length
|
||||
|
||||
/// Decks-Hauptbildschirm im Cardecky-Look: horizontale Scroll-Reihen
|
||||
/// mit Fan-Stack-Karten-Tiles. Web-Vorbild:
|
||||
/// `cards/apps/web/src/routes/decks/+page.svelte`.
|
||||
|
|
@ -238,7 +240,10 @@ struct DeckListView: View {
|
|||
.foregroundStyle(CardsTheme.foreground)
|
||||
} description: {
|
||||
Text(
|
||||
"Browse den Marketplace im Entdecken-Tab — kein Konto nötig. Für eigene Decks und Cloud-Sync logge dich ein."
|
||||
"""
|
||||
Browse den Marketplace im Entdecken-Tab — kein Konto \
|
||||
nötig. Für eigene Decks und Cloud-Sync logge dich ein.
|
||||
"""
|
||||
)
|
||||
.foregroundStyle(CardsTheme.mutedForeground)
|
||||
} actions: {
|
||||
|
|
@ -254,7 +259,10 @@ struct DeckListView: View {
|
|||
.foregroundStyle(CardsTheme.foreground)
|
||||
} description: {
|
||||
Text(
|
||||
"Tippe unten auf »+«, um dein erstes Deck zu erstellen, oder browse den Marketplace im Entdecken-Tab."
|
||||
"""
|
||||
Tippe unten auf »+«, um dein erstes Deck zu erstellen, \
|
||||
oder browse den Marketplace im Entdecken-Tab.
|
||||
"""
|
||||
)
|
||||
.foregroundStyle(CardsTheme.mutedForeground)
|
||||
}
|
||||
|
|
@ -285,3 +293,5 @@ struct DeckListView: View {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// swiftlint:enable type_body_length
|
||||
|
|
|
|||
56
Sources/Features/Decks/DeckPrintView.swift
Normal file
56
Sources/Features/Decks/DeckPrintView.swift
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import SwiftUI
|
||||
|
||||
#if canImport(SafariServices) && canImport(UIKit)
|
||||
import SafariServices
|
||||
import UIKit
|
||||
#endif
|
||||
|
||||
/// In-App-Browser für die Druck-Ansicht des Decks. Nutzt
|
||||
/// `SFSafariViewController`, weil iOS dort die Print-Sheet und
|
||||
/// „In Dateien speichern" → PDF von Haus aus mitbringt — kein eigener
|
||||
/// PDF-Renderer in der App nötig.
|
||||
///
|
||||
/// Auth-Cookies für `cardecky.mana.how` werden geteilt mit Safari auf
|
||||
/// dem Gerät; der User muss dort eingeloggt sein, damit die Print-
|
||||
/// Seite den Deck-Inhalt rendert.
|
||||
struct DeckPrintView: View {
|
||||
let deckId: String
|
||||
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
|
||||
private var printURL: URL {
|
||||
URL(string: "https://cardecky.mana.how/decks/\(deckId)/print")!
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
#if canImport(SafariServices) && canImport(UIKit)
|
||||
SafariViewRepresentable(url: printURL)
|
||||
.ignoresSafeArea()
|
||||
#else
|
||||
VStack(spacing: 16) {
|
||||
Text("Druck-Ansicht ist nur auf iOS verfügbar.")
|
||||
.font(.subheadline)
|
||||
Link("Im Web öffnen", destination: printURL)
|
||||
Button("Schließen") { dismiss() }
|
||||
}
|
||||
.padding(32)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if canImport(SafariServices) && canImport(UIKit)
|
||||
private struct SafariViewRepresentable: UIViewControllerRepresentable {
|
||||
let url: URL
|
||||
|
||||
func makeUIViewController(context _: Context) -> SFSafariViewController {
|
||||
let config = SFSafariViewController.Configuration()
|
||||
config.entersReaderIfAvailable = false
|
||||
let controller = SFSafariViewController(url: url, configuration: config)
|
||||
controller.preferredControlTintColor = .systemGreen
|
||||
controller.dismissButtonStyle = .close
|
||||
return controller
|
||||
}
|
||||
|
||||
func updateUIViewController(_: SFSafariViewController, context _: Context) {}
|
||||
}
|
||||
#endif
|
||||
138
Sources/Features/Decks/DeckSecondaryActions.swift
Normal file
138
Sources/Features/Decks/DeckSecondaryActions.swift
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
import SwiftUI
|
||||
|
||||
/// Sekundär-Action-Buttons unterhalb der Lern-/Karten-hinzufügen-Buttons
|
||||
/// in `DeckDetailView`. Eigenständige View, damit `DeckDetailView` selbst
|
||||
/// nicht über die Type-Body-Length-Grenze rutscht und die einzelnen
|
||||
/// Aktionen einzeln (z.B. via Snapshot-Tests) prüfbar bleiben.
|
||||
///
|
||||
/// Reines Layout — alle Side-Effects laufen über die Callbacks im Parent.
|
||||
struct DeckSecondaryActions: View {
|
||||
let isForkedFromMarketplace: Bool
|
||||
let isPullingUpdate: Bool
|
||||
let isDuplicating: Bool
|
||||
let onPullUpdate: () -> Void
|
||||
let onDuplicate: () -> Void
|
||||
let onPublish: () -> Void
|
||||
let onPrint: () -> Void
|
||||
let onEdit: () -> Void
|
||||
let onDelete: () -> Void
|
||||
|
||||
var body: some View {
|
||||
if isForkedFromMarketplace {
|
||||
updateButton
|
||||
} else {
|
||||
publishButton
|
||||
}
|
||||
duplicateButton
|
||||
printButton
|
||||
editDeleteRow
|
||||
}
|
||||
|
||||
private var printButton: some View {
|
||||
Button(action: onPrint) {
|
||||
HStack {
|
||||
Image(systemName: "printer")
|
||||
Text("Druck-Ansicht / PDF")
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, 10)
|
||||
.background(CardsTheme.surface, in: RoundedRectangle(cornerRadius: 10))
|
||||
.foregroundStyle(CardsTheme.foreground)
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.stroke(CardsTheme.border, lineWidth: 1)
|
||||
)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
|
||||
private var publishButton: some View {
|
||||
Button(action: onPublish) {
|
||||
HStack {
|
||||
Image(systemName: "globe.badge.chevron.backward")
|
||||
Text("Im Marketplace veröffentlichen")
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, 10)
|
||||
.background(CardsTheme.surface, in: RoundedRectangle(cornerRadius: 10))
|
||||
.foregroundStyle(CardsTheme.primary)
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.stroke(CardsTheme.primary.opacity(0.3), lineWidth: 1)
|
||||
)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
|
||||
private var updateButton: some View {
|
||||
Button(action: onPullUpdate) {
|
||||
HStack {
|
||||
if isPullingUpdate {
|
||||
ProgressView().tint(CardsTheme.primary)
|
||||
} else {
|
||||
Image(systemName: "arrow.triangle.2.circlepath")
|
||||
}
|
||||
Text(isPullingUpdate ? "Wird geprüft …" : "Updates aus Marketplace prüfen")
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, 10)
|
||||
.background(CardsTheme.surface, in: RoundedRectangle(cornerRadius: 10))
|
||||
.foregroundStyle(CardsTheme.primary)
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.stroke(CardsTheme.primary.opacity(0.3), lineWidth: 1)
|
||||
)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.disabled(isPullingUpdate)
|
||||
}
|
||||
|
||||
private var duplicateButton: some View {
|
||||
Button(action: onDuplicate) {
|
||||
HStack {
|
||||
if isDuplicating {
|
||||
ProgressView().tint(CardsTheme.foreground)
|
||||
} else {
|
||||
Image(systemName: "doc.on.doc")
|
||||
}
|
||||
Text(isDuplicating ? "Wird dupliziert …" : "Deck duplizieren")
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, 10)
|
||||
.background(CardsTheme.surface, in: RoundedRectangle(cornerRadius: 10))
|
||||
.foregroundStyle(CardsTheme.foreground)
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.stroke(CardsTheme.border, lineWidth: 1)
|
||||
)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.disabled(isDuplicating)
|
||||
}
|
||||
|
||||
private var editDeleteRow: some View {
|
||||
HStack(spacing: 12) {
|
||||
Button(action: onEdit) {
|
||||
Label("Bearbeiten", systemImage: "pencil")
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, 10)
|
||||
.background(CardsTheme.surface, in: RoundedRectangle(cornerRadius: 10))
|
||||
.foregroundStyle(CardsTheme.foreground)
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.stroke(CardsTheme.border, lineWidth: 1)
|
||||
)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
|
||||
Button(action: onDelete) {
|
||||
Label("Löschen", systemImage: "trash")
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, 10)
|
||||
.background(CardsTheme.error.opacity(0.1), in: RoundedRectangle(cornerRadius: 10))
|
||||
.foregroundStyle(CardsTheme.error)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue