A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
blob: 9d4301ef9abe2cef77522fabbc7de5e2305ada16 (4077 bytes)[doc][blame][raw]
1
import {http, $lang} from './utils.js';2
import VMenu from './component/menu.js';3
import VPlayer from './component/player.js';4
import VPopup from './component/popup.js';5
import VSearch from './page/search.js';6
import VFavorites from './page/favorites.js';7
import VAccount from './page/account.js';9
export const state = {10
app: null,11
tab: 'search',12
account: null,13
station: null,14
authenticated: false15
};17
(async () => {18
state.locale = await http`get::/asset/json/locale.json`();20
new Vue({21
el: '#app',22
data: {23
state24
},25
components: {26
VMenu,27
VSearch,28
VFavorites,29
VAccount,30
VPlayer,31
VPopup32
},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
// ignore45
}46
if(state.account === null) {47
// TODO: create account or authenticate48
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: 'arrow-right',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
})();