2020-05-07 20:10:13 +00:00
|
|
|
import $ from 'jquery'
|
2020-04-22 20:06:59 +00:00
|
|
|
import { socket } from './modules/socket.js'
|
|
|
|
import { toast } from './modules/toasts.js'
|
|
|
|
import Downloads from './modules/downloads.js'
|
|
|
|
import QualityModal from './modules/quality-modal.js'
|
2020-04-28 18:42:22 +00:00
|
|
|
import Tabs from './modules/tabs.js'
|
2020-04-23 19:03:12 +00:00
|
|
|
import Search from './modules/search.js'
|
2020-04-28 18:42:22 +00:00
|
|
|
import TrackPreview from './modules/track-preview.js'
|
2020-04-19 20:02:06 +00:00
|
|
|
|
|
|
|
/* ===== Socketio listeners ===== */
|
|
|
|
|
|
|
|
// Debug messages for socketio
|
|
|
|
socket.on('message', function (msg) {
|
|
|
|
console.log(msg)
|
|
|
|
})
|
|
|
|
|
|
|
|
socket.on('logging_in', function () {
|
|
|
|
toast('Logging in', 'loading', false, 'login-toast')
|
|
|
|
})
|
|
|
|
|
2020-05-14 11:32:02 +00:00
|
|
|
socket.on('init_autologin', function() {
|
|
|
|
let arl = localStorage.getItem('arl')
|
|
|
|
if (arl) socket.emit('login', arl)
|
|
|
|
})
|
|
|
|
|
2020-04-19 20:02:06 +00:00
|
|
|
socket.on('logged_in', function (data) {
|
|
|
|
switch (data.status) {
|
|
|
|
case 1:
|
|
|
|
case 3:
|
|
|
|
toast('Logged in', 'done', true, 'login-toast')
|
|
|
|
if (data.arl) {
|
|
|
|
localStorage.setItem('arl', data.arl)
|
|
|
|
$('#login_input_arl').val(data.arl)
|
|
|
|
}
|
|
|
|
$('#open_login_prompt').hide()
|
|
|
|
if (data.user) {
|
|
|
|
$('#settings_username').text(data.user.name)
|
|
|
|
$('#settings_picture').attr(
|
|
|
|
'src',
|
|
|
|
`https://e-cdns-images.dzcdn.net/images/user/${data.user.picture}/125x125-000000-80-0-0.jpg`
|
|
|
|
)
|
2020-04-29 19:46:10 +00:00
|
|
|
// $('#logged_in_info').show()
|
|
|
|
document.getElementById('logged_in_info').classList.remove('hide')
|
2020-04-19 20:02:06 +00:00
|
|
|
}
|
2020-05-09 12:45:28 +00:00
|
|
|
document.getElementById('home_not_logged_in').classList.add('hide')
|
2020-04-19 20:02:06 +00:00
|
|
|
break
|
|
|
|
case 2:
|
|
|
|
toast('Already logged in', 'done', true, 'login-toast')
|
|
|
|
if (data.user) {
|
|
|
|
$('#settings_username').text(data.user.name)
|
|
|
|
$('#settings_picture').attr(
|
|
|
|
'src',
|
|
|
|
`https://e-cdns-images.dzcdn.net/images/user/${data.user.picture}/125x125-000000-80-0-0.jpg`
|
|
|
|
)
|
2020-04-29 19:46:10 +00:00
|
|
|
// $('#logged_in_info').show()
|
|
|
|
document.getElementById('logged_in_info').classList.remove('hide')
|
2020-04-19 20:02:06 +00:00
|
|
|
}
|
2020-05-09 12:45:28 +00:00
|
|
|
document.getElementById('home_not_logged_in').classList.add('hide')
|
2020-04-19 20:02:06 +00:00
|
|
|
break
|
|
|
|
case 0:
|
|
|
|
toast("Couldn't log in", 'close', true, 'login-toast')
|
|
|
|
localStorage.removeItem('arl')
|
|
|
|
$('#login_input_arl').val('')
|
|
|
|
$('#open_login_prompt').show()
|
2020-04-29 19:46:10 +00:00
|
|
|
document.getElementById('logged_in_info').classList.add('hide')
|
|
|
|
// $('#logged_in_info').hide()
|
2020-04-19 20:02:06 +00:00
|
|
|
$('#settings_username').text('Not Logged')
|
|
|
|
$('#settings_picture').attr('src', `https://e-cdns-images.dzcdn.net/images/user/125x125-000000-80-0-0.jpg`)
|
2020-05-09 12:45:28 +00:00
|
|
|
document.getElementById('home_not_logged_in').classList.remove('hide')
|
2020-04-19 20:02:06 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
socket.on('logged_out', function () {
|
|
|
|
toast('Logged out', 'done', true, 'login-toast')
|
|
|
|
localStorage.removeItem('arl')
|
|
|
|
$('#login_input_arl').val('')
|
|
|
|
$('#open_login_prompt').show()
|
2020-04-29 19:46:10 +00:00
|
|
|
document.getElementById('logged_in_info').classList.add('hide')
|
|
|
|
// $('#logged_in_info').hide()
|
2020-04-19 20:02:06 +00:00
|
|
|
$('#settings_username').text('Not Logged')
|
|
|
|
$('#settings_picture').attr('src', `https://e-cdns-images.dzcdn.net/images/user/125x125-000000-80-0-0.jpg`)
|
2020-05-09 12:45:28 +00:00
|
|
|
document.getElementById('home_not_logged_in').classList.remove('hide')
|
2020-04-19 20:02:06 +00:00
|
|
|
})
|
|
|
|
|
2020-04-21 20:20:19 +00:00
|
|
|
/* ===== App initialization ===== */
|
2020-04-23 19:03:12 +00:00
|
|
|
function startApp() {
|
2020-04-26 17:33:09 +00:00
|
|
|
Downloads.init()
|
2020-04-22 20:06:59 +00:00
|
|
|
QualityModal.init()
|
2020-04-23 19:03:12 +00:00
|
|
|
Tabs.linkListeners()
|
|
|
|
Search.linkListeners()
|
2020-04-28 18:42:22 +00:00
|
|
|
TrackPreview.init()
|
2020-04-19 20:02:06 +00:00
|
|
|
|
2020-05-13 20:17:43 +00:00
|
|
|
if ('true' === localStorage.getItem('darkMode')) {
|
|
|
|
document.querySelector('.theme_toggler.active').classList.remove('active')
|
|
|
|
document.querySelector('.theme_toggler#dark').classList.add('active')
|
|
|
|
}
|
|
|
|
|
2020-05-02 12:36:12 +00:00
|
|
|
document.getElementById('logged_in_info').classList.add('hide')
|
|
|
|
|
2020-04-19 20:02:06 +00:00
|
|
|
if (localStorage.getItem('arl')) {
|
|
|
|
let arl = localStorage.getItem('arl')
|
|
|
|
|
|
|
|
$('#login_input_arl').val(arl)
|
2020-05-09 12:45:28 +00:00
|
|
|
document.getElementById('home_not_logged_in').classList.add('hide')
|
2020-04-19 20:02:06 +00:00
|
|
|
}
|
2020-05-13 20:17:43 +00:00
|
|
|
|
2020-05-05 11:07:34 +00:00
|
|
|
if ('true' === localStorage.getItem('slimDownloads')) {
|
2020-05-05 20:27:37 +00:00
|
|
|
document.getElementById('download_list').classList.add('slim')
|
2020-05-05 11:07:34 +00:00
|
|
|
}
|
2020-05-13 20:17:43 +00:00
|
|
|
|
2020-05-05 13:08:04 +00:00
|
|
|
let spotifyUser = localStorage.getItem('spotifyUser')
|
2020-05-13 20:17:43 +00:00
|
|
|
|
2020-05-05 20:27:37 +00:00
|
|
|
if (spotifyUser != '') {
|
2020-05-05 13:08:04 +00:00
|
|
|
socket.emit('update_userSpotifyPlaylists', spotifyUser)
|
|
|
|
}
|
2020-04-19 20:02:06 +00:00
|
|
|
// Open default tab
|
|
|
|
document.getElementById('main_home_tablink').click()
|
|
|
|
}
|
|
|
|
|
2020-04-23 19:03:12 +00:00
|
|
|
document.addEventListener('DOMContentLoaded', startApp)
|