so://phie

verbal

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

blob: fb7bf20e9d0c212e446d9369dc10498137bb20f0 (5195 bytes)[doc][blame][raw]

1import Vue from '/asset/lib/vue.min.js';

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

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

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

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

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

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

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

9import VAuth from './page/auth.js';

10import VDetail from './component/detail.js';

11

12export const VERSION = '{{version}}';

13export const SWIPE_THRESHOLD = 70;

14export const TOKEN_NAME = 'verbal-token';

15

16export const state = {

17 app: null,

18 tab: 'search',

19 tabs: ['search', 'favorites', 'account'],

20 account: null,

21 devices: null,

22 token: null,

23 station: null,

24 authenticated: null,

25 version: VERSION

26};

27

28(async () => {

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

30 new Vue({

31 el: '#app',

32 data: {

33 state,

34 touch: null,

35 target: null

36 },

37 components: {

38 VMenu,

39 VSearch,

40 VFavorites,

41 VAccount,

42 VAuth,

43 VPlayer,

44 VPopup,

45 VDetail

46 },

47 mounted() {

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

49 state.app = this;

50 this.init();

51 },

52 methods: {

53 async init() {

54 try {

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

56 state.devices = await http`get::/api/devices`();

57 state.token = localStorage.getItem(TOKEN_NAME);

58 }

59 catch(err) {

60 state.account = null;

61 state.devices = null;

62 state.token = null;

63 }

64 state.tab = 'search';

65 state.station = null;

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

67 state.authenticated = false;

68 return;

69 }

70 state.authenticated = true;

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

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

73 document.addEventListener('touchmove', this.onScroll);

74 if('serviceWorker' in navigator) {

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

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

77 }

78 },

79 showError(error) {

80 this.$refs.popup.open({

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

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

83 actions: [

84 {

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

86 icon: 'message-report',

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

88 },

89 {

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

91 icon: 'arrow-right',

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

93 }

94 ]

95 });

96 },

97 updated() {

98 this.$refs.popup.open({

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

100 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.',

101 actions: [

102 {

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

104 icon: 'check',

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

106 }

107 ]

108 });

109 },

110 onScroll() {

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

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

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

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

115 }

116 }

117 }

118 }

119 },

120 template: `

121 <div

122 v-if="state.authenticated !== null"

123 class="px-4 sm:px-10 max-w-[1200px] mx-auto flex flex-col min-h-[100vh]"

124 >

125 <v-auth v-if="!state.authenticated" :state="state"></v-auth>

126 <v-menu v-if="state.authenticated" :state="state"></v-menu>

127 <div>

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

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

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

131 </div>

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

133 <v-detail ref="detail" v-if="state.authenticated"></v-detail>

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

135 </div>

136 `

137 });

138})();