Skip to content

Commit be067a3

Browse files
author
Salma Alam-Naylor
committed
Scroll to top of mode selector when clicking on a similar mode chip
1 parent 716a355 commit be067a3

File tree

11 files changed

+69
-29
lines changed

11 files changed

+69
-29
lines changed

apps/fretonator-web/src/app/common/chips/chip/chip.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<a
22
[routerLink]="['/', note, noteExtender, mode]"
33
[attr.aria-label]="note | createChipLinkTitle: noteExtender: mode"
4+
(click)="onClick($event)"
45
class="chip"
56
[class.chip--active]="selected"
67
[class.chip--round]="rounded"

apps/fretonator-web/src/app/common/chips/chip/chip.component.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, DoCheck, Input } from '@angular/core';
1+
import { Component, DoCheck, EventEmitter, Input, Output } from '@angular/core';
22
import { Mode } from '../../../util/types';
33
import { ActivatedRoute } from '@angular/router';
44

@@ -19,6 +19,7 @@ export class ChipComponent implements DoCheck {
1919
@Input() selectedColor: SelectedColor = SelectedColor.default;
2020
@Input() rounded = false;
2121
@Input() isBaseNote = false;
22+
@Output() chipClick = new EventEmitter<MouseEvent>();
2223
SelectedColor = SelectedColor;
2324
selected = false;
2425

@@ -48,4 +49,8 @@ export class ChipComponent implements DoCheck {
4849

4950
return true;
5051
}
52+
53+
onClick(event: MouseEvent) {
54+
this.chipClick.emit(event);
55+
}
5156
}

apps/fretonator-web/src/app/common/fretonator/fretonator.component.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ <h4 class="fretonator__playCta">
8989
<app-similar-modes [modeDisplayString]="modeDisplayString"
9090
[similarModes]="modeMap | getSimilarModes : mode"
9191
[isTheoretical]="modeMap | isTheoreticalScale">
92-
9392
</app-similar-modes>
9493

9594
</div>

apps/fretonator-web/src/app/common/fretonator/fretonator.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export class FretonatorComponent {
3333
fretMode = FretMode.twelve;
3434
frets = FretReturner[this.fretMode];
3535

36-
3736
get fretModes() {
3837
return FretMode;
3938
}

apps/fretonator-web/src/app/common/fretonator/similar-modes/similar-modes.component.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ <h4 class="similarModes__title">Did you know?</h4>
99
[note]="mode.note"
1010
[noteExtender]="mode.noteExtender"
1111
[mode]="mode.mode"
12-
selectedColor="default">{{mode.noteDisplayName}} {{mode.mode | titlecase}}</app-chip>
12+
(chipClick)="onModeChange()">{{mode.noteDisplayName}} {{mode.mode | titlecase}}</app-chip>
1313
</app-chips>
1414
</div>
1515

1616
<p class="similarModes__copy">There are only 7 patterns you need to learn. Once you've memorised those patterns,
17-
you can play any of the 7 standard modes <em>(Ionian, Dorian, Phrygian, Lydian, Mixolydian, Aolian, Locrian</em>) from
17+
you can play any of the 7 standard modes <em>(Ionian, Dorian, Phrygian, Lydian, Mixolydian, Aolian, Locrian</em>)
18+
from
1819
any starting note, anywhere on the fretboard.</p>
1920
<p class="similarModes__copy">These patterns always appear in the same order, one after the other.</p>
2021
</div>

apps/fretonator-web/src/app/common/fretonator/similar-modes/similar-modes.component.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { Component, Input } from '@angular/core';
1+
import { Component, ElementRef, Input } from '@angular/core';
22
import { SimilarModes } from '../../../util/types';
3+
import { GlobalService } from '../../../global.service';
34

45
@Component({
56
selector: 'app-similar-modes',
@@ -10,4 +11,10 @@ export class SimilarModesComponent {
1011
@Input() similarModes: SimilarModes;
1112
@Input() modeDisplayString: string;
1213
@Input() isTheoretical: boolean;
14+
15+
constructor(private globalService: GlobalService){}
16+
17+
onModeChange() {
18+
this.globalService.getScrollTarget().scrollIntoView();
19+
}
1320
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { TestBed } from '@angular/core/testing';
2+
3+
import { GlobalService } from './global.service';
4+
5+
describe('GlobalService', () => {
6+
let service: GlobalService;
7+
8+
beforeEach(() => {
9+
TestBed.configureTestingModule({});
10+
service = TestBed.inject(GlobalService);
11+
});
12+
13+
it('should be created', () => {
14+
expect(service).toBeTruthy();
15+
});
16+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Injectable } from '@angular/core';
2+
3+
@Injectable({
4+
providedIn: 'root'
5+
})
6+
export class GlobalService {
7+
8+
private scrollTarget: HTMLElement;
9+
10+
getScrollTarget(): HTMLElement {
11+
return this.scrollTarget;
12+
}
13+
14+
setScrollTarget(el: HTMLElement) {
15+
this.scrollTarget = el;
16+
}
17+
}

apps/fretonator-web/src/app/pages/home/home-index/__snapshots__/home-index.component.spec.ts.snap

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,9 +1417,7 @@ exports[`HomeIndexComponent should create 1`] = `
14171417
class="chips"
14181418
>
14191419
1420-
<app-chip
1421-
selectedcolor="default"
1422-
>
1420+
<app-chip>
14231421
<a
14241422
aria-label="D Dorian"
14251423
class="chip"
@@ -1428,9 +1426,7 @@ exports[`HomeIndexComponent should create 1`] = `
14281426
D Dorian
14291427
</a>
14301428
</app-chip>
1431-
<app-chip
1432-
selectedcolor="default"
1433-
>
1429+
<app-chip>
14341430
<a
14351431
aria-label="E Phrygian"
14361432
class="chip"
@@ -1439,9 +1435,7 @@ exports[`HomeIndexComponent should create 1`] = `
14391435
E Phrygian
14401436
</a>
14411437
</app-chip>
1442-
<app-chip
1443-
selectedcolor="default"
1444-
>
1438+
<app-chip>
14451439
<a
14461440
aria-label="F Lydian"
14471441
class="chip"
@@ -1450,9 +1444,7 @@ exports[`HomeIndexComponent should create 1`] = `
14501444
F Lydian
14511445
</a>
14521446
</app-chip>
1453-
<app-chip
1454-
selectedcolor="default"
1455-
>
1447+
<app-chip>
14561448
<a
14571449
aria-label="G Mixolydian"
14581450
class="chip"
@@ -1461,9 +1453,7 @@ exports[`HomeIndexComponent should create 1`] = `
14611453
G Mixolydian
14621454
</a>
14631455
</app-chip>
1464-
<app-chip
1465-
selectedcolor="default"
1466-
>
1456+
<app-chip>
14671457
<a
14681458
aria-label="A Aolian (Minor)"
14691459
class="chip"
@@ -1472,9 +1462,7 @@ exports[`HomeIndexComponent should create 1`] = `
14721462
A Aolian
14731463
</a>
14741464
</app-chip>
1475-
<app-chip
1476-
selectedcolor="default"
1477-
>
1465+
<app-chip>
14781466
<a
14791467
aria-label="B Locrian"
14801468
class="chip"

apps/fretonator-web/src/app/pages/home/home-index/home-index.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ <h1 class="hero__title">
2929

3030
<div class="modeSelector__container">
3131
<div class="modeSelector__chipsContainer">
32-
<h2 class="modeSelector__label">Starting note</h2>
32+
<h2 class="modeSelector__label" #scrollTarget>Starting note</h2>
3333

3434
<app-chips>
3535
<app-chip *ngFor="let thisNote of octave"

0 commit comments

Comments
 (0)