This commit is contained in:
2025-04-02 13:18:06 +02:00
parent f8e3034dcf
commit e5992d8754
3 changed files with 45 additions and 38 deletions

View File

@@ -12,11 +12,11 @@
<div if={!state.loading && state.favorites.items.length > 0}>
<div class="results-grid">
<div class="card" each={item in state.favorites.items}>
<a onclick={() => removeFavoris(item.id)}>
<a onclick={() => removeFavoris(item.id, item.type)}>
<button><i class="fa-solid fa-star"></i></button>
</a>
<a href={"#/release-details/" +(item.isMaster ? "master" : "release") + "/" + item.id}>
<h4>{item.title}</h4>
<a href={"#/release-details/" + item.type + "/" + item.id}>
<h4>{item.artists[0].name} {item.title}</h4>
<img src={item.thumb} alt="cover" />
<div if={item.type !== 'artist'}>
<p>{item.year}</p>
@@ -40,34 +40,32 @@
},
async onMounted() {
const ids = await window.getFavorites();
const favs = await window.getFavorites();
const items = [];
for (const id of ids) {
const release = await window.getReleaseDetails(id);
items.push(release);
for (const fav of favs) {
let data;
if (fav.Type === "master") {
data = await window.getMasterDetails(fav.releaseId);
} else {
data = await window.getReleaseDetails(fav.releaseId);
}
items.push({
...data,
type: fav.Type
});
}
const masterPromises = items.map(item => isMaster(item.id, item.master_id));
const masterResults = await Promise.all(masterPromises);
const enrichedItems = result.results.map((item, index) => ({
...item,
isMaster: masterResults[index]
}));
this.state.favorites.items = enrichedItems;
this.state.favorites.items = items;
this.state.loading = false;
console.log(this.state)
this.update();
},
ismaster(id , master_id){
return id === master_id;
},
async removeFavoris(id) {
await window.removeFavorite(id);
async removeFavoris(id, type) {
await window.removeFavorite(id, type);
this.state.favorites.items = this.state.favorites.items.filter(item => item.id !== id);
this.update();
}