A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
blob: 7da5c4521b8f3ef7fb1b7dc7181e2417be0b4a7a (1808 bytes)[doc][blame][raw]
1
import {watch} from '/asset/lib/vue.min.js';2
import {state} from '../main.js';3
import {$lang} from '../utils.js';4
import VButton from './button.js';6
export default {7
props: ['station'],8
data() {9
return {10
state,11
synced: false,12
playing: false,13
loading: false,14
error: false15
};16
},17
components: {18
VButton19
},20
methods: {21
$lang,22
togglePlay(station) {23
if(this.synced) {24
state.app.$refs.player.setPlaying(!this.playing);25
return;26
}27
state.app.$refs.player.play(station);28
}29
},30
mounted() {31
watch([32
() => this.station,33
() => state.app.$refs.player.station,34
() => state.app.$refs.player.playing,35
() => state.app.$refs.player.loading,36
() => state.app.$refs.player.error37
], ([, value, playing, loading, error]) => {38
if(value === null || value?.id !== this.station?.id) {39
this.synced = false;40
this.playing = false;41
return;42
}43
this.synced = true;44
this.playing = playing;45
this.loading = loading;46
this.error = error;47
});48
},49
template: `50
<v-button51
:icon="[ error ? 'alert-circle' : (loading ? 'rotate-clockwise' : (playing ? 'player-pause' : 'player-play')) ]"52
@click="() => togglePlay(station)"53
:text="$lang(loading ? 'player.loading' : (playing ? 'global.pause' : 'global.listen'))"54
class="bg-zinc-900 hover:bg-white px-1"55
:animation="[ error ? '' : (loading ? 'animate-spin' : '') ]"56
:active="synced"57
></v-button>58
`59
}