activated typescript strict mode
This commit is contained in:
@@ -2,6 +2,6 @@ export interface Chord {
|
||||
chord: string;
|
||||
length: number;
|
||||
position: number;
|
||||
slashChord?: string;
|
||||
add?: string;
|
||||
slashChord: string | null;
|
||||
add: string | null;
|
||||
}
|
||||
|
||||
@@ -4,5 +4,5 @@ import {Chord} from './chord';
|
||||
export interface Line {
|
||||
type: LineType;
|
||||
text: string;
|
||||
chords?: Chord[];
|
||||
chords: Chord[] | null;
|
||||
}
|
||||
|
||||
@@ -12,8 +12,10 @@ export class SongDataService {
|
||||
public constructor(private dbService: DbService) {}
|
||||
|
||||
public list$ = (): Observable<Song[]> => this.dbService.col$(this.collection);
|
||||
public read$ = (songId: string): Observable<Song | undefined> => this.dbService.doc$(this.collection + '/' + songId);
|
||||
public update$ = async (songId: string, data: Partial<Song>): Promise<void> => await this.dbService.doc(this.collection + '/' + songId).update(data);
|
||||
public read$ = (songId: string): Observable<Song | null> => this.dbService.doc$(this.collection + '/' + songId);
|
||||
public update$ = async (songId: string, data: Partial<Song>): Promise<void> =>
|
||||
await this.dbService.doc(this.collection + '/' + songId).update(data);
|
||||
public add = async (data: Partial<Song>): Promise<string> => (await this.dbService.col(this.collection).add(data)).id;
|
||||
public delete = async (songId: string): Promise<void> => await this.dbService.doc(this.collection + '/' + songId).delete();
|
||||
public delete = async (songId: string): Promise<void> =>
|
||||
await this.dbService.doc(this.collection + '/' + songId).delete();
|
||||
}
|
||||
|
||||
@@ -26,13 +26,15 @@ export class SongService {
|
||||
}
|
||||
|
||||
public list$ = (): Observable<Song[]> => this.songDataService.list$(); //.pipe(tap(_ => (this.list = _)));
|
||||
public read$ = (songId: string): Observable<Song | undefined> => this.songDataService.read$(songId);
|
||||
public read = (songId: string): Promise<Song | undefined> => this.read$(songId).pipe(first()).toPromise();
|
||||
public read$ = (songId: string): Observable<Song | null> => this.songDataService.read$(songId);
|
||||
public read = (songId: string): Promise<Song | null> => this.read$(songId).pipe(first()).toPromise();
|
||||
|
||||
public async update$(songId: string, data: Partial<Song>): Promise<void> {
|
||||
const song = await this.read(songId);
|
||||
if (!song) return;
|
||||
const edits = song.edits ?? [];
|
||||
const user = await this.userService.currentUser();
|
||||
if (!user) return;
|
||||
edits.push({username: user.name, timestamp: Timestamp.now()});
|
||||
await this.songDataService.update$(songId, {...data, edits});
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ export class TextRenderingService {
|
||||
|
||||
public constructor(private transposeService: TransposeService) {}
|
||||
|
||||
public parse(text: string, transpose: TransposeMode): Section[] {
|
||||
public parse(text: string, transpose: TransposeMode | null): Section[] {
|
||||
if (!text) {
|
||||
return [];
|
||||
}
|
||||
@@ -27,22 +27,21 @@ export class TextRenderingService {
|
||||
};
|
||||
return arrayOfLines.reduce((array, line) => {
|
||||
const type = this.getSectionTypeOfLine(line);
|
||||
if (this.regexSection.exec(line)) {
|
||||
return [
|
||||
...array,
|
||||
{
|
||||
type,
|
||||
number: indices[type]++,
|
||||
lines: [],
|
||||
},
|
||||
];
|
||||
if (this.regexSection.exec(line) && type !== null) {
|
||||
const section: Section = {
|
||||
type,
|
||||
number: indices[type]++,
|
||||
lines: [],
|
||||
};
|
||||
return [...array, section];
|
||||
}
|
||||
array[array.length - 1].lines.push(this.getLineOfLineText(line, transpose));
|
||||
const lineOfLineText = this.getLineOfLineText(line, transpose);
|
||||
if (lineOfLineText) array[array.length - 1].lines.push(lineOfLineText);
|
||||
return array;
|
||||
}, [] as Section[]);
|
||||
}
|
||||
|
||||
private getLineOfLineText(text: string, transpose: TransposeMode): Line {
|
||||
private getLineOfLineText(text: string, transpose: TransposeMode | null): Line | null {
|
||||
if (!text) {
|
||||
return null;
|
||||
}
|
||||
@@ -50,11 +49,13 @@ export class TextRenderingService {
|
||||
const hasMatches = cords.length > 0;
|
||||
const type = hasMatches ? LineType.chord : LineType.text;
|
||||
|
||||
const line = {type, text, chords: hasMatches ? cords : undefined};
|
||||
return transpose ? this.transposeService.transpose(line, transpose.baseKey, transpose.targetKey) : this.transposeService.renderChords(line);
|
||||
const line: Line = {type, text, chords: hasMatches ? cords : null};
|
||||
return transpose
|
||||
? this.transposeService.transpose(line, transpose.baseKey, transpose.targetKey)
|
||||
: this.transposeService.renderChords(line);
|
||||
}
|
||||
|
||||
private getSectionTypeOfLine(line: string): SectionType {
|
||||
private getSectionTypeOfLine(line: string): SectionType | null {
|
||||
if (!line) {
|
||||
return null;
|
||||
}
|
||||
@@ -71,10 +72,12 @@ export class TextRenderingService {
|
||||
case 'Bridge':
|
||||
return SectionType.Bridge;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private readChords(chordLine: string): Chord[] {
|
||||
let match: string[];
|
||||
let match: string[] | null;
|
||||
const chords: Chord[] = [];
|
||||
|
||||
// https://regex101.com/r/68jMB8/5
|
||||
@@ -86,6 +89,8 @@ export class TextRenderingService {
|
||||
chord: match[1],
|
||||
length: match[0].length,
|
||||
position: regex.lastIndex - match[0].length,
|
||||
slashChord: null,
|
||||
add: null,
|
||||
};
|
||||
if (match[3]) {
|
||||
chord.slashChord = match[3];
|
||||
|
||||
@@ -17,8 +17,9 @@ export class TransposeService {
|
||||
const difference = this.getDistance(baseKey, targetKey);
|
||||
const map = this.getMap(baseKey, difference);
|
||||
|
||||
const chords = difference > 0 ? line.chords.map(chord => this.transposeChord(chord, map)) : line.chords;
|
||||
const renderedLine = this.renderLine(chords);
|
||||
const chords =
|
||||
difference > 0 && line.chords && map ? line.chords.map(chord => this.transposeChord(chord, map)) : line.chords;
|
||||
const renderedLine = this.renderLine(chords ?? []);
|
||||
|
||||
return {...line, text: renderedLine, chords};
|
||||
}
|
||||
@@ -28,13 +29,16 @@ export class TransposeService {
|
||||
return line;
|
||||
}
|
||||
|
||||
const renderedLine = this.renderLine(line.chords);
|
||||
const renderedLine = this.renderLine(line.chords ?? []);
|
||||
return {...line, text: renderedLine};
|
||||
}
|
||||
|
||||
public getDistance(baseKey: string, targetKey: string): number {
|
||||
const scale = getScaleType(baseKey);
|
||||
return scale ? (scale[0].indexOf(targetKey) - scale[0].indexOf(baseKey) ?? scale[1].indexOf(targetKey) - scale[1].indexOf(baseKey)) % 12 : 0;
|
||||
return scale
|
||||
? (scale[0].indexOf(targetKey) - scale[0].indexOf(baseKey) ??
|
||||
scale[1].indexOf(targetKey) - scale[1].indexOf(baseKey)) % 12
|
||||
: 0;
|
||||
}
|
||||
|
||||
public getMap(baseKey: string, difference: number): TransposeMap | null {
|
||||
@@ -42,7 +46,7 @@ export class TransposeService {
|
||||
if (!scale) {
|
||||
return null;
|
||||
}
|
||||
const map = {};
|
||||
const map: {[key: string]: string} = {};
|
||||
for (let i = 0; i < 12; i++) {
|
||||
const source = scale[0][i];
|
||||
const mappedIndex = (i + difference) % 12;
|
||||
@@ -68,7 +72,8 @@ export class TransposeService {
|
||||
}
|
||||
|
||||
private renderLine(chords: Chord[]): string {
|
||||
let template = ' ';
|
||||
let template =
|
||||
' ';
|
||||
|
||||
chords.forEach(chord => {
|
||||
const pos = chord.position;
|
||||
@@ -85,6 +90,10 @@ export class TransposeService {
|
||||
}
|
||||
|
||||
private renderChord(chord: Chord) {
|
||||
return scaleMapping[chord.chord] + (chord.add ? chord.add : '') + (chord.slashChord ? '/' + scaleMapping[chord.slashChord] : '');
|
||||
return (
|
||||
scaleMapping[chord.chord] +
|
||||
(chord.add ? chord.add : '') +
|
||||
(chord.slashChord ? '/' + scaleMapping[chord.slashChord] : '')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ export class UploadService extends FileBase {
|
||||
const ref = this.angularFireStorage.ref(filePath);
|
||||
const task = ref.put(upload.file);
|
||||
|
||||
task.percentageChanges().subscribe(percent => (upload.progress = percent));
|
||||
task.percentageChanges().subscribe(percent => (upload.progress = percent ?? 0));
|
||||
task
|
||||
.snapshotChanges()
|
||||
.pipe(finalize(() => void this.saveFileData(songId, upload)))
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
export class Upload {
|
||||
public $key: string;
|
||||
public file: File;
|
||||
public name: string;
|
||||
public path: string;
|
||||
public progress: number;
|
||||
public name = '';
|
||||
public path = '';
|
||||
public progress = 0;
|
||||
public createdAt: Date = new Date();
|
||||
|
||||
public constructor(file: File) {
|
||||
|
||||
Reference in New Issue
Block a user