mastoradio/src/components/Queue.svelte

71 lines
1.6 KiB
Svelte
Raw Normal View History

2020-01-13 14:39:22 +01:00
<div>
2020-01-16 20:10:40 +01:00
{#each $queue as track, i}
<div class="entry" class:active={i === $index}>
2020-01-13 14:39:22 +01:00
<div>
2020-01-16 20:10:40 +01:00
<button on:click={() => toggle(i)}>
{#if i != $index}
▶️
{:else if $loading}
🕒
{:else if $paused}
2020-01-13 14:39:22 +01:00
▶️
2020-01-16 20:10:40 +01:00
{:else}
⏸️
2020-01-13 14:39:22 +01:00
{/if}
</button>
</div>
<div>
2020-01-16 20:10:40 +01:00
<div>{track.metadata.title}</div>
2020-01-13 14:39:22 +01:00
<div>
2020-01-16 20:10:40 +01:00
<b>{track.status.account.username} <small style="color: dimgray">{track.status.account.acct}</small></b>
{track.data.url}
2020-01-13 14:39:22 +01:00
</div>
</div>
</div>
{/each}
2020-01-16 20:10:40 +01:00
{#if $enqueueing}
LOADING ...
{/if}
2020-01-13 14:39:22 +01:00
</div>
<script>
import { onMount } from 'svelte'
2020-01-16 20:10:40 +01:00
import { index, queue, paused, enqueueing, enqueue, loading } from '/store.js'
2020-01-13 14:39:22 +01:00
2020-01-16 20:10:40 +01:00
const toggle = i => {
if (i === $index) {
2020-01-13 14:39:22 +01:00
$paused = !$paused
2020-01-16 20:10:40 +01:00
} else {
$index = i
$paused = false
2020-01-13 14:39:22 +01:00
}
}
onMount(() => {
2020-01-16 20:10:40 +01:00
enqueue().then(() => {
$index = 0
2020-01-13 14:39:22 +01:00
})
})
2020-01-16 20:10:40 +01:00
$: if ($index !== null && $index === $queue.length - 1) {
enqueue()
}
2020-01-13 14:39:22 +01:00
</script>
<style>
.entry {
display: flex;
border: 1px solid black;
}
.entry:hover {
background-color: rgb(219, 184, 219);
}
.entry.active {
background-color: plum;
}
</style>