From 6f9aa95faf9bba9a9da51c0352676a918bd75674 Mon Sep 17 00:00:00 2001 From: Cory Dransfeldt Date: Sun, 13 Oct 2024 15:54:31 -0700 Subject: [PATCH] chore: clean up filter --- config/filters/media.js | 43 ++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/config/filters/media.js b/config/filters/media.js index 43a7e6a8..b349d82f 100644 --- a/config/filters/media.js +++ b/config/filters/media.js @@ -13,39 +13,26 @@ export default { if (!data || !type) return '' const dataSlice = data.slice(0, count) - if (dataSlice.length === 0) return null - if (dataSlice.length === 1) { - const item = dataSlice[0] - if (type === 'genre') { - return `${item['genre_name']}` - } else if (type === 'artist') { - return `${item['name']}` - } else if (type === 'book') { - return `${item['title']}` + + const buildLink = (item) => { + switch (type) { + case 'genre': + return `${item['genre_name']}` + case 'artist': + return `${item['name']}` + case 'book': + return `${item['title']}` + default: + return '' } } - const allButLast = dataSlice.slice(0, -1).map(item => { - if (type === 'genre') { - return `${item['genre_name']}` - } else if (type === 'artist') { - return `${item['name']}` - } else if (type === 'book') { - return `${item['title']}` - } - }).join(', ') + if (dataSlice.length === 1) return buildLink(dataSlice[0]) - let last - const lastItem = dataSlice[dataSlice.length - 1] - - if (type === 'genre') { - last = `${lastItem['genre_name']}` - } else if (type === 'artist') { - last = `${lastItem['name']}` - } else if (type === 'book') { - last = `${lastItem['title']}` - } + const links = dataSlice.map(buildLink) + const allButLast = links.slice(0, -1).join(', ') + const last = links[links.length - 1] return `${allButLast} and ${last}` }