|
| 1 | +<script> |
| 2 | + import { page } from "$app/stores"; |
| 3 | + import Chord from "$lib/Chord.svelte"; |
| 4 | + import { getChordVariations } from "$frets/chordFingerings.js"; |
| 5 | + import { tunings } from "$lib"; |
| 6 | +
|
| 7 | + let { data } = $props(); |
| 8 | +
|
| 9 | + // Read state from URL params with defaults |
| 10 | + let tuning = $state($page.url.searchParams.get("tuning") || "Standard"); |
| 11 | + let positionParam = $page.url.searchParams.get("position"); |
| 12 | + let position = $state(positionParam ? parseInt(positionParam) : 0); |
| 13 | +
|
| 14 | + const chordName = $derived(data.chordName); |
| 15 | + const tuningObj = $derived(tunings.get(tuning)); |
| 16 | + const variations = $derived(getChordVariations(chordName, tuningObj)); |
| 17 | +
|
| 18 | + $effect(() => { |
| 19 | + console.log("Chord page:", { |
| 20 | + chordName, |
| 21 | + tuning, |
| 22 | + position, |
| 23 | + variations, |
| 24 | + }); |
| 25 | + }); |
| 26 | +</script> |
| 27 | + |
| 28 | +<svelte:head> |
| 29 | + <title>{chordName} Chord</title> |
| 30 | + <meta name="Description" content="{chordName} chord variations for guitar" /> |
| 31 | +</svelte:head> |
| 32 | + |
| 33 | +<div class="container mx-auto p-8"> |
| 34 | + <div class="mb-8"> |
| 35 | + <h1 class="text-4xl font-bold mb-2 dark:text-gray-100">{chordName}</h1> |
| 36 | + <p class="text-gray-600 dark:text-gray-400"> |
| 37 | + {variations.positions.length} position{variations.positions.length !== 1 |
| 38 | + ? "s" |
| 39 | + : ""} available |
| 40 | + </p> |
| 41 | + </div> |
| 42 | + |
| 43 | + {#if variations.positions.length > 0} |
| 44 | + <div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-6"> |
| 45 | + {#each variations.positions as _, idx} |
| 46 | + <div |
| 47 | + class="relative bg-gray-50 border border-gray-200 hover:bg-gray-100 hover:border-gray-300 transition-all dark:bg-blue-900/20 dark:border dark:border-blue-900/50 dark:hover:bg-blue-900/40 dark:hover:border-blue-500/50 rounded-lg p-4"> |
| 48 | + <div class="absolute top-2 right-2 text-xs text-blue-500"> |
| 49 | + Position {idx + 1} |
| 50 | + </div> |
| 51 | + <Chord {chordName} position={idx} tuning={tuningObj} /> |
| 52 | + </div> |
| 53 | + {/each} |
| 54 | + </div> |
| 55 | + {:else} |
| 56 | + <div |
| 57 | + class="bg-yellow-50 border border-yellow-200 rounded-lg p-6 dark:bg-yellow-900/20 dark:border-yellow-800"> |
| 58 | + <p class="text-yellow-800 dark:text-yellow-200"> |
| 59 | + No chord variations found for {chordName}. Try a different chord name. |
| 60 | + </p> |
| 61 | + </div> |
| 62 | + {/if} |
| 63 | +</div> |
0 commit comments