Skip to content

Commit f57bd68

Browse files
author
Salma Alam-Naylor
committed
Store fretboard configuration in local storage
1 parent 9c88459 commit f57bd68

File tree

5 files changed

+114
-13
lines changed

5 files changed

+114
-13
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@
3232
</button>
3333
<button class="fretboard__toggleButton fretboard__toggleButton--middle-right"
3434
[class.fretboard__toggleButton--active]="orientation === orientations.left"
35-
(click)="setOrientation(orientations.left)">Left handed
35+
(click)="setOrientation(orientations.left)">
36+
<span class="toggle__shortLabel">LH</span>
37+
<span class="toggle__longLabel">Left handed</span>
3638
</button>
3739
<button class="fretboard__toggleButton fretboard__toggleButton--right"
3840
[class.fretboard__toggleButton--active]="orientation === orientations.right"
39-
(click)="setOrientation(orientations.right)">Right handed
41+
(click)="setOrientation(orientations.right)">
42+
<span class="toggle__shortLabel">RH</span>
43+
<span class="toggle__longLabel">Right handed</span>
4044
</button>
4145
</div>
4246

apps/fretonator-web/src/app/common/fretonator/fretboard/fretboard.component.scss

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,26 @@
451451
height: pxToRem(44);
452452
}
453453

454+
.toggle__shortLabel {
455+
display: inline;
456+
font-weight: inherit;
457+
padding-left: pxToRem($grid_unit * 1.5);
458+
padding-right: pxToRem($grid_unit * 1.5);
459+
460+
@media screen and (min-width: $screen-med) {
461+
display: none;
462+
}
463+
}
464+
465+
.toggle__longLabel {
466+
display: none;
467+
font-weight: inherit;
468+
469+
@media screen and (min-width: $screen-med) {
470+
display: inline;
471+
}
472+
}
473+
454474
.fretboard__toggleButton--active {
455475
background-color: var(--black);
456476
color: var(--offwhite);

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import { By } from '@angular/platform-browser';
88
describe('FretboardComponent', () => {
99
const selectors = {
1010
twelveButton: By.css('.fretboard__toggleButton--left'),
11-
twentyFourButton: By.css('.fretboard__toggleButton--middle-left')
11+
twentyFourButton: By.css('.fretboard__toggleButton--middle-left'),
12+
rightButton: By.css('.fretboard__toggleButton--right'),
13+
leftButton: By.css('.fretboard__toggleButton--middle-right')
1214
};
1315

1416
const classNames = {
@@ -68,4 +70,26 @@ describe('FretboardComponent', () => {
6870
expect(twelveButton.classes[classNames.toggleFretButtonSelected]).toBeTruthy();
6971
});
7072
});
73+
74+
describe('setOrientation()', () => {
75+
let leftButton: DebugElement;
76+
let rightButton: DebugElement;
77+
78+
beforeEach(() => {
79+
leftButton = fixture.debugElement.query(selectors.leftButton);
80+
rightButton = fixture.debugElement.query(selectors.rightButton);
81+
});
82+
83+
it('changes the fret mode to left orientation when the button is clicked', () => {
84+
leftButton.nativeElement.click();
85+
fixture.detectChanges();
86+
expect(leftButton.classes[classNames.toggleFretButtonSelected]).toBeTruthy();
87+
});
88+
89+
it('changes the fret mode to right orientation when the button is clicked', () => {
90+
rightButton.nativeElement.click();
91+
fixture.detectChanges();
92+
expect(rightButton.classes[classNames.toggleFretButtonSelected]).toBeTruthy();
93+
});
94+
})
7195
});

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

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {
1111
} from '@angular/core';
1212
import { FretMap, Mode } from '../../../util/types';
1313
import { NotePlaybackService } from '../../playback/note-playback.service';
14+
import { GlobalService } from '../../../global.service';
15+
import { AbstractDataService } from '../../abstract-data/abstract-data.service';
1416

1517
export enum FretMode {
1618
twelve = 'twelve',
@@ -24,29 +26,60 @@ export enum Orientation {
2426

2527
const FretReturner = {
2628
'twelve': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
27-
'twentyFour': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24],
29+
'twentyFour': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]
2830
};
2931

32+
const StorageKeys = {
33+
fretMode: 'fretonator_fretMode',
34+
orientation: 'fretonator_orientation'
35+
}
36+
3037
@Component({
3138
selector: 'app-fretboard',
3239
templateUrl: './fretboard.component.html',
3340
styleUrls: ['./fretboard.component.scss']
3441
})
35-
export class FretboardComponent implements OnChanges, AfterViewInit {
42+
export class FretboardComponent implements OnChanges, OnInit {
3643
@ViewChild('fretboardContainer') fretboardContainer: ElementRef<HTMLElement>;
37-
@Output() loadExpandedChange = new EventEmitter<Boolean>()
44+
@Output() loadExpandedChange = new EventEmitter<Boolean>();
3845
@Input() fretMap: FretMap;
3946
@Input() mode: Mode;
4047
@Input() stringNamesAreCaseSensitive = false;
4148
@Input() loadExpanded = false;
42-
orientation = Orientation.left; //CHANGE BACK
43-
fretMode = FretMode.twelve;
44-
frets = FretReturner[this.fretMode] ;
49+
orientation;
50+
fretMode;
51+
frets;
4552

46-
constructor(public playbackService: NotePlaybackService) {
53+
constructor(public playbackService: NotePlaybackService,
54+
private localStorage: AbstractDataService) {
4755
}
4856

49-
ngAfterViewInit() {
57+
ngOnInit() {
58+
const _fretMode = this.localStorage.getItem(StorageKeys.fretMode);
59+
switch (_fretMode) {
60+
case 'twelve':
61+
this.fretMode = FretMode.twelve;
62+
break;
63+
case 'twentyFour':
64+
this.fretMode = FretMode.twentyFour;
65+
break;
66+
default:
67+
this.fretMode = FretMode.twelve;
68+
}
69+
70+
const _orientation = this.localStorage.getItem(StorageKeys.orientation);
71+
switch (_orientation) {
72+
case 'right':
73+
this.orientation = Orientation.right;
74+
break;
75+
case 'left':
76+
this.orientation = Orientation.left;
77+
break;
78+
default:
79+
this.orientation = Orientation.right;
80+
}
81+
82+
this.configureFretboard();
5083
}
5184

5285

@@ -71,12 +104,14 @@ export class FretboardComponent implements OnChanges, AfterViewInit {
71104

72105
setOrientation(orientation: Orientation) {
73106
this.orientation = orientation;
107+
this.localStorage.setItem(StorageKeys.orientation, this.orientation);
74108

75109
this.configureFretboard();
76110
}
77111

78112
setFretMode(fretMode: FretMode) {
79113
this.fretMode = fretMode;
114+
this.localStorage.setItem(StorageKeys.fretMode, this.fretMode);
80115
this.configureFretboard();
81116
}
82117
}

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,12 +364,30 @@ exports[`HomeIndexComponent should create 1`] = `
364364
<button
365365
class="fretboard__toggleButton fretboard__toggleButton--middle-right"
366366
>
367-
Left handed
367+
<span
368+
class="toggle__shortLabel"
369+
>
370+
LH
371+
</span>
372+
<span
373+
class="toggle__longLabel"
374+
>
375+
Left handed
376+
</span>
368377
</button>
369378
<button
370379
class="fretboard__toggleButton fretboard__toggleButton--right fretboard__toggleButton--active"
371380
>
372-
Right handed
381+
<span
382+
class="toggle__shortLabel"
383+
>
384+
RH
385+
</span>
386+
<span
387+
class="toggle__longLabel"
388+
>
389+
Right handed
390+
</span>
373391
</button>
374392
</div>
375393
<div

0 commit comments

Comments
 (0)