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 { numberWithDots, convertDuration } from '@/utils/utils'
|
||||||
import EventBus from '@/utils/EventBus'
|
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 }
|
const resetObj = { data: [], next: 0, total: 0, hasLoaded: false }
|
||||||
|
|
||||||
@ -172,7 +172,7 @@ export default {
|
|||||||
return this.results.allTab
|
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) {
|
changeSearchTab(tabName) {
|
||||||
tabName = tabName.toLowerCase()
|
tabName = tabName.toLowerCase()
|
||||||
|
@ -30,28 +30,28 @@
|
|||||||
|
|
||||||
<ResultsTracks
|
<ResultsTracks
|
||||||
v-else-if="section === 'TRACK'"
|
v-else-if="section === 'TRACK'"
|
||||||
:viewInfo="reduceSearchResults(viewInfo.TRACK, formatSingleTrack)"
|
:viewInfo="formatSearchResults(viewInfo.TRACK, formatSingleTrack)"
|
||||||
:itemsToShow="6"
|
:itemsToShow="6"
|
||||||
@add-to-queue="$emit('add-to-queue', $event)"
|
@add-to-queue="$emit('add-to-queue', $event)"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ResultsAlbums
|
<ResultsAlbums
|
||||||
v-else-if="section == 'ALBUM'"
|
v-else-if="section == 'ALBUM'"
|
||||||
:viewInfo="reduceSearchResults(viewInfo.ALBUM, formatAlbums)"
|
:viewInfo="formatSearchResults(viewInfo.ALBUM, formatAlbums)"
|
||||||
:itemsToShow="6"
|
:itemsToShow="6"
|
||||||
@add-to-queue="$emit('add-to-queue', $event)"
|
@add-to-queue="$emit('add-to-queue', $event)"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ResultsPlaylists
|
<ResultsPlaylists
|
||||||
v-else-if="section == 'PLAYLIST'"
|
v-else-if="section == 'PLAYLIST'"
|
||||||
:viewInfo="reduceSearchResults(viewInfo.PLAYLIST, formatPlaylist)"
|
:viewInfo="formatSearchResults(viewInfo.PLAYLIST, formatPlaylist)"
|
||||||
:itemsToShow="6"
|
:itemsToShow="6"
|
||||||
@add-to-queue="$emit('add-to-queue', $event)"
|
@add-to-queue="$emit('add-to-queue', $event)"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ResultsArtists
|
<ResultsArtists
|
||||||
v-else-if="section === 'ARTIST'"
|
v-else-if="section === 'ARTIST'"
|
||||||
:viewInfo="reduceSearchResults(viewInfo.ARTIST, formatArtist)"
|
:viewInfo="formatSearchResults(viewInfo.ARTIST, formatArtist)"
|
||||||
:itemsToShow="6"
|
:itemsToShow="6"
|
||||||
@add-to-queue="$emit('add-to-queue', $event)"
|
@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 ResultsArtists from '@components/search/ResultsArtists.vue'
|
||||||
import ResultsPlaylists from '@components/search/ResultsPlaylists.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 {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@ -130,7 +130,7 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
convertDuration,
|
convertDuration,
|
||||||
upperCaseFirstLowerCaseRest,
|
upperCaseFirstLowerCaseRest,
|
||||||
reduceSearchResults,
|
formatSearchResults,
|
||||||
formatSingleTrack,
|
formatSingleTrack,
|
||||||
formatAlbums,
|
formatAlbums,
|
||||||
formatArtist,
|
formatArtist,
|
||||||
|
@ -22,7 +22,7 @@ import { getProperty } from '@/utils/utils'
|
|||||||
* @param {Formatter} formatFunc
|
* @param {Formatter} formatFunc
|
||||||
* @returns {null|ReducedSearchResult}
|
* @returns {null|ReducedSearchResult}
|
||||||
*/
|
*/
|
||||||
export function reduceSearchResults(rawObj, formatFunc) {
|
export function formatSearchResults(rawObj, formatFunc) {
|
||||||
if (!rawObj.hasLoaded) {
|
if (!rawObj.hasLoaded) {
|
||||||
return null
|
return null
|
||||||
} else {
|
} else {
|
||||||
@ -46,6 +46,12 @@ export function reduceSearchResults(rawObj, formatFunc) {
|
|||||||
* @param {FormattedData} track
|
* @param {FormattedData} track
|
||||||
*/
|
*/
|
||||||
export function formatSingleTrack(track) {
|
export function formatSingleTrack(track) {
|
||||||
|
let isTrackExplicit = getProperty(track, 'explicit_lyrics', 'EXPLICIT_LYRICS')
|
||||||
|
|
||||||
|
if (typeof isTrackExplicit === 'string') {
|
||||||
|
isTrackExplicit = isTrackExplicit !== '0'
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
/* Track */
|
/* Track */
|
||||||
trackTitle: getProperty(track, 'title', 'SNG_TITLE'),
|
trackTitle: getProperty(track, 'title', 'SNG_TITLE'),
|
||||||
@ -53,7 +59,7 @@ export function formatSingleTrack(track) {
|
|||||||
trackPreview: getProperty(track, 'preview'),
|
trackPreview: getProperty(track, 'preview'),
|
||||||
trackDuration: getProperty(track, 'duration', 'DURATION'),
|
trackDuration: getProperty(track, 'duration', 'DURATION'),
|
||||||
trackLink: getProperty(track, 'link') || `https://www.deezer.com/track/${track.SNG_ID}`,
|
trackLink: getProperty(track, 'link') || `https://www.deezer.com/track/${track.SNG_ID}`,
|
||||||
isTrackExplicit: getProperty(track, 'explicit_lyrics', 'EXPLICIT_LYRICS'),
|
isTrackExplicit,
|
||||||
|
|
||||||
/* Artist */
|
/* Artist */
|
||||||
artistID: getProperty(track, 'artist.id', 'ART_ID'),
|
artistID: getProperty(track, 'artist.id', 'ART_ID'),
|
||||||
@ -69,6 +75,12 @@ export function formatSingleTrack(track) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function formatAlbums(album) {
|
export function formatAlbums(album) {
|
||||||
|
let isAlbumExplicit = getProperty(album, 'explicit_lyrics', 'EXPLICIT_ALBUM_CONTENT.EXPLICIT_LYRICS_STATUS')
|
||||||
|
|
||||||
|
if ('number' === typeof isAlbumExplicit) {
|
||||||
|
isAlbumExplicit = isAlbumExplicit === 1
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
/* Album */
|
/* Album */
|
||||||
albumID: getProperty(album, 'id', 'ALB_ID'),
|
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`,
|
`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}`,
|
albumLink: getProperty(album, 'link') || `https://deezer.com/album/${album.ALB_ID}`,
|
||||||
albumTracks: getProperty(album, 'nb_tracks', 'NUMBER_TRACK'),
|
albumTracks: getProperty(album, 'nb_tracks', 'NUMBER_TRACK'),
|
||||||
isAlbumExplicit: getProperty(album, 'explicit_lyrics', 'EXPLICIT_ALBUM_CONTENT.EXPLICIT_LYRICS_STATUS'),
|
isAlbumExplicit,
|
||||||
|
|
||||||
/* Artist */
|
/* Artist */
|
||||||
artistName: getProperty(album, 'artist.name', 'ART_NAME')
|
artistName: getProperty(album, 'artist.name', 'ART_NAME')
|
||||||
|
@ -109,7 +109,7 @@ export function getProperty(obj, ...props) {
|
|||||||
}, obj)
|
}, obj)
|
||||||
: obj[prop]
|
: obj[prop]
|
||||||
|
|
||||||
if (!!valueToTest) {
|
if ('undefined' !== typeof valueToTest) {
|
||||||
return valueToTest
|
return valueToTest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user