kjdskjdsk
This commit is contained in:
@@ -6,8 +6,10 @@ import {
|
||||
deleteDeck,
|
||||
exportDeckText,
|
||||
loadDecks,
|
||||
loadSharedDeck,
|
||||
newDeckId,
|
||||
saveDeck,
|
||||
shareDeck,
|
||||
type ApiCard,
|
||||
type DeckCard,
|
||||
type SavedDeck,
|
||||
@@ -26,6 +28,8 @@ interface DraftDeck {
|
||||
definePageMeta({ middleware: 'auth' })
|
||||
|
||||
const { public: { apiBase } } = useRuntimeConfig()
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const BASIC_NAMES = ['Plains', 'Island', 'Swamp', 'Mountain', 'Forest']
|
||||
|
||||
const decks = ref<SavedDeck[]>([])
|
||||
@@ -43,6 +47,8 @@ const importErrors = ref<string[]>([])
|
||||
const importing = ref(false)
|
||||
const basics = ref<Record<string, ApiCard>>({})
|
||||
const showExport = ref(false)
|
||||
const shareLink = ref('')
|
||||
const shareCopied = ref(false)
|
||||
|
||||
const count = computed(() => 1 + (draft.value?.cards.length ?? 0))
|
||||
const grouped = computed(() => {
|
||||
@@ -115,6 +121,30 @@ async function reloadDecks() {
|
||||
decks.value = (await loadDecks(apiBase)).sort((a, b) => b.updatedAt - a.updatedAt)
|
||||
}
|
||||
|
||||
async function share(deck: SavedDeck) {
|
||||
error.value = ''
|
||||
try {
|
||||
const token = await shareDeck(apiBase, deck.id)
|
||||
shareLink.value = `${window.location.origin}/decks?share=${token}`
|
||||
shareCopied.value = false
|
||||
} catch (caught) {
|
||||
error.value = errorMessage(caught)
|
||||
}
|
||||
}
|
||||
|
||||
async function copyShareLink() {
|
||||
try {
|
||||
await navigator.clipboard.writeText(shareLink.value)
|
||||
shareCopied.value = true
|
||||
} catch {
|
||||
shareCopied.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function closeShare() {
|
||||
shareLink.value = ''
|
||||
}
|
||||
|
||||
function selectDeck(deck: SavedDeck) {
|
||||
draft.value = {
|
||||
id: deck.id,
|
||||
@@ -314,6 +344,27 @@ function errorMessage(caught: unknown): string {
|
||||
onMounted(async () => {
|
||||
await reloadDecks()
|
||||
|
||||
const sharedToken = route.query.share
|
||||
if (typeof sharedToken === 'string' && sharedToken) {
|
||||
try {
|
||||
const deck = await loadSharedDeck(apiBase, sharedToken)
|
||||
draft.value = {
|
||||
id: newDeckId(),
|
||||
name: deck.name,
|
||||
commander: { ...deck.commander },
|
||||
cards: deck.cards.map(card => ({ ...card })),
|
||||
cardBack: deck.cardBack ?? undefined,
|
||||
}
|
||||
notice.value = 'Shared deck loaded. Save it to add it to your account.'
|
||||
} catch (caught) {
|
||||
error.value = errorMessage(caught)
|
||||
}
|
||||
// Drop the token from the URL so a reload does not import the deck again.
|
||||
const query = { ...route.query }
|
||||
delete query.share
|
||||
await router.replace({ query })
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await $fetch<{ cards: (ApiCard | null)[] }>(`${apiBase}/cards/resolve`, {
|
||||
method: 'POST',
|
||||
@@ -519,33 +570,50 @@ onMounted(async () => {
|
||||
</header>
|
||||
|
||||
<section class="decks-panel">
|
||||
<p v-if="error" class="error">{{ error }}</p>
|
||||
<p v-if="!decks.length" class="muted">No saved decks yet.</p>
|
||||
<div class="deck-grid">
|
||||
<button type="button" class="deck-tile import-tile" @click="openImport">
|
||||
<span class="plus" aria-hidden="true">+</span>
|
||||
<span class="deck-name">Import deck</span>
|
||||
</button>
|
||||
<button
|
||||
v-for="deck in decks"
|
||||
:key="deck.id"
|
||||
type="button"
|
||||
class="deck-tile"
|
||||
@click="selectDeck(deck)"
|
||||
>
|
||||
<span class="deck-stack">
|
||||
<img :src="commanderImage(deck)" :alt="`${deck.commander.name} card`" loading="lazy">
|
||||
</span>
|
||||
<span class="deck-name">{{ deck.name }}</span>
|
||||
<span class="deck-meta">
|
||||
<span class="tag" :class="deck.cards.length + 1 === 100 ? 'good' : 'bad'">
|
||||
{{ deck.cards.length + 1 }}/100
|
||||
<div v-for="deck in decks" :key="deck.id" class="deck-cell">
|
||||
<button type="button" class="deck-tile" @click="selectDeck(deck)">
|
||||
<span class="deck-stack">
|
||||
<img :src="commanderImage(deck)" :alt="`${deck.commander.name} card`" loading="lazy">
|
||||
</span>
|
||||
<span class="muted deck-commander">{{ deck.commander.name }}</span>
|
||||
</span>
|
||||
</button>
|
||||
<span class="deck-name">{{ deck.name }}</span>
|
||||
<span class="deck-meta">
|
||||
<span class="tag" :class="deck.cards.length + 1 === 100 ? 'good' : 'bad'">
|
||||
{{ deck.cards.length + 1 }}/100
|
||||
</span>
|
||||
<span class="muted deck-commander">{{ deck.commander.name }}</span>
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="mini share-button"
|
||||
:aria-label="`Share ${deck.name}`"
|
||||
@click="share(deck)"
|
||||
>Share</button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div v-if="shareLink" class="modal-backdrop" @click.self="closeShare">
|
||||
<div class="modal">
|
||||
<h2>Share deck</h2>
|
||||
<p class="muted">Anyone with this link can view and import a copy of the deck.</p>
|
||||
<input :value="shareLink" readonly aria-label="Share link">
|
||||
<div class="row wrap modal-actions">
|
||||
<button type="button" @click="closeShare">Done</button>
|
||||
<button type="button" class="primary" @click="copyShareLink">
|
||||
{{ shareCopied ? 'Copied' : 'Copy link' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="importOpen" class="modal-backdrop" @click.self="closeImport">
|
||||
<form class="modal" @submit.prevent="importDeck">
|
||||
<h2>Import deck</h2>
|
||||
@@ -609,6 +677,21 @@ onMounted(async () => {
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.deck-cell {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.4rem;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.deck-cell .deck-tile {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.share-button {
|
||||
align-self: flex-end;
|
||||
}
|
||||
|
||||
.deck-tile {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
Reference in New Issue
Block a user