v0.6.0 — Phase β-5 Marketplace
Voller Marketplace-Flow mit TabBar und Universal-Link-Handler. Drei Live-Decks (Geografie, English A2, Periodensystem) sind browse-, abonnier- und lernbar. - PublicDeckEntry/PublicDeck/PublicDeckVersion/PublicDeckOwner/ PublicDeckDetail Codable mit snake_case - ExploreResponse, BrowseResponse, SubscribeResponse - MarketplaceSort-Enum (recent/popular/trending) - CardsAPI.explore/browseMarketplace/publicDeck/subscribe/unsubscribe - MarketplaceStore @Observable mit Explore + Browse States - ExploreView: Featured + Trending Horizontal-Carousels, Browse-Link - BrowseView: Searchable + Sort-Picker + List - PublicDeckView: Header/Metadata/Subscribe — Subscribe löst Auto-Fork serverseitig aus, Response liefert private_deck_id, NavigationLink zum eigenen Deck - PublicDeckCard + BrowseRow mit forest-Theme - RootView: TabBar (Decks/Entdecken/Account) statt Single-View - Universal-Link-Handler: onOpenURL + onContinueUserActivity für https://cardecky.mana.how/d/<slug> und cards://d/<slug> - associated-domains: applinks:cardecky.mana.how im entitlement - 5 neue Marketplace-Decoding-Tests (35 Total grün) Universal-Links funktionieren erst nach AASA-Setup auf cardecky.mana.how/.well-known/apple-app-site-association (Web-Aufgabe, heute 404). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
80eb3708b4
commit
07ada72b0f
10 changed files with 1015 additions and 24 deletions
|
|
@ -1,18 +1,62 @@
|
|||
import ManaCore
|
||||
import SwiftUI
|
||||
|
||||
/// Top-Level-Switch: Login vs Deck-Liste.
|
||||
/// Ab Phase β-3 könnte hier eine Tab-Bar entstehen (Decks / Study /
|
||||
/// Stats / Account) — für β-1 reicht der einfache Switch.
|
||||
/// Top-Level-Switch: Login vs Haupt-App. Haupt-App ist eine TabBar mit
|
||||
/// drei Tabs (Decks / Entdecken / Account).
|
||||
struct RootView: View {
|
||||
@Environment(AuthClient.self) private var auth
|
||||
@State private var selectedTab: AppTab = .decks
|
||||
@State private var pendingDeepLinkSlug: String?
|
||||
|
||||
var body: some View {
|
||||
switch auth.status {
|
||||
case .signedIn:
|
||||
DeckListView()
|
||||
mainTabs
|
||||
.onOpenURL { url in handle(url: url) }
|
||||
.onContinueUserActivity(NSUserActivityTypeBrowsingWeb) { activity in
|
||||
if let url = activity.webpageURL { handle(url: url) }
|
||||
}
|
||||
case .unknown, .signedOut, .signingIn, .error:
|
||||
LoginView()
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var mainTabs: some View {
|
||||
TabView(selection: $selectedTab) {
|
||||
DeckListView()
|
||||
.tabItem { Label("Decks", systemImage: "rectangle.stack") }
|
||||
.tag(AppTab.decks)
|
||||
|
||||
ExploreView(deepLinkSlug: $pendingDeepLinkSlug)
|
||||
.tabItem { Label("Entdecken", systemImage: "sparkles") }
|
||||
.tag(AppTab.explore)
|
||||
|
||||
NavigationStack {
|
||||
AccountView()
|
||||
}
|
||||
.tabItem { Label("Account", systemImage: "person.crop.circle") }
|
||||
.tag(AppTab.account)
|
||||
}
|
||||
}
|
||||
|
||||
/// Universal-Link- und URL-Scheme-Handler:
|
||||
/// - `https://cardecky.mana.how/d/<slug>` → Explore-Tab + PublicDeckView
|
||||
/// - `cards://study/<deckId>` → später (β-6 Notifications)
|
||||
private func handle(url: URL) {
|
||||
Log.app.info("Open URL: \(url.absoluteString, privacy: .public)")
|
||||
if url.host == "cardecky.mana.how" || url.scheme == "cards" {
|
||||
let parts = url.pathComponents.filter { $0 != "/" }
|
||||
if parts.count >= 2, parts[0] == "d" {
|
||||
pendingDeepLinkSlug = parts[1]
|
||||
selectedTab = .explore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum AppTab: Hashable {
|
||||
case decks
|
||||
case explore
|
||||
case account
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,6 +54,72 @@ actor CardsAPI {
|
|||
return try decoder.decode(DueReviewsResponse.self, from: data).total
|
||||
}
|
||||
|
||||
// MARK: - Marketplace
|
||||
|
||||
/// `GET /api/v1/marketplace/explore` — Featured + Trending.
|
||||
func explore() async throws -> ExploreResponse {
|
||||
let (data, http) = try await transport.request(path: "/api/v1/marketplace/explore")
|
||||
try ensureOK(http, data: data)
|
||||
return try decoder.decode(ExploreResponse.self, from: data)
|
||||
}
|
||||
|
||||
/// `GET /api/v1/marketplace/decks` — Browse mit Filtern.
|
||||
func browseMarketplace(
|
||||
query: String? = nil,
|
||||
sort: MarketplaceSort = .recent,
|
||||
language: String? = nil,
|
||||
limit: Int = 20,
|
||||
offset: Int = 0
|
||||
) async throws -> BrowseResponse {
|
||||
var items: [URLQueryItem] = [
|
||||
.init(name: "sort", value: sort.rawValue),
|
||||
.init(name: "limit", value: "\(limit)"),
|
||||
.init(name: "offset", value: "\(offset)"),
|
||||
]
|
||||
if let query, !query.trimmingCharacters(in: .whitespaces).isEmpty {
|
||||
items.append(.init(name: "q", value: query))
|
||||
}
|
||||
if let language {
|
||||
items.append(.init(name: "language", value: language))
|
||||
}
|
||||
var components = URLComponents()
|
||||
components.queryItems = items
|
||||
let queryString = components.percentEncodedQuery ?? ""
|
||||
let path = "/api/v1/marketplace/decks?\(queryString)"
|
||||
|
||||
let (data, http) = try await transport.request(path: path)
|
||||
try ensureOK(http, data: data)
|
||||
return try decoder.decode(BrowseResponse.self, from: data)
|
||||
}
|
||||
|
||||
/// `GET /api/v1/marketplace/decks/:slug`.
|
||||
func publicDeck(slug: String) async throws -> PublicDeckDetail {
|
||||
let (data, http) = try await transport.request(path: "/api/v1/marketplace/decks/\(slug)")
|
||||
try ensureOK(http, data: data)
|
||||
return try decoder.decode(PublicDeckDetail.self, from: data)
|
||||
}
|
||||
|
||||
/// `POST /api/v1/marketplace/decks/:slug/subscribe` — Auto-Fork
|
||||
/// passiert serverseitig, Response liefert `private_deck_id`.
|
||||
@discardableResult
|
||||
func subscribe(slug: String) async throws -> SubscribeResponse {
|
||||
let (data, http) = try await transport.request(
|
||||
path: "/api/v1/marketplace/decks/\(slug)/subscribe",
|
||||
method: "POST"
|
||||
)
|
||||
try ensureOK(http, data: data)
|
||||
return try decoder.decode(SubscribeResponse.self, from: data)
|
||||
}
|
||||
|
||||
/// `DELETE /api/v1/marketplace/decks/:slug/subscribe`.
|
||||
func unsubscribe(slug: String) async throws {
|
||||
let (data, http) = try await transport.request(
|
||||
path: "/api/v1/marketplace/decks/\(slug)/subscribe",
|
||||
method: "DELETE"
|
||||
)
|
||||
try ensureOK(http, data: data)
|
||||
}
|
||||
|
||||
// MARK: - Media
|
||||
|
||||
/// `POST /api/v1/media/upload` — Multipart-Upload. Max 25 MiB.
|
||||
|
|
|
|||
162
Sources/Core/Domain/Marketplace.swift
Normal file
162
Sources/Core/Domain/Marketplace.swift
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
import Foundation
|
||||
|
||||
/// Browse-Eintrag aus `/api/v1/marketplace/decks` und `.../explore`.
|
||||
struct PublicDeckEntry: Codable, Hashable, Sendable, Identifiable {
|
||||
let slug: String
|
||||
let title: String
|
||||
let description: String?
|
||||
let language: String?
|
||||
let category: String?
|
||||
let license: String
|
||||
let priceCredits: Int
|
||||
let cardCount: Int
|
||||
let starCount: Int
|
||||
let subscriberCount: Int
|
||||
let isFeatured: Bool
|
||||
let createdAt: Date
|
||||
let owner: PublicDeckOwner
|
||||
|
||||
var id: String { slug }
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case slug, title, description, language, category, license
|
||||
case priceCredits = "price_credits"
|
||||
case cardCount = "card_count"
|
||||
case starCount = "star_count"
|
||||
case subscriberCount = "subscriber_count"
|
||||
case isFeatured = "is_featured"
|
||||
case createdAt = "created_at"
|
||||
case owner
|
||||
}
|
||||
|
||||
var isPaid: Bool { priceCredits > 0 }
|
||||
}
|
||||
|
||||
struct PublicDeckOwner: Codable, Hashable, Sendable {
|
||||
let slug: String
|
||||
let displayName: String
|
||||
let verifiedMana: Bool
|
||||
let verifiedCommunity: Bool
|
||||
let pseudonym: String?
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case slug
|
||||
case displayName = "display_name"
|
||||
case verifiedMana = "verified_mana"
|
||||
case verifiedCommunity = "verified_community"
|
||||
case pseudonym
|
||||
}
|
||||
|
||||
init(from decoder: Decoder) throws {
|
||||
let c = try decoder.container(keyedBy: CodingKeys.self)
|
||||
slug = try c.decode(String.self, forKey: .slug)
|
||||
displayName = try c.decode(String.self, forKey: .displayName)
|
||||
verifiedMana = try c.decode(Bool.self, forKey: .verifiedMana)
|
||||
verifiedCommunity = try c.decode(Bool.self, forKey: .verifiedCommunity)
|
||||
pseudonym = try c.decodeIfPresent(String.self, forKey: .pseudonym)
|
||||
}
|
||||
}
|
||||
|
||||
/// Response von `GET /api/v1/marketplace/explore`.
|
||||
struct ExploreResponse: Decodable, Sendable {
|
||||
let featured: [PublicDeckEntry]
|
||||
let trending: [PublicDeckEntry]
|
||||
}
|
||||
|
||||
/// Response von `GET /api/v1/marketplace/decks`.
|
||||
struct BrowseResponse: Decodable, Sendable {
|
||||
let items: [PublicDeckEntry]
|
||||
let total: Int
|
||||
}
|
||||
|
||||
/// Vollständiges Public-Deck aus `GET /api/v1/marketplace/decks/:slug`.
|
||||
struct PublicDeck: Codable, Hashable, Sendable, Identifiable {
|
||||
let id: String
|
||||
let slug: String
|
||||
let title: String
|
||||
let description: String?
|
||||
let language: String?
|
||||
let category: String?
|
||||
let license: String
|
||||
let priceCredits: Int
|
||||
let ownerUserId: String
|
||||
let latestVersionId: String?
|
||||
let isFeatured: Bool
|
||||
let isTakedown: Bool
|
||||
let createdAt: Date
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case id, slug, title, description, language, category, license
|
||||
case priceCredits = "price_credits"
|
||||
case ownerUserId = "owner_user_id"
|
||||
case latestVersionId = "latest_version_id"
|
||||
case isFeatured = "is_featured"
|
||||
case isTakedown = "is_takedown"
|
||||
case createdAt = "created_at"
|
||||
}
|
||||
}
|
||||
|
||||
struct PublicDeckVersion: Codable, Hashable, Sendable, Identifiable {
|
||||
let id: String
|
||||
let deckId: String
|
||||
let semver: String
|
||||
let changelog: String?
|
||||
let contentHash: String?
|
||||
let cardCount: Int
|
||||
let publishedAt: Date
|
||||
let deprecatedAt: Date?
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case id
|
||||
case deckId = "deck_id"
|
||||
case semver
|
||||
case changelog
|
||||
case contentHash = "content_hash"
|
||||
case cardCount = "card_count"
|
||||
case publishedAt = "published_at"
|
||||
case deprecatedAt = "deprecated_at"
|
||||
}
|
||||
}
|
||||
|
||||
/// Response von `GET /api/v1/marketplace/decks/:slug`.
|
||||
struct PublicDeckDetail: Decodable, Sendable {
|
||||
let deck: PublicDeck
|
||||
let latestVersion: PublicDeckVersion?
|
||||
let owner: PublicDeckOwner?
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case deck
|
||||
case latestVersion = "latest_version"
|
||||
case owner
|
||||
}
|
||||
}
|
||||
|
||||
/// Response von `POST /api/v1/marketplace/decks/:slug/subscribe`.
|
||||
struct SubscribeResponse: Decodable, Sendable {
|
||||
let subscribed: Bool
|
||||
let deckSlug: String
|
||||
let currentVersionId: String?
|
||||
let privateDeckId: String
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case subscribed
|
||||
case deckSlug = "deck_slug"
|
||||
case currentVersionId = "current_version_id"
|
||||
case privateDeckId = "private_deck_id"
|
||||
}
|
||||
}
|
||||
|
||||
/// Browse-Sort-Optionen aus `BrowseQuerySchema`.
|
||||
enum MarketplaceSort: String, Sendable, CaseIterable {
|
||||
case recent
|
||||
case popular
|
||||
case trending
|
||||
|
||||
var label: String {
|
||||
switch self {
|
||||
case .recent: "Neueste"
|
||||
case .popular: "Beliebt"
|
||||
case .trending: "Im Trend"
|
||||
}
|
||||
}
|
||||
}
|
||||
142
Sources/Features/Marketplace/BrowseView.swift
Normal file
142
Sources/Features/Marketplace/BrowseView.swift
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
import ManaCore
|
||||
import SwiftUI
|
||||
|
||||
/// Browse-View: Suche, Sortier-Picker, Sprachfilter, Liste der Resultate.
|
||||
struct BrowseView: View {
|
||||
@Environment(AuthClient.self) private var auth
|
||||
@State private var store: MarketplaceStore?
|
||||
@State private var queryText: String = ""
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
CardsTheme.background.ignoresSafeArea()
|
||||
VStack(spacing: 0) {
|
||||
filters
|
||||
Divider().background(CardsTheme.border)
|
||||
resultsList
|
||||
}
|
||||
}
|
||||
.navigationTitle("Durchsuchen")
|
||||
#if os(iOS)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
#endif
|
||||
.searchable(text: $queryText, placement: .navigationBarDrawer(displayMode: .always),
|
||||
prompt: "Decks suchen")
|
||||
.onSubmit(of: .search) {
|
||||
store?.browseQuery = queryText
|
||||
Task { await store?.browse() }
|
||||
}
|
||||
.task {
|
||||
if store == nil {
|
||||
store = MarketplaceStore(auth: auth)
|
||||
await store?.browse()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var filters: some View {
|
||||
if let store {
|
||||
HStack {
|
||||
Picker("Sortierung", selection: Binding(
|
||||
get: { store.browseSort },
|
||||
set: { newValue in
|
||||
store.browseSort = newValue
|
||||
Task { await store.browse() }
|
||||
}
|
||||
)) {
|
||||
ForEach(MarketplaceSort.allCases, id: \.self) { sort in
|
||||
Text(sort.label).tag(sort)
|
||||
}
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
}
|
||||
.padding(.horizontal, 16)
|
||||
.padding(.vertical, 8)
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var resultsList: some View {
|
||||
if let store {
|
||||
if store.isLoadingBrowse, store.browseResults.isEmpty {
|
||||
Spacer()
|
||||
ProgressView()
|
||||
.tint(CardsTheme.primary)
|
||||
Spacer()
|
||||
} else if store.browseResults.isEmpty {
|
||||
ContentUnavailableView(
|
||||
"Keine Decks gefunden",
|
||||
systemImage: "magnifyingglass",
|
||||
description: Text("Versuche eine andere Suche oder Sortierung.")
|
||||
)
|
||||
.foregroundStyle(CardsTheme.foreground)
|
||||
} else {
|
||||
List {
|
||||
ForEach(store.browseResults) { entry in
|
||||
NavigationLink(value: MarketplaceRoute.publicDeck(slug: entry.slug)) {
|
||||
BrowseRow(entry: entry)
|
||||
}
|
||||
.listRowBackground(Color.clear)
|
||||
.listRowSeparator(.hidden)
|
||||
.listRowInsets(EdgeInsets(top: 4, leading: 16, bottom: 4, trailing: 16))
|
||||
}
|
||||
}
|
||||
.listStyle(.plain)
|
||||
.scrollContentBackground(.hidden)
|
||||
.refreshable {
|
||||
await store.browse()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct BrowseRow: View {
|
||||
let entry: PublicDeckEntry
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 12) {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
HStack {
|
||||
Text(entry.title)
|
||||
.font(.headline)
|
||||
.foregroundStyle(CardsTheme.foreground)
|
||||
if entry.isFeatured {
|
||||
Image(systemName: "star.fill")
|
||||
.font(.caption)
|
||||
.foregroundStyle(CardsTheme.warning)
|
||||
}
|
||||
}
|
||||
if let description = entry.description, !description.isEmpty {
|
||||
Text(description)
|
||||
.font(.caption)
|
||||
.foregroundStyle(CardsTheme.mutedForeground)
|
||||
.lineLimit(2)
|
||||
}
|
||||
HStack(spacing: 12) {
|
||||
Label("\(entry.cardCount)", systemImage: "rectangle.stack")
|
||||
Label("\(entry.starCount)", systemImage: "star")
|
||||
if entry.isPaid {
|
||||
Label("\(entry.priceCredits)", systemImage: "creditcard")
|
||||
.foregroundStyle(CardsTheme.primary)
|
||||
}
|
||||
if let language = entry.language {
|
||||
Text(language.uppercased())
|
||||
.font(.caption2.weight(.semibold))
|
||||
.padding(.horizontal, 4)
|
||||
.padding(.vertical, 1)
|
||||
.background(CardsTheme.muted, in: Capsule())
|
||||
}
|
||||
}
|
||||
.font(.caption2)
|
||||
.foregroundStyle(CardsTheme.mutedForeground)
|
||||
}
|
||||
Spacer()
|
||||
Image(systemName: "chevron.right")
|
||||
.font(.footnote)
|
||||
.foregroundStyle(CardsTheme.mutedForeground)
|
||||
}
|
||||
.padding(.vertical, 8)
|
||||
}
|
||||
}
|
||||
180
Sources/Features/Marketplace/ExploreView.swift
Normal file
180
Sources/Features/Marketplace/ExploreView.swift
Normal file
|
|
@ -0,0 +1,180 @@
|
|||
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 {
|
||||
CardsTheme.background.ignoresSafeArea()
|
||||
content
|
||||
}
|
||||
.navigationTitle("Entdecken")
|
||||
.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(CardsTheme.primary)
|
||||
} else if let message = store.errorMessage, store.featured.isEmpty {
|
||||
ContentUnavailableView(
|
||||
"Marketplace nicht erreichbar",
|
||||
systemImage: "wifi.exclamationmark",
|
||||
description: Text(message)
|
||||
)
|
||||
.foregroundStyle(CardsTheme.foreground)
|
||||
} else {
|
||||
ScrollView {
|
||||
VStack(alignment: .leading, spacing: 24) {
|
||||
if !store.featured.isEmpty {
|
||||
section(title: "Vorgestellt", items: store.featured)
|
||||
}
|
||||
if !store.trending.isEmpty {
|
||||
section(title: "Im Trend", items: store.trending)
|
||||
}
|
||||
|
||||
NavigationLink(value: MarketplaceRoute.browse) {
|
||||
HStack {
|
||||
Label("Alle Decks durchsuchen", systemImage: "magnifyingglass")
|
||||
Spacer()
|
||||
Image(systemName: "chevron.right")
|
||||
.font(.footnote)
|
||||
}
|
||||
.padding()
|
||||
.background(CardsTheme.surface, in: RoundedRectangle(cornerRadius: 10))
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.stroke(CardsTheme.border, lineWidth: 1)
|
||||
)
|
||||
.foregroundStyle(CardsTheme.foreground)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.padding(.horizontal, 16)
|
||||
}
|
||||
.padding(.vertical, 16)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func section(title: String, items: [PublicDeckEntry]) -> some View {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
Text(title)
|
||||
.font(.title3.weight(.semibold))
|
||||
.foregroundStyle(CardsTheme.foreground)
|
||||
.padding(.horizontal, 16)
|
||||
|
||||
ScrollView(.horizontal, showsIndicators: false) {
|
||||
HStack(spacing: 12) {
|
||||
ForEach(items) { item in
|
||||
NavigationLink(value: MarketplaceRoute.publicDeck(slug: item.slug)) {
|
||||
PublicDeckCard(entry: item)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 16)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Routen-Enum für die Marketplace-NavigationStack.
|
||||
enum MarketplaceRoute: Hashable {
|
||||
case browse
|
||||
case publicDeck(slug: String)
|
||||
}
|
||||
|
||||
/// Public-Deck-Karten-Tile in Featured/Trending-Carousels und Browse-Grid.
|
||||
struct PublicDeckCard: View {
|
||||
let entry: PublicDeckEntry
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
HStack {
|
||||
Text(entry.title)
|
||||
.font(.headline)
|
||||
.foregroundStyle(CardsTheme.foreground)
|
||||
.lineLimit(2)
|
||||
Spacer()
|
||||
if entry.isFeatured {
|
||||
Image(systemName: "star.fill")
|
||||
.font(.caption)
|
||||
.foregroundStyle(CardsTheme.warning)
|
||||
}
|
||||
}
|
||||
if let description = entry.description, !description.isEmpty {
|
||||
Text(description)
|
||||
.font(.caption)
|
||||
.foregroundStyle(CardsTheme.mutedForeground)
|
||||
.lineLimit(2)
|
||||
}
|
||||
HStack(spacing: 12) {
|
||||
Label("\(entry.cardCount)", systemImage: "rectangle.stack")
|
||||
Label("\(entry.starCount)", systemImage: "star")
|
||||
if entry.isPaid {
|
||||
Label("\(entry.priceCredits) Credits", systemImage: "creditcard")
|
||||
.foregroundStyle(CardsTheme.primary)
|
||||
}
|
||||
}
|
||||
.font(.caption2)
|
||||
.foregroundStyle(CardsTheme.mutedForeground)
|
||||
|
||||
HStack(spacing: 4) {
|
||||
Text(entry.owner.displayName)
|
||||
.font(.caption2)
|
||||
.foregroundStyle(CardsTheme.mutedForeground)
|
||||
if entry.owner.verifiedMana {
|
||||
Image(systemName: "checkmark.seal.fill")
|
||||
.font(.caption2)
|
||||
.foregroundStyle(CardsTheme.primary)
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(12)
|
||||
.frame(width: 260, alignment: .leading)
|
||||
.background(CardsTheme.surface, in: RoundedRectangle(cornerRadius: 10))
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.stroke(CardsTheme.border, lineWidth: 1)
|
||||
)
|
||||
}
|
||||
}
|
||||
56
Sources/Features/Marketplace/MarketplaceStore.swift
Normal file
56
Sources/Features/Marketplace/MarketplaceStore.swift
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import Foundation
|
||||
import ManaCore
|
||||
import Observation
|
||||
|
||||
/// Holt Explore-Daten und Browse-Resultate. Browse hat einen aktuellen
|
||||
/// Query-/Sort-State; bei Änderung wird neu gefetcht.
|
||||
@MainActor
|
||||
@Observable
|
||||
final class MarketplaceStore {
|
||||
private(set) var featured: [PublicDeckEntry] = []
|
||||
private(set) var trending: [PublicDeckEntry] = []
|
||||
private(set) var browseResults: [PublicDeckEntry] = []
|
||||
private(set) var isLoadingExplore = false
|
||||
private(set) var isLoadingBrowse = false
|
||||
private(set) var errorMessage: String?
|
||||
|
||||
var browseQuery: String = ""
|
||||
var browseSort: MarketplaceSort = .recent
|
||||
var browseLanguage: String?
|
||||
|
||||
private let api: CardsAPI
|
||||
|
||||
init(auth: AuthClient) {
|
||||
api = CardsAPI(auth: auth)
|
||||
}
|
||||
|
||||
func loadExplore() async {
|
||||
isLoadingExplore = true
|
||||
errorMessage = nil
|
||||
defer { isLoadingExplore = false }
|
||||
do {
|
||||
let res = try await api.explore()
|
||||
featured = res.featured
|
||||
trending = res.trending
|
||||
} catch {
|
||||
errorMessage = (error as? LocalizedError)?.errorDescription ?? String(describing: error)
|
||||
Log.api.error("Explore failed: \(self.errorMessage ?? "", privacy: .public)")
|
||||
}
|
||||
}
|
||||
|
||||
func browse() async {
|
||||
isLoadingBrowse = true
|
||||
errorMessage = nil
|
||||
defer { isLoadingBrowse = false }
|
||||
do {
|
||||
let res = try await api.browseMarketplace(
|
||||
query: browseQuery,
|
||||
sort: browseSort,
|
||||
language: browseLanguage
|
||||
)
|
||||
browseResults = res.items
|
||||
} catch {
|
||||
errorMessage = (error as? LocalizedError)?.errorDescription ?? String(describing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
201
Sources/Features/Marketplace/PublicDeckView.swift
Normal file
201
Sources/Features/Marketplace/PublicDeckView.swift
Normal file
|
|
@ -0,0 +1,201 @@
|
|||
import ManaCore
|
||||
import SwiftData
|
||||
import SwiftUI
|
||||
|
||||
/// Detail-View für ein Public-Deck. Subscribe-Button löst Auto-Fork
|
||||
/// serverseitig aus und navigiert anschließend zur eigenen Deck-Detail.
|
||||
struct PublicDeckView: View {
|
||||
let slug: String
|
||||
|
||||
@Environment(AuthClient.self) private var auth
|
||||
@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?
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
CardsTheme.background.ignoresSafeArea()
|
||||
content
|
||||
}
|
||||
.navigationTitle(detail?.deck.title ?? "Deck")
|
||||
#if os(iOS)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
#endif
|
||||
.task(id: slug) {
|
||||
await load()
|
||||
}
|
||||
}
|
||||
|
||||
@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)
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
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 {
|
||||
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 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue