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 t.Path = newPath
// Recalculate hash
hash := sha512.Sum512([]byte(t.Path))
t.Id = hash[:]
return nil return nil
} }
@ -73,6 +77,10 @@ func (t *Track) MoveTo(path string) error {
} }
t.Path = path t.Path = path
// Recalculate hash
hash := sha512.Sum512([]byte(t.Path))
t.Id = hash[:]
return nil return nil
} }

View File

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

View File

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