A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
blob: 249dad8a230d8f1fe23f7694f0df98be6cb016c2 (2285 bytes)[doc][blame][raw]
1
import {http} from './utils.js';2
import VMenu from './component/menu.js';3
import VPlayer from './component/player.js';4
import VSearch from './page/search.js';5
import VFavorites from './page/favorites.js';6
import VAccount from './page/account.js';8
export const state = {9
app: null,10
tab: 'search',11
account: {12
username: '',13
language: 'en'14
},15
station: null16
};18
(async () => {19
state.locale = await http`get::/asset/json/locale.json`();21
new Vue({22
el: '#app',23
data: {24
state25
},26
components: {27
VMenu,28
VSearch,29
VFavorites,30
VAccount,31
VPlayer32
},33
mounted() {34
document.body.style.display = '';35
state.app = this;36
this.init();37
},38
methods: {39
async init() {40
window.app = this;41
state.account = await http`get::/api/account`();42
document.addEventListener('scroll', this.onScroll);43
document.addEventListener('wheel', this.onScroll);44
if('serviceWorker' in navigator) {45
navigator.serviceWorker.register('/worker.js');46
navigator.serviceWorker.addEventListener('controllerchange', this.updated);47
}48
},49
updated() {50
// TODO: show update popup51
},52
onScroll() {53
if(state.tab === 'search') {54
if(window.innerHeight + window.pageYOffset >= document.body.offsetHeight - 200) {55
if(this.$refs.search.searching) {56
this.$refs.search.doSearchMore();57
}58
}59
}60
}61
},62
template: `63
<div class="px-4 sm:px-10 pb-8 sm:pb-[100px] max-w-[1200px] mx-auto flex flex-col">64
<v-menu :state="state"></v-menu>65
<v-player :station="state.station"></v-player>66
<v-search ref="search" :state="state"></v-search>67
<v-favorites ref="favorites" :state="state"></v-favorites>68
<v-account :state="state"></v-account>69
</div>70
`71
});72
})();