Skip to content

Commit ef01e91

Browse files
committed
add alt position chords
1 parent f052ad6 commit ef01e91

4 files changed

Lines changed: 77 additions & 5 deletions

File tree

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@
9494
bind:clientHeight={height}
9595
bind:this={el}
9696
data-chord={chordName}
97-
href="#"
98-
title="Chord diagram for {chordName}"
97+
href="/chords/{chordName}"
98+
title="View all positions for {chordName}"
9999
class="w-full h-full flex">
100100
</a>
101101
<div class="flex w-full justify-center items-center py-2">
102102
<button
103-
class="flex justify-center items-center gap-1 w-full h-fit p-1 mx-5 text-xs cursor-pointer border border-gray-500 bg-gray-200 rounded-full hover:text-white hover:bg-green-600 hover:border-green-800"
103+
class="flex justify-center items-center gap-1 w-full h-fit p-1 mx-5 text-xs cursor-pointer border border-gray-500 bg-gray-200 rounded-full dark:bg-blue-500 dark:border-blue-400 dark:text-white hover:text-white hover:bg-green-600 hover:border-green-800"
104104
aria-label="Play {chordName} chord at position {position}"
105105
onclick={playChord}>
106106
<div class="font-medium">{chordName}</div>
@@ -110,8 +110,9 @@
110110
</div>
111111
112112
<style>
113+
@reference "tailwindcss";
113114
:global(.barre-rectangle) {
114-
@apply fill-[#333] dark:fill-[#e5e7eb];
115+
@apply fill-[#333] dark:fill-blue-400/50;
115116
}
116117
117118
:global(.tuning) {

src/lib/ScaleChords.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script>
22
import { Mode } from "tonal";
3-
import Chord from "$frets/Chord.svelte";
3+
import Chord from "$lib/Chord.svelte";
44
55
let { scale } = $props();
66

src/routes/chords/[chord]/+page.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export function load({ params }) {
2+
// Use chord name directly from URL (e.g., "Cm", "CM7", "Ddim")
3+
const chordName = params.chord;
4+
5+
return {
6+
chordName
7+
};
8+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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

Comments
 (0)