Follow track change when toggle

This commit is contained in:
nemunaire 2022-10-15 13:00:51 +02:00
parent cc301da971
commit 69ddfd48e9
3 changed files with 18 additions and 5 deletions

View File

@ -58,6 +58,10 @@ func (t *Track) Rename(newName string) error {
}
t.Path = newPath
// Recalculate hash
hash := sha512.Sum512([]byte(t.Path))
t.Id = hash[:]
return nil
}
@ -73,6 +77,10 @@ func (t *Track) MoveTo(path string) error {
}
t.Path = path
// Recalculate hash
hash := sha512.Sum512([]byte(t.Path))
t.Id = hash[:]
return nil
}

View File

@ -24,10 +24,9 @@ export class Track {
}
}
toggleEnable() {
async toggleEnable() {
this.enabled = !this.enabled;
this.save();
return this;
return await this.save();
}
async save() {
@ -39,7 +38,7 @@ export class Track {
if (res.status == 200) {
const data = await res.json();
this.update(data);
return data;
return this;
} else {
throw new Error((await res.json()).errmsg);
}

View File

@ -14,6 +14,12 @@
import { getTrack } from '$lib/track';
import { tracks } from '$lib/stores/tracks';
function toggleEnable(track) {
track.toggleEnable().then((t) => {
tracks.refresh();
goto('musiks/tracks/' + t.id);
})
}
function deleteThis(track) {
track.delete().then(() => {
tracks.refresh();
@ -38,7 +44,7 @@
</ListGroupItem>
<ListGroupItem class="d-flex gap-2">
<strong>Active&nbsp;?</strong>
<Input type="switch" on:change={() => track.toggleEnable()} checked={track.enabled} />
<Input type="switch" on:change={() => toggleEnable(track)} checked={track.enabled} />
</ListGroupItem>
<ListGroupItem>
<strong>ID</strong>