feat: paginate watching pages + music updates

This commit is contained in:
Cory Dransfeldt 2024-05-26 15:18:17 -07:00
parent 9c0f47278c
commit 0d926fd844
No known key found for this signature in database
25 changed files with 141 additions and 90 deletions

View file

@ -251,12 +251,23 @@ export default {
getLastWatched: (show) => show?.['episodes'][show['episodes']?.length - 1]?.['last_watched_at'],
sortByPlaysDescending: (data) => data.sort((a, b) => (b['total_plays'] || b['plays']) - (a['total_plays'] || a['plays'])),
genreStrings: (genres, key) => genres.map(genre => genre[key]),
genreLinks: (genres, count = 10) => {
const genreData = genres.slice(0, count)
if (genreData.length === 0) return ''
if (genreData.length === 1) return genreData[0]
const allButLast = genreData.slice(0, -1).map(genre => `<a href="/music/genre/${sanitizeMediaString(genre)}">${genre}</a>`).join(', ')
const last = `<a href="/music/genre/${sanitizeMediaString(genreData[genreData.length - 1])}">${genreData[genreData.length - 1]}</a>`
mediaLinks: (data, type, count = 10) => {
const dataSlice = data.slice(0, count)
if (dataSlice.length === 0) return ''
if (dataSlice.length === 1) return type === 'genre' ? dataSlice[0] : dataSlice[0]['artist_name']
const allButLast = dataSlice.slice(0, -1).map(item => {
if (type === 'genre') {
return `<a href="/music/genre/${sanitizeMediaString(item)}">${item}</a>`
} else if (type === 'artist') {
return `<a href="/music/artists/${sanitizeMediaString(item['name_string'])}-${sanitizeMediaString(item['country'].toLowerCase())}">${item['name_string']}</a>`
}
}).join(', ')
const last = type === 'genre'
? `<a href="/music/genre/${sanitizeMediaString(dataSlice[dataSlice.length - 1])}">${dataSlice[dataSlice.length - 1]}</a>`
: `<a href="/music/artists/${sanitizeMediaString(dataSlice[dataSlice.length - 1]['name_string'])}-${sanitizeMediaString(dataSlice[dataSlice.length - 1]['country'].toLowerCase())}">${dataSlice[dataSlice.length - 1]['name_string']}</a>`
return `${allButLast} and ${last}`
},

View file

@ -19,4 +19,21 @@ export const sanitizeMediaString = (str) => {
remove: /[#,&,+()$~%.'":*?<>{}]/g,
lower: true,
})
}
export const regionNames = new Intl.DisplayNames(['en'], { type: 'region' })
export const getCountryName = (countryCode) => regionNames.of(countryCode.trim()) || countryCode.trim()
export const parseCountryField = (countryField) => {
if (!countryField) return null
const delimiters = [',', '/', '&', 'and']
let countries = [countryField]
delimiters.forEach(delimiter => {
countries = countries.flatMap(country => country.split(delimiter))
})
return countries.map(getCountryName).join(', ')
}