A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
blob: 7e1ead19734c559cad0a9b817404fb46a5385127 (1917 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
], ([station, value, playing, loading, error]) => {38
if(value === null || value?.id !== station?.id) {39
this.synced = false;40
this.playing = false;41
this.loading = false;42
this.error = false;43
return;44
}45
this.synced = true;46
this.playing = playing;47
this.loading = loading;48
this.error = error;49
}, { immediate: true, deep: true });50
},51
template: `52
<v-button53
:icon="[ error ? 'alert-circle' : (loading ? 'rotate-clockwise' : (playing ? 'player-pause' : 'player-play')) ]"54
@click="() => togglePlay(station)"55
:text="$lang(loading ? 'player.loading' : (playing ? 'global.pause' : 'global.listen'))"56
class="bg-zinc-900 hover:bg-white px-1"57
:animation="[ error ? '' : (loading ? 'animate-spin' : '') ]"58
:active="synced"59
></v-button>60
`61
}