fix: resolved errors in formatting search results
This commit is contained in:
parent
7f0d621f62
commit
738a2ff35e
File diff suppressed because one or more lines are too long
@ -44,7 +44,7 @@ import { sendAddToQueue } from '@/utils/downloads'
|
||||
import { numberWithDots, convertDuration } from '@/utils/utils'
|
||||
import EventBus from '@/utils/EventBus'
|
||||
|
||||
import { reduceSearchResults, formatSingleTrack, formatAlbums, formatArtist, formatPlaylist } from '@/data/search'
|
||||
import { formatSearchResults, formatSingleTrack, formatAlbums, formatArtist, formatPlaylist } from '@/data/search'
|
||||
|
||||
const resetObj = { data: [], next: 0, total: 0, hasLoaded: false }
|
||||
|
||||
@ -172,7 +172,7 @@ export default {
|
||||
return this.results.allTab
|
||||
}
|
||||
|
||||
return reduceSearchResults(this.results[this.currentTab.viewInfo], this.currentTab.formatFunc)
|
||||
return formatSearchResults(this.results[this.currentTab.viewInfo], this.currentTab.formatFunc)
|
||||
},
|
||||
changeSearchTab(tabName) {
|
||||
tabName = tabName.toLowerCase()
|
||||
|
@ -30,28 +30,28 @@
|
||||
|
||||
<ResultsTracks
|
||||
v-else-if="section === 'TRACK'"
|
||||
:viewInfo="reduceSearchResults(viewInfo.TRACK, formatSingleTrack)"
|
||||
:viewInfo="formatSearchResults(viewInfo.TRACK, formatSingleTrack)"
|
||||
:itemsToShow="6"
|
||||
@add-to-queue="$emit('add-to-queue', $event)"
|
||||
/>
|
||||
|
||||
<ResultsAlbums
|
||||
v-else-if="section == 'ALBUM'"
|
||||
:viewInfo="reduceSearchResults(viewInfo.ALBUM, formatAlbums)"
|
||||
:viewInfo="formatSearchResults(viewInfo.ALBUM, formatAlbums)"
|
||||
:itemsToShow="6"
|
||||
@add-to-queue="$emit('add-to-queue', $event)"
|
||||
/>
|
||||
|
||||
<ResultsPlaylists
|
||||
v-else-if="section == 'PLAYLIST'"
|
||||
:viewInfo="reduceSearchResults(viewInfo.PLAYLIST, formatPlaylist)"
|
||||
:viewInfo="formatSearchResults(viewInfo.PLAYLIST, formatPlaylist)"
|
||||
:itemsToShow="6"
|
||||
@add-to-queue="$emit('add-to-queue', $event)"
|
||||
/>
|
||||
|
||||
<ResultsArtists
|
||||
v-else-if="section === 'ARTIST'"
|
||||
:viewInfo="reduceSearchResults(viewInfo.ARTIST, formatArtist)"
|
||||
:viewInfo="formatSearchResults(viewInfo.ARTIST, formatArtist)"
|
||||
:itemsToShow="6"
|
||||
@add-to-queue="$emit('add-to-queue', $event)"
|
||||
/>
|
||||
@ -81,7 +81,7 @@ import ResultsAlbums from '@components/search/ResultsAlbums.vue'
|
||||
import ResultsArtists from '@components/search/ResultsArtists.vue'
|
||||
import ResultsPlaylists from '@components/search/ResultsPlaylists.vue'
|
||||
|
||||
import { reduceSearchResults, formatSingleTrack, formatAlbums, formatArtist, formatPlaylist } from '@/data/search'
|
||||
import { formatSearchResults, formatSingleTrack, formatAlbums, formatArtist, formatPlaylist } from '@/data/search'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
@ -130,7 +130,7 @@ export default {
|
||||
methods: {
|
||||
convertDuration,
|
||||
upperCaseFirstLowerCaseRest,
|
||||
reduceSearchResults,
|
||||
formatSearchResults,
|
||||
formatSingleTrack,
|
||||
formatAlbums,
|
||||
formatArtist,
|
||||
|
@ -22,7 +22,7 @@ import { getProperty } from '@/utils/utils'
|
||||
* @param {Formatter} formatFunc
|
||||
* @returns {null|ReducedSearchResult}
|
||||
*/
|
||||
export function reduceSearchResults(rawObj, formatFunc) {
|
||||
export function formatSearchResults(rawObj, formatFunc) {
|
||||
if (!rawObj.hasLoaded) {
|
||||
return null
|
||||
} else {
|
||||
@ -46,6 +46,12 @@ export function reduceSearchResults(rawObj, formatFunc) {
|
||||
* @param {FormattedData} track
|
||||
*/
|
||||
export function formatSingleTrack(track) {
|
||||
let isTrackExplicit = getProperty(track, 'explicit_lyrics', 'EXPLICIT_LYRICS')
|
||||
|
||||
if (typeof isTrackExplicit === 'string') {
|
||||
isTrackExplicit = isTrackExplicit !== '0'
|
||||
}
|
||||
|
||||
return {
|
||||
/* Track */
|
||||
trackTitle: getProperty(track, 'title', 'SNG_TITLE'),
|
||||
@ -53,7 +59,7 @@ export function formatSingleTrack(track) {
|
||||
trackPreview: getProperty(track, 'preview'),
|
||||
trackDuration: getProperty(track, 'duration', 'DURATION'),
|
||||
trackLink: getProperty(track, 'link') || `https://www.deezer.com/track/${track.SNG_ID}`,
|
||||
isTrackExplicit: getProperty(track, 'explicit_lyrics', 'EXPLICIT_LYRICS'),
|
||||
isTrackExplicit,
|
||||
|
||||
/* Artist */
|
||||
artistID: getProperty(track, 'artist.id', 'ART_ID'),
|
||||
@ -69,6 +75,12 @@ export function formatSingleTrack(track) {
|
||||
}
|
||||
|
||||
export function formatAlbums(album) {
|
||||
let isAlbumExplicit = getProperty(album, 'explicit_lyrics', 'EXPLICIT_ALBUM_CONTENT.EXPLICIT_LYRICS_STATUS')
|
||||
|
||||
if ('number' === typeof isAlbumExplicit) {
|
||||
isAlbumExplicit = isAlbumExplicit === 1
|
||||
}
|
||||
|
||||
return {
|
||||
/* Album */
|
||||
albumID: getProperty(album, 'id', 'ALB_ID'),
|
||||
@ -78,7 +90,7 @@ export function formatAlbums(album) {
|
||||
`https://e-cdns-images.dzcdn.net/images/cover/${album.ALB_PICTURE}/156x156-000000-80-0-0.jpg`,
|
||||
albumLink: getProperty(album, 'link') || `https://deezer.com/album/${album.ALB_ID}`,
|
||||
albumTracks: getProperty(album, 'nb_tracks', 'NUMBER_TRACK'),
|
||||
isAlbumExplicit: getProperty(album, 'explicit_lyrics', 'EXPLICIT_ALBUM_CONTENT.EXPLICIT_LYRICS_STATUS'),
|
||||
isAlbumExplicit,
|
||||
|
||||
/* Artist */
|
||||
artistName: getProperty(album, 'artist.name', 'ART_NAME')
|
||||
|
@ -109,7 +109,7 @@ export function getProperty(obj, ...props) {
|
||||
}, obj)
|
||||
: obj[prop]
|
||||
|
||||
if (!!valueToTest) {
|
||||
if ('undefined' !== typeof valueToTest) {
|
||||
return valueToTest
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user