made startApp function cleaner, updated package name to 0.1.6 because of alpha 5 release , updated README.md

This commit is contained in:
Roberto Tonino
2020-05-15 22:21:31 +02:00
parent f371aa157a
commit cf3331d94b
9 changed files with 130 additions and 106 deletions

View File

@@ -7,6 +7,39 @@ import Tabs from './modules/tabs.js'
import Search from './modules/search.js'
import TrackPreview from './modules/track-preview.js'
/* ===== App initialization ===== */
function startApp() {
// Setting current theme
setUserTheme()
Downloads.init()
QualityModal.init()
Tabs.init()
Search.linkListeners()
TrackPreview.init()
}
document.addEventListener('DOMContentLoaded', startApp)
/* ===== General functions ===== */
/**
* Sets the current theme according to
* the localStorage saved theme.
* @since 0.1.6
*/
function setUserTheme() {
let selectedTheme = localStorage.getItem('selectedTheme')
if (selectedTheme) {
let activeClass = 'theme_toggler--active'
document.querySelector(`.${activeClass}`).classList.remove(activeClass)
document.querySelector(`.theme_toggler[data-theme-variant="${selectedTheme}"]`).classList.add(activeClass)
}
}
/* ===== Socketio listeners ===== */
// Debug messages for socketio
@@ -77,40 +110,7 @@ socket.on('logged_out', function () {
$('#login_input_arl').val('')
$('#open_login_prompt').show()
document.getElementById('logged_in_info').classList.add('hide')
// $('#logged_in_info').hide()
$('#settings_username').text('Not Logged')
$('#settings_picture').attr('src', `https://e-cdns-images.dzcdn.net/images/user/125x125-000000-80-0-0.jpg`)
document.getElementById('home_not_logged_in').classList.remove('hide')
})
/* ===== App initialization ===== */
function startApp() {
Downloads.init()
QualityModal.init()
Tabs.init()
Search.linkListeners()
TrackPreview.init()
document.getElementById('logged_in_info').classList.add('hide')
if (localStorage.getItem('arl')) {
let arl = localStorage.getItem('arl')
$('#login_input_arl').val(arl)
document.getElementById('home_not_logged_in').classList.add('hide')
}
if ('true' === localStorage.getItem('slimDownloads')) {
document.getElementById('download_list').classList.add('slim')
}
let spotifyUser = localStorage.getItem('spotifyUser')
if (spotifyUser != '') {
socket.emit('update_userSpotifyPlaylists', spotifyUser)
}
// Open default tab
document.getElementById('main_home_tablink').click()
}
document.addEventListener('DOMContentLoaded', startApp)

View File

@@ -17,8 +17,8 @@ const HomeTab = new Vue({
artistView,
albumView,
playlistView,
openSettings(e){
document.getElementById("main_settings_tablink").click()
openSettings(e) {
document.getElementById('main_settings_tablink').click()
},
addToQueue(e) {
e.stopPropagation()
@@ -33,6 +33,10 @@ const HomeTab = new Vue({
}
},
mounted() {
if (localStorage.getItem('arl')) {
this.$refs.notLogged.classList.add('hide')
}
socket.on('init_home', this.initHome)
}
}).$mount('#home_tab')

View File

@@ -82,17 +82,24 @@ const SettingsTab = new Vue({
}
},
mounted() {
socket.on('init_settings', this.initSettings)
socket.on('updateSettings', this.updateSettings)
this.$refs.loggedInInfo.classList.add('hide')
let spotyUser = localStorage.getItem('spotifyUser')
if (localStorage.getItem('arl')) {
this.$refs.loginInput.value = localStorage.getItem('arl')
}
if ('' !== spotyUser) {
this.lastUser = spotyUser
this.spotifyUser = spotyUser
let spotifyUser = localStorage.getItem('spotifyUser')
if (spotifyUser) {
this.lastUser = spotifyUser
this.spotifyUser = spotifyUser
socket.emit('update_userSpotifyPlaylists', spotifyUser)
}
this.changeSlimDownloads = 'true' === localStorage.getItem('slimDownloads')
socket.on('init_settings', this.initSettings)
socket.on('updateSettings', this.updateSettings)
}
}).$mount('#settings_tab')

View File

@@ -20,6 +20,11 @@ function init() {
listEl = document.getElementById('download_list')
dragHandlerEl = document.getElementById('download_tab_drag_handler')
// Check if download tab has slim entries
if ('true' === localStorage.getItem('slimDownloads')) {
listEl.classList.add('slim')
}
// Check if download tab should be open
if ('true' === localStorage.getItem('downloadTabOpen')) {
tabContainerEl.classList.remove('tab_hidden')
@@ -104,8 +109,8 @@ function addToQueue(queueItem, current = false) {
} else {
if (queue.indexOf(queueItem.uuid) == -1) queue.push(queueItem.uuid)
}
let queueDOM = document.getElementById("download_"+queueItem.uuid)
if (typeof(queueDOM) == 'undefined' || queueDOM == null){
let queueDOM = document.getElementById('download_' + queueItem.uuid)
if (typeof queueDOM == 'undefined' || queueDOM == null) {
$(listEl).append(
`<div class="download_object" id="download_${queueItem.uuid}" data-deezerid="${queueItem.id}">
<div class="download_info">

View File

@@ -101,6 +101,7 @@ function handleSidebarClick(event) {
changeTab(sidebarEl, 'main', 'search_tab')
break
case 'main_home_tablink':
console.log('al laod', sidebarEl)
changeTab(sidebarEl, 'main', 'home_tab')
break
case 'main_charts_tablink':
@@ -269,20 +270,15 @@ function backTab() {
}
function init() {
let selectedTheme = localStorage.getItem('selectedTheme')
if (selectedTheme) {
document.querySelector('.theme_toggler--active').classList.remove('theme_toggler--active')
document
.querySelector(`.theme_toggler[data-theme-variant="${selectedTheme}"]`)
.classList.add('theme_toggler--active')
}
// Open default tab
changeTab(document.getElementById('main_home_tablink'), 'main', 'home_tab')
linkListeners()
}
export default {
init,
changeTab,
artistView,
albumView,
playlistView,