Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions docs/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ and ramps difficulty over time.
on top to 6th (low E) on bottom. Nut is drawn on the right edge. Each scale note shows
a circular dot with its note name; the root (degree 1) uses amber (primary) fill.
Out-of-scale cells render blank.
- Left-handed mode: mirrors the fretboard on the x-axis (nut on the left edge, fret numbers increase right-to-left). String labels are on the right side instead of the left. Toggled from the Scales section; persisted in localStorage.
- Left-handed mode: mirrors the fretboard on the x-axis (nut on the left edge, fret numbers increase right-to-left). String labels are on the right side instead of the left. Toggled from the Settings dialog; persisted in localStorage.
- Open in-scale notes render as small dots without any finger or degree label. When
`startFret=0` the open-string column is not shown on the board.
- Scales: provides pentatonic (major & minor), major, natural minor, and blues. Each is
Expand All @@ -24,10 +24,19 @@ and ramps difficulty over time.
- Difficulty: a level (1..N). Higher levels raise the metronome BPM and widen the scale
position (more frets spanned). The user can level up when they can hold the current
tempo for the whole session.
- Settings modal (keeb-style): a `<dialog>` opened from a Settings button in the header bar.
Two-column panel (label left, control right). Persistent settings: level (select),
left-handed toggle (checkbox), and daily goal in minutes (number input). Changes persist
to localStorage.
- All state (goal, level, last session) is stored in the browser (localStorage); no backend.

## Design
- Flat design: no border boxes on sections; sections are separated by the page grid gap only.
- Fretboard grid lines come from the container background + 1px gap, not cell borders.
- Settings uses a keeb-style `<dialog>` modal with `.modal-head` and a two-column `.panel` grid.

## Data
- Browser localStorage: daily goal minutes, difficulty level, last completed session time.
- Browser localStorage: daily goal minutes, difficulty level, left-handed flag, last completed session time.
- No server, no gateway. Works offline after first load (service worker precache).

## Not in scope
Expand Down
57 changes: 35 additions & 22 deletions e2e/fret.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ test("renders the app", async ({ page }) => {
test("set daily goal and see progress update", async ({ page }) => {
await page.goto("/");
await expect(page.locator("app-main")).toBeVisible();
// Find the goal input inside goal-ui and set a value
const goalInput = page.locator("goal-ui").locator('input[type="number"]');
// Open Settings dialog
await page.locator('button[aria-label="Settings"]').click();
// Fill the goal input inside the dialog
const goalInput = page.locator("dialog[aria-label=\"Settings\"]").locator('input[type="number"]').last();
await goalInput.fill("30");
// Click the refresh button to trigger the change event
await page.locator("goal-ui").locator('button.ghost').click();
// Now see the goal reflected in the progress text
await expect(page.locator("goal-ui").locator("span").first()).toContainText("30");
// Close dialog
await page.locator("dialog[aria-label=\"Settings\"]").locator("button.x").click();
// See the goal reflected in the practice progress text
await expect(page.locator("practice-ui")).toContainText("30 min");
});

test("render a fretboard with dots for the selected scale", async ({ page }) => {
Expand Down Expand Up @@ -48,20 +50,28 @@ test("scale-view shows positionWidth columns from difficulty level", async ({ pa
// Default level 1 has positionWidth=5
const fretboard = page.locator("scale-view").locator(".fretboard");
await expect(fretboard).toBeVisible();
// Count cells — should be positionWidth (5 for level 1) columns
const cells = fretboard.locator(".cell").first();
await expect(cells).toBeVisible();
// Open Settings dialog and change level
await page.locator('button[aria-label="Settings"]').click();
// Change to level 2 (positionWidth=6)
await page.locator("#level-select").selectOption("2");
const select = page.locator("dialog[aria-label=\"Settings\"]").locator("select");
await select.selectOption("2");
// Close dialog
await page.locator("dialog[aria-label=\"Settings\"]").locator("button.x").click();
await expect(fretboard.locator(".cell")).toHaveCount(36);
// Change to level 3 (positionWidth=6)
await page.locator("#level-select").selectOption("3");
// Open again for level 3
await page.locator('button[aria-label="Settings"]').click();
await select.selectOption("3");
await page.locator("dialog[aria-label=\"Settings\"]").locator("button.x").click();
await expect(fretboard.locator(".cell")).toHaveCount(36);
// Change to level 4 (positionWidth=7)
await page.locator("#level-select").selectOption("4");
// Level 4 (positionWidth=7)
await page.locator('button[aria-label="Settings"]').click();
await select.selectOption("4");
await page.locator("dialog[aria-label=\"Settings\"]").locator("button.x").click();
await expect(fretboard.locator(".cell")).toHaveCount(42);
// Change to level 6 (positionWidth=8)
await page.locator("#level-select").selectOption("6");
// Level 6 (positionWidth=8)
await page.locator('button[aria-label="Settings"]').click();
await select.selectOption("6");
await page.locator("dialog[aria-label=\"Settings\"]").locator("button.x").click();
await expect(fretboard.locator(".cell")).toHaveCount(48);
});

Expand All @@ -85,22 +95,25 @@ test("left-handed mode mirrors fretboard", async ({ page }) => {
await page.evaluate(() => localStorage.removeItem("fret:leftHanded"));
// Default: first fret-num should be "1"
await expect(page.locator("scale-view").locator(".fret-num").first()).toHaveText("1");
// Toggle left-handed checkbox
await page.locator("scale-view").locator("label:has-text('Left-handed') input[type='checkbox']").check({ force: true });
// Open Settings dialog and toggle left-handed
await page.locator('button[aria-label="Settings"]').click();
// Checkbox is hidden behind the toggle switch; set via evaluate to fire the change handler.
await page.locator("dialog[aria-label=\"Settings\"]").locator('input[type="checkbox"]').evaluate((el) => {
(el as HTMLInputElement).checked = true;
el.dispatchEvent(new Event('change', { bubbles: true }));
});
// Close dialog
await page.locator("dialog[aria-label=\"Settings\"]").locator("button.x").click();
// Now the board should mirror: fret-num order reversed
// First fret-num header should now show the highest fret in the window
const firstFretNum = await page.locator("scale-view").locator(".fret-num").first().textContent();
// With 5 frets and startFret=0, normal order is 1-5, reversed is 5-1
expect(firstFretNum).toBe("5");
// String labels column should be on the right in left-handed mode
// Verify: every row has a .string-label AFTER its cells in DOM order
const labelPositions = await page.locator("scale-view").locator(".string-label").all();
expect(labelPositions.length).toBe(6);
// String labels should NOT reverse: 1st appears first, 6th last
await expect(page.locator("scale-view").locator(".string-label").first()).toContainText("1st");
await expect(page.locator("scale-view").locator(".string-label").last()).toContainText("6th");
// Cell order should also be reversed
const cellTitle = await page.locator("scale-view").locator(".cell").first().getAttribute("title");
// First cell should be in the 6th string (low E) at the highest fret
expect(cellTitle).toContain("fret 5");
});
170 changes: 129 additions & 41 deletions src/app-main.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import "./ui/scale-view.js";
import "./ui/difficulty.js";
import "./ui/metronome.js";
import "./ui/practice.js";
import "./ui/goal.js";
import { LitElement, html, css } from "https://kit.thatsit.app/lit.js";
import { LitElement, html, css, nothing } from "https://kit.thatsit.app/lit.js";
import { sharedStyles, toast } from "https://kit.thatsit.app/kit.js";
import { DIFFICULTY_LEVELS } from "../src/difficulty.js";
import { getGoalMinutes, getTodayMs } from "../src/goals.js";
import { getGoalMinutes, getTodayMs, setGoalMinutes } from "../src/goals.js";
import { settingsDialog, settingsDialogStyles, showDialog } from "./ui/settings-dialog.js";

export class AppMain extends LitElement {
static properties = {
_level: { type: Number },
_settingsOpen: { type: Boolean },
_leftHanded: { type: Boolean },
_goalMin: { type: Number },
};

static styles = [
settingsDialogStyles,
sharedStyles,
css`
.page {
Expand All @@ -23,54 +26,125 @@ export class AppMain extends LitElement {
display: grid;
gap: 20px;
}
@media (max-width: 600px) {
.page {
padding: 12px;
gap: 14px;
}
}
.title-row {
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
gap: 8px;
}
h1 {
font-size: 22px;
margin: 0 0 4px;
margin: 0;
}
.section {
padding: 16px;
border: 1px solid var(--border-color);
border-radius: var(--radius);
}
.icon-btn {
background: none;
border: 0;
padding: 0;
cursor: pointer;
display: grid;
place-items: center;
color: var(--text-muted);
}
.icon-btn:hover { color: var(--text-primary); }
.section h2 {
margin: 0 0 12px;
font-size: 16px;
}
.row {
/* Dialog modal styles */
dialog {
border: 1px solid var(--border-color);
border-radius: calc(var(--radius) * 2);
background: var(--bg);
color: var(--text-primary);
padding: 0;
box-shadow: 0 18px 50px var(--shadow-color);
width: min(24rem, calc(100vw - 2rem));
}
dialog::backdrop {
background: color-mix(in srgb, var(--text-primary), transparent 62%);
backdrop-filter: blur(3px);
}
.modal-head {
display: flex;
gap: 10px;
align-items: center;
flex-wrap: wrap;
justify-content: space-between;
padding: 12px 14px;
border-bottom: 1px solid var(--border-color);
}
.x {
display: grid;
place-items: center;
width: 36px;
height: 36px;
flex: none;
border: 0;
background: none;
border-radius: var(--radius);
color: var(--text-muted);
}
.x:hover {
color: var(--text-primary);
background: var(--code-bg);
}
.panel {
display: grid;
grid-template-columns: auto 1fr;
gap: 14px 16px;
align-items: center;
padding: 16px 14px;
}
.panel label {
display: contents;
}
.panel label > .label {
justify-self: start;
}
.panel label > select,
.panel label > input {
justify-self: end;
width: 100%;
max-width: 12rem;
}
.full {
grid-column: 1 / -1;
}
`,
];

_level = parseInt(localStorage.getItem("fret:level") ?? "1", 10);
_leftHanded = localStorage.getItem("fret:leftHanded") === "true";
_settingsOpen = false;
_goalMin = getGoalMinutes();

render() {
const goalMin = getGoalMinutes();
const todayMs = getTodayMs();
const levelConfig = DIFFICULTY_LEVELS.find((d) => d.level === this._level);
const positionWidth = levelConfig?.positionWidth ?? 5;
return html`
<div class="page">
<h1>Fret</h1>

<div class="section">
<h2>Scales</h2>
<scale-view .positionWidth=${positionWidth}></scale-view>
<div class="title-row">
<h1>Fret</h1>
<button class="icon-btn" aria-label="Settings" aria-haspopup="dialog" @click=${() => this._toggleSettings(true)}>
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915"/>
<circle cx="12" cy="12" r="3"/>
</svg>
</button>
</div>

<div class="section">
<h2>Difficulty</h2>
<div class="row">
<label>
Level
<select id="level-select" .value=${this._level} @change=${this._onLevelChange}>
${DIFFICULTY_LEVELS.map((d) => html`<option value="${d.level}">${d.name} (${d.bpm} bpm, position ${d.positionWidth})</option>`)}
</select>
</label>
</div>
<h2>Scales</h2>
<scale-view .positionWidth=${positionWidth} .leftHanded=${this._leftHanded}></scale-view>
</div>

<div class="section">
Expand All @@ -80,30 +154,44 @@ export class AppMain extends LitElement {

<div class="section">
<h2>Practice</h2>
<practice-ui id="practice"></practice-ui>
<practice-ui id="practice" .goalMin=${this._goalMin} .todayMs=${todayMs}></practice-ui>
</div>

<div class="section">
<h2>Goal</h2>
<goal-ui id="goal" .goalMin=${goalMin} .todayMs=${todayMs}></goal-ui>
</div>
${this._settingsOpen ? settingsDialog({
level: this._level,
leftHanded: this._leftHanded,
goalMin: this._goalMin,
onLevel: (level: number) => { localStorage.setItem("fret:level", String(level)); this._level = level; const c = DIFFICULTY_LEVELS.find((d) => d.level === level); if (c) { const m = this.shadowRoot?.querySelector("metronome-ui"); if (m && "bpm" in m) (m as HTMLElement & { bpm: number }).bpm = c.bpm; toast(`${c.name} — ${c.bpm} BPM`); } },
onLeftHanded: (lh) => this._onLeftHandedChange(lh),
onGoal: (gm: number) => { this._onGoalChange(gm); },
onClose: (open) => this._settingsOpen = open,
}) : nothing}
</div>
`;
}

_onLevelChange(e: Event): void {
const level = parseInt((e.target as HTMLSelectElement).value, 10);
localStorage.setItem("fret:level", String(level));
this._level = level;
const levelConfig = DIFFICULTY_LEVELS.find((d) => d.level === level);
if (levelConfig) {
const metro = this.shadowRoot?.querySelector("metronome-ui");
if (metro && "bpm" in metro) {
(metro as HTMLElement & { bpm: number }).bpm = levelConfig.bpm;
}
toast(`${levelConfig.name} — ${levelConfig.bpm} BPM`);
_toggleSettings(open: boolean): void {
this._settingsOpen = open;
}

_onLeftHandedChange(leftHanded: boolean): void {
localStorage.setItem("fret:leftHanded", String(leftHanded));
this._leftHanded = leftHanded;
toast(`Left-handed mode ${leftHanded ? "on" : "off"}`);
}

_onGoalChange(goalMin: number): void {
setGoalMinutes(goalMin);
this._goalMin = goalMin;
toast(`Daily goal set to ${goalMin} min`);
}

updated(changed: Map<string, unknown>): void {
if (changed.has("_settingsOpen")) {
showDialog(this.renderRoot, this._settingsOpen);
}
}

}

customElements.define("app-main", AppMain);
Loading
Loading