Add Song model type

This commit is contained in:
Jakob Moser 2025-11-13 00:20:32 +01:00
parent ef6e52c0cb
commit 58a096db29
Signed by: jakob
GPG Key ID: 3EF2BA2851B3F53C

View File

@ -0,0 +1,24 @@
import { Base } from "./Base.js"
import { getFavoriteIds, addFavorite, removeFavorite } from "./favorites.js"
export default class Song extends Base {
static async forceLoad() {
return await m.request({ url: "/songs.json" })
}
get favorite() {
return getFavoriteIds().has(this.id || this.uuid)
}
set favorite(isFavorite) {
if (isFavorite) {
addFavorite(this.id || this.uuid)
} else {
removeFavorite(this.id || this.uuid)
}
}
toggleFavorite() {
this.favorite = !this.favorite
}
}