wordeck-native/Sources/Features/Marketplace/ExploreView.swift
Till JS 542082772a refactor(big-bang): cards-native → wordeck-native
Code + Identity-Rename zur Vorbereitung auf Apple-Dev-Portal-Aktion
(Bundle ev.mana.wordeck, App-Group group.ev.mana.wordeck, AASA
applinks:wordeck.com). Build bleibt funktional, aber gegen die
neue text-only-API können image-occlusion-Creates 422 zurückgeben —
das wird mit der Wordeck-Native v1.0-Welle (parallele Apple-Aktion)
sauber gemacht.

Umbenennung:
- 41 Files: cardecky/Cardecky → wordeck/Wordeck (Display, Strings,
  Kommentare)
- 57 Files: CardsNative → WordeckNative, CardsAPI → WordeckAPI,
  CardsTheme → WordeckTheme, CardsBrand → WordeckBrand, CardsWidget →
  WordeckWidget, CardsDueWidget → WordeckDueWidget
- Bundle-ID ev.mana.cardecky → ev.mana.wordeck (project.yml,
  Info.plist, entitlements, Keychain-Service, App-Group)
- AASA applinks:cardecky.mana.how → applinks:wordeck.com
- API-Base cardecky-api.mana.how → api.wordeck.com
- 10 Files renamed (App-Entry, API-Extensions, Theme, Widget,
  Entitlements, Tests)
- xcodeproj regenerated via xcodegen → WordeckNative.xcodeproj
- MaskRegionsTests.swift gelöscht (image-occlusion entfällt mit
  Wordeck text-only)

Forgejo-Repo git.mana.how/till/cards-native → wordeck-native umbenannt
(Auto-Redirect aktiv). Lokales Verzeichnis Code/cards-native/ bleibt
vorerst — wird beim nächsten Apple-Setup mit Bundle-Test umbenannt.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-17 23:10:42 +02:00

193 lines
7.1 KiB
Swift

import ManaCore
import SwiftUI
/// Explore-Tab: Featured + Trending Sections, plus Browse-Link.
struct ExploreView: View {
@Binding var deepLinkSlug: String?
@Environment(AuthClient.self) private var auth
@State private var store: MarketplaceStore?
@State private var path: [MarketplaceRoute] = []
init(deepLinkSlug: Binding<String?> = .constant(nil)) {
_deepLinkSlug = deepLinkSlug
}
var body: some View {
NavigationStack(path: $path) {
ZStack {
WordeckTheme.background.ignoresSafeArea()
content
}
.navigationTitle("Entdecken")
#if os(iOS)
.navigationBarTitleDisplayMode(.inline)
#endif
.navigationDestination(for: MarketplaceRoute.self) { route in
switch route {
case .browse:
BrowseView()
case let .publicDeck(slug):
PublicDeckView(slug: slug)
}
}
.navigationDestination(for: String.self) { deckId in
DeckDetailView(deckId: deckId)
}
.refreshable {
await store?.loadExplore()
}
.task {
if store == nil {
store = MarketplaceStore(auth: auth)
}
await store?.loadExplore()
}
.onChange(of: deepLinkSlug) { _, newSlug in
guard let slug = newSlug else { return }
path = [.publicDeck(slug: slug)]
deepLinkSlug = nil
}
}
}
@ViewBuilder
private var content: some View {
if let store {
if store.isLoadingExplore, store.featured.isEmpty, store.trending.isEmpty {
ProgressView()
.tint(WordeckTheme.primary)
} else if let message = store.errorMessage, store.featured.isEmpty {
ContentUnavailableView(
"Marketplace nicht erreichbar",
systemImage: "wifi.exclamationmark",
description: Text(message)
)
.foregroundStyle(WordeckTheme.foreground)
} else {
ScrollView {
VStack(alignment: .leading, spacing: 24) {
if !store.featured.isEmpty {
section(title: "Vorgestellt", icon: "star.fill", items: store.featured)
}
if !store.trending.isEmpty {
section(title: "Im Trend", icon: "flame.fill", items: store.trending)
}
NavigationLink(value: MarketplaceRoute.browse) {
HStack {
Label("Alle Decks durchsuchen", systemImage: "magnifyingglass")
Spacer()
Image(systemName: "chevron.right")
.font(.footnote)
}
.padding()
.background(WordeckTheme.surface, in: RoundedRectangle(cornerRadius: 10))
.overlay(
RoundedRectangle(cornerRadius: 10)
.stroke(WordeckTheme.border, lineWidth: 1)
)
.foregroundStyle(WordeckTheme.foreground)
}
.buttonStyle(.plain)
.padding(.horizontal, 20)
}
.padding(.vertical, 12)
}
}
}
}
private func section(title: String, icon: String, items: [PublicDeckEntry]) -> some View {
VStack(alignment: .leading, spacing: 12) {
HStack(spacing: 6) {
Image(systemName: icon)
.foregroundStyle(WordeckTheme.primary)
Text(title)
.font(.title3.weight(.semibold))
.foregroundStyle(WordeckTheme.foreground)
Text("\(items.count)")
.font(.subheadline)
.foregroundStyle(WordeckTheme.mutedForeground)
}
.padding(.horizontal, 20)
ScrollView(.horizontal, showsIndicators: false) {
HStack(alignment: .top, spacing: 16) {
ForEach(items) { item in
NavigationLink(value: MarketplaceRoute.publicDeck(slug: item.slug)) {
PublicDeckCard(entry: item)
.frame(width: 240)
}
.buttonStyle(.plain)
}
}
.padding(.horizontal, 20)
.padding(.bottom, 12)
.scrollTargetLayout()
}
.scrollTargetBehavior(.viewAligned)
}
}
}
/// Routen-Enum für die Marketplace-NavigationStack.
enum MarketplaceRoute: Hashable {
case browse
case publicDeck(slug: String)
}
/// Tile für Marketplace-Decks im Explore-Tab. Nutzt `DeckCoverTile`
/// als Basis (selber Look + Größe wie `DeckStackTile` auf der Decks-
/// Seite). Footer: Karten-Count, Star-Count, Credits, Owner-Badge.
struct PublicDeckCard: View {
let entry: PublicDeckEntry
var body: some View {
DeckCoverTile(
title: entry.title,
description: entry.description,
category: parsedCategory,
seed: entry.slug,
colorAccentHex: nil,
isFeatured: entry.isFeatured
) {
footerContent
}
}
private var parsedCategory: DeckCategory? {
guard let category = entry.category else { return nil }
return DeckCategory(rawValue: category)
}
private var footerContent: some View {
VStack(alignment: .leading, spacing: 6) {
HStack(spacing: 8) {
Label("\(entry.cardCount)", systemImage: "rectangle.stack")
.font(.caption2)
.foregroundStyle(WordeckTheme.mutedForeground)
Label("\(entry.starCount)", systemImage: "star.fill")
.font(.caption2)
.foregroundStyle(WordeckTheme.warning)
if entry.isPaid {
Label("\(entry.priceCredits)", systemImage: "creditcard")
.font(.caption2.weight(.semibold))
.foregroundStyle(WordeckTheme.primary)
}
Spacer()
}
HStack(spacing: 4) {
Text(entry.owner.displayName)
.font(.caption2)
.foregroundStyle(WordeckTheme.mutedForeground)
.lineLimit(1)
if entry.owner.verifiedMana {
Image(systemName: "checkmark.seal.fill")
.font(.caption2)
.foregroundStyle(WordeckTheme.primary)
}
}
}
}
}