so://phie

verbal

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

blob: 4d81feca71aca31a494a4c09cb89f21608755888 (4071 bytes)[doc][blame][raw]

1import {http, $lang} from './utils.js';

2import VMenu from './component/menu.js';

3import VPlayer from './component/player.js';

4import VPopup from './component/popup.js';

5import VSearch from './page/search.js';

6import VFavorites from './page/favorites.js';

7import VAccount from './page/account.js';

8

9export const state = {

10 app: null,

11 tab: 'search',

12 account: null,

13 station: null,

14 authenticated: false

15};

16

17(async () => {

18 state.locale = await http`get::/asset/json/locale.json`();

19

20 new Vue({

21 el: '#app',

22 data: {

23 state

24 },

25 components: {

26 VMenu,

27 VSearch,

28 VFavorites,

29 VAccount,

30 VPlayer,

31 VPopup

32 },

33 mounted() {

34 document.body.style.display = '';

35 state.app = this;

36 this.init();

37 },

38 methods: {

39 async init() {

40 try {

41 state.account = await http`get::/api/account`();

42 }

43 catch(error) {

44 // ignore

45 }

46 if(state.account === null) {

47 // TODO: create account or authenticate

48 return;

49 }

50 state.authenticated = true;

51 document.addEventListener('scroll', this.onScroll);

52 document.addEventListener('wheel', this.onScroll);

53 if('serviceWorker' in navigator) {

54 navigator.serviceWorker.register('/worker.js');

55 navigator.serviceWorker.addEventListener('controllerchange', this.updated);

56 }

57 },

58 showError(error) {

59 this.$refs.popup.open({

60 title: $lang('global.error'),

61 description: $lang('global.error.message', error),

62 actions: [

63 {

64 title: $lang('global.report'),

65 icon: 'message-report',

66 handle: () => window.open('https://github.com/typable/verbal/issues')

67 },

68 {

69 title: $lang('global.continue'),

70 icon: 'arrow-right',

71 handle: () => this.$refs.popup.close()

72 }

73 ]

74 });

75 },

76 updated() {

77 this.$refs.popup.open({

78 title: $lang('global.update'),

79 description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.',

80 actions: [

81 {

82 title: $lang('global.continue'),

83 icon: 'check',

84 handle: () => window.location.reload()

85 }

86 ]

87 });

88 },

89 onScroll() {

90 if(state.tab === 'search') {

91 if(window.innerHeight + window.pageYOffset >= document.body.offsetHeight - 200) {

92 if(this.$refs.search.searching) {

93 this.$refs.search.doSearchMore();

94 }

95 }

96 }

97 }

98 },

99 template: `

100 <div class="px-4 sm:px-10 pb-8 sm:pb-[100px] max-w-[1200px] mx-auto flex flex-col">

101 <v-menu :state="state"></v-menu>

102 <v-player v-if="state.authenticated" :station="state.station"></v-player>

103 <v-search v-if="state.authenticated" ref="search" :state="state"></v-search>

104 <v-favorites v-if="state.authenticated" ref="favorites" :state="state"></v-favorites>

105 <v-account v-if"state.authenticated" :state="state"></v-account>

106 <v-popup ref="popup"></v-popup>

107 </div>

108 `

109 });

110})();

111