Deck version update

This commit is contained in:
gitea
2026-02-14 10:59:22 +01:00
parent 32c786fa24
commit 6009ce5ec2
14 changed files with 1008 additions and 143 deletions
+37 -15
View File
@@ -1,9 +1,13 @@
<script>
import { onMount } from 'svelte';
import { push } from 'svelte-spa-router';
import { auth } from '../lib/stores/auth.js';
import { navContext } from '../lib/stores/navContext.js';
import { fetchPublishedDecksByOwner, copyDeckToUser, getMyDeckRating, submitDeckRating } from '../lib/api/decks.js';
import RatingModal from '../lib/RatingModal.svelte';
onMount(() => navContext.set('community'));
export let params = {};
let decks = [];
@@ -123,6 +127,7 @@
<ul class="deck-grid">
{#each decks as deck (deck.id)}
<li class="deck-card">
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
<div class="deck-card-inner" role="button" tabindex="0" onclick={() => goPreview(deck.id)} onkeydown={(e) => e.key === 'Enter' && goPreview(deck.id)}>
<h3 class="deck-title">{deck.title}</h3>
{#if deck.description}
@@ -131,21 +136,29 @@
<div class="deck-meta">
<span class="deck-count">{deck.question_count ?? 0} questions</span>
</div>
<div
class="deck-rating"
class:clickable={userId && deck.owner_id !== userId}
aria-label="Rating: {deck.average_rating ?? 0} out of 5 stars"
onclick={userId && deck.owner_id !== userId ? (e) => openRatingModal(deck, e) : undefined}
role={userId && deck.owner_id !== userId ? 'button' : undefined}
tabindex={userId && deck.owner_id !== userId ? 0 : undefined}
onkeydown={userId && deck.owner_id !== userId ? (e) => e.key === 'Enter' && openRatingModal(deck, e) : undefined}
>
<span class="stars">{['★', '★', '★', '★', '★'].map((_, i) => (i < Math.round(deck.average_rating ?? 0) ? '★' : '☆')).join('')}</span>
<span class="rating-text">{formatRating(deck.average_rating ?? 0)}</span>
{#if (deck.rating_count ?? 0) > 0}
<span class="rating-count">({deck.rating_count})</span>
{/if}
</div>
{#if userId && deck.owner_id !== userId}
<button
type="button"
class="deck-rating clickable"
aria-label="Rating: {deck.average_rating ?? 0} out of 5 stars"
onclick={(e) => openRatingModal(deck, e)}
onkeydown={(e) => e.key === 'Enter' && openRatingModal(deck, e)}
>
<span class="stars">{['★', '★', '★', '★', '★'].map((_, i) => (i < Math.round(deck.average_rating ?? 0) ? '★' : '☆')).join('')}</span>
<span class="rating-text">{formatRating(deck.average_rating ?? 0)}</span>
{#if (deck.rating_count ?? 0) > 0}
<span class="rating-count">({deck.rating_count})</span>
{/if}
</button>
{:else}
<div class="deck-rating" aria-label="Rating: {deck.average_rating ?? 0} out of 5 stars">
<span class="stars">{['★', '★', '★', '★', '★'].map((_, i) => (i < Math.round(deck.average_rating ?? 0) ? '★' : '☆')).join('')}</span>
<span class="rating-text">{formatRating(deck.average_rating ?? 0)}</span>
{#if (deck.rating_count ?? 0) > 0}
<span class="rating-count">({deck.rating_count})</span>
{/if}
</div>
{/if}
<div class="deck-card-actions">
{#if !deck.user_has_this}
<button type="button" class="btn btn-small btn-primary" onclick={(e) => { e.stopPropagation(); handleUse(deck.id); }} disabled={addingDeckId === deck.id}>
@@ -291,6 +304,15 @@
font-size: 0.9rem;
color: var(--text-muted, #a0a0a0);
margin-bottom: 0.25rem;
border: none;
background: transparent;
padding: 0;
font: inherit;
text-align: left;
}
button.deck-rating {
cursor: pointer;
}
.deck-rating.clickable {