feat: massive refactor
This commit is contained in:
parent
d424082c95
commit
1880790c05
38 changed files with 245 additions and 761 deletions
|
@ -13,27 +13,7 @@ const fetchAllArtists = async () => {
|
|||
while (true) {
|
||||
const { data, error } = await supabase
|
||||
.from('optimized_artists')
|
||||
.select(`
|
||||
id,
|
||||
name_string,
|
||||
url,
|
||||
tentative,
|
||||
total_plays,
|
||||
country,
|
||||
description,
|
||||
favorite,
|
||||
genre,
|
||||
emoji,
|
||||
tattoo,
|
||||
art,
|
||||
albums,
|
||||
concerts,
|
||||
books,
|
||||
movies,
|
||||
posts,
|
||||
related_artists,
|
||||
shows
|
||||
`)
|
||||
.select('*')
|
||||
.range(rangeStart, rangeStart + PAGE_SIZE - 1)
|
||||
|
||||
if (error) {
|
||||
|
@ -51,49 +31,8 @@ const fetchAllArtists = async () => {
|
|||
|
||||
const processArtists = (artists) => {
|
||||
return artists.map(artist => ({
|
||||
name: artist['name_string'],
|
||||
tentative: artist['tentative'],
|
||||
totalPlays: artist['total_plays'],
|
||||
...artist,
|
||||
country: parseCountryField(artist['country']),
|
||||
description: artist['description'],
|
||||
favorite: artist['favorite'],
|
||||
genre: {
|
||||
name: artist['genre']['name'],
|
||||
url: artist['genre']['url'],
|
||||
},
|
||||
emoji: artist['emoji'],
|
||||
tattoo: artist['tattoo'],
|
||||
image: artist['art'] ? `/${artist['art']}` : '',
|
||||
url: artist['url'],
|
||||
albums: (artist['albums'] || []).map(album => ({
|
||||
name: album['name'],
|
||||
releaseYear: album['release_year'],
|
||||
totalPlays: album['total_plays'],
|
||||
art: album.art ? `/${album['art']}` : ''
|
||||
})).sort((a, b) => a['release_year'] - b['release_year']),
|
||||
concerts: artist['concerts'] ? artist['concerts'].sort((a, b) => new Date(b['date']) - new Date(a['date'])) : null,
|
||||
books: artist['books'] ? artist['books'].map(book => ({
|
||||
title: book['title'],
|
||||
author: book['author'],
|
||||
description: book['description'],
|
||||
url: `/books/${book['isbn']}`,
|
||||
})).sort((a, b) => a['title'].localeCompare(b['title'])) : null,
|
||||
movies: artist['movies'] ? artist['movies'].map(movie => ({
|
||||
title: movie['title'],
|
||||
year: movie['year'],
|
||||
url: `/watching/movies/${movie['tmdb_id']}`,
|
||||
})).sort((a, b) => b['year'] - a['year']) : null,
|
||||
shows: artist['shows'] ? artist['shows'].map(show => ({
|
||||
title: show['title'],
|
||||
year: show['year'],
|
||||
url: `/watching/shows/${show['tmdb_id']}`,
|
||||
})).sort((a, b) => b['year'] - a['year']) : null,
|
||||
posts: artist['posts'] ? artist['posts'].map(post => ({
|
||||
title: post['title'],
|
||||
date: post['date'],
|
||||
url: post['url'],
|
||||
})).sort((a, b) => new Date(b['date']) - new Date(a['date'])) : null,
|
||||
relatedArtists: artist['related_artists'] ? artist['related_artists'].sort((a, b) => a['name'].localeCompare(b['name'])) : null,
|
||||
}))
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue