Files
SAE_riot/components/favorites.riot

140 lines
3.5 KiB
Plaintext
Raw Normal View History

2025-03-28 13:53:35 +01:00
<favorites>
2025-03-31 13:15:47 +02:00
<h2>Mes favoris</h2>
2025-03-28 16:27:07 +01:00
2025-03-31 13:15:47 +02:00
<div if={state.loading}>
<p>Chargement des favoris...</p>
</div>
<div if={!state.loading && state.favorites.items.length === 0}>
<p>Aucun favori trouvé.</p>
</div>
<div if={!state.loading && state.favorites.items.length > 0}>
<div class="results-grid">
<div class="card" each={item in state.favorites.items}>
2025-04-02 13:18:06 +02:00
<a onclick={() => removeFavoris(item.id, item.type)}>
2025-03-31 13:15:47 +02:00
<button><i class="fa-solid fa-star"></i></button>
</a>
2025-04-02 13:18:06 +02:00
<a href={"#/release-details/" + item.type + "/" + item.id}>
<h4>{item.artists[0].name} {item.title}</h4>
2025-03-31 13:15:47 +02:00
<img src={item.thumb} alt="cover" />
<div if={item.type !== 'artist'}>
<p>{item.year}</p>
<footer>
{item.community?.want} <i class="fa-solid fa-check"></i>
{item.community?.have} <i class="fa-regular fa-heart"></i>
</footer>
</div>
</a>
2025-04-03 14:38:06 +02:00
<a if={item.type === "release"} href={"#/release-details/master/" + item.master_id}><button>master</button></a>
<a if={item.type === "master"} href="#"><button onclick={() => this.MainReleaseDetails(item)}>release</button></a>
2025-03-31 13:15:47 +02:00
</div>
2025-03-28 16:27:07 +01:00
</div>
2025-03-31 13:15:47 +02:00
</div>
2025-03-28 16:27:07 +01:00
2025-03-31 13:15:47 +02:00
<script>
export default {
state: {
favorites: {
items: []
},
loading: true
},
2025-03-28 16:27:07 +01:00
2025-03-31 13:15:47 +02:00
async onMounted() {
2025-04-02 13:18:06 +02:00
const favs = await window.getFavorites();
2025-03-28 13:53:35 +01:00
2025-03-31 13:15:47 +02:00
const items = [];
2025-04-02 13:18:06 +02:00
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
});
2025-03-31 13:15:47 +02:00
}
2025-03-28 16:27:07 +01:00
2025-04-02 13:18:06 +02:00
this.state.favorites.items = items;
2025-03-31 13:15:47 +02:00
this.state.loading = false;
this.update();
},
2025-03-28 16:27:07 +01:00
2025-04-02 13:18:06 +02:00
async removeFavoris(id, type) {
await window.removeFavorite(id, type);
2025-03-31 13:15:47 +02:00
this.state.favorites.items = this.state.favorites.items.filter(item => item.id !== id);
this.update();
2025-04-03 14:38:06 +02:00
},
async MainReleaseDetails(item) {
const res = await fetch(item.resource_url);
const json = await res.json();
const mainUrl = json.main_release_url;
const res2 = await fetch(mainUrl);
const releaseData = await res2.json();
console.log(releaseData);
window.location.hash = `#/release-details/release/${releaseData.id}`;
2025-03-31 13:15:47 +02:00
}
}
</script>
<style>
.results-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
gap: 1rem;
padding: 1rem;
}
.card {
background: white;
border-radius: 10px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.07);
padding: 1rem;
text-align: center;
transition: transform 0.2s ease;
}
.card:hover {
transform: translateY(-4px);
}
.card img {
width: 100%;
border-radius: 6px;
margin-bottom: 0.5rem;
}
.card h4 {
font-size: 1.1rem;
margin: 0.5rem 0;
}
footer {
display: flex;
justify-content: space-around;
font-size: 0.9rem;
color: #666;
}
.card a i.fa-star {
color: #fbc02d;
font-size: 1.3rem;
transition: transform 0.2s ease;
}
.card a i.fa-star:hover {
transform: scale(1.2);
}
</style>
</favorites>