so://phie

verbal

A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal

blob: c68394c16cf2d03a09d7865292ac5c74729537f4 (1843 bytes)[doc][blame][raw]

1import {watch} from '/asset/lib/vue.min.js';

2import {state} from '../main.js';

3import {$lang} from '../utils.js';

4import VButton from './button.js';

5

6export default {

7 props: ['station'],

8 data() {

9 return {

10 state,

11 synced: false,

12 playing: false,

13 loading: false,

14 error: false

15 };

16 },

17 components: {

18 VButton

19 },

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.error

37 ], ([station, value, playing, loading, error]) => {

38 if(value === null || value?.id !== 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 }, { immediate: true, deep: true });

48 },

49 template: `

50 <v-button

51 :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}