-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelpers.ts
49 lines (44 loc) · 1.42 KB
/
Helpers.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { FormSelection } from "../types/FormSelection"
import { Track } from "../types/Track"
import { TrackSource } from "../types/TrackSource"
export const getTrackIdList = (tracks: Track[]): string => {
return tracks.map((o) => o.id).join(",")
}
export const combineTwoArraysOnId = (a: any[], b: any[]): any[] => {
return a.map((oa) => {
return { ...oa, ...b.find((d) => d.id === oa.id) }
})
}
export const getSourcesString = (sources: FormSelection): string => {
let s: string = "your "
if (!sources.artists && !sources.tracks && !sources.artists && sources.recommended) s = ""
if (sources.saved) {
s = s + "liked songs, "
}
if (sources.tracks) {
s = s + "top tracks, "
}
if (sources.artists) {
s = s + "top artists, "
}
if (sources.recommended) {
s = s + `${sources.genres[0].replace("-", " ")}, `
}
return s ? s.substring(0, s.length - 2) : s
}
export const getTrackSourceFromFormSelection = (formSelection: FormSelection): TrackSource[] => {
let result: TrackSource[] = []
if (formSelection.saved) {
result.push(TrackSource.SAVED_SONGS)
}
if (formSelection.tracks) {
result.push(TrackSource.TOP_SONGS)
}
if (formSelection.artists) {
result.push(TrackSource.TOP_ARTISTS_SONGS)
}
if (formSelection.recommended) {
result.push(TrackSource.RECOMMENDED_SONGS)
}
return result
}