2020-04-28 18:42:22 +00:00
|
|
|
import ArtistTab from './components/artist-tab.js'
|
|
|
|
import TracklistTab from './components/tracklist-tab.js'
|
|
|
|
import LinkAnalyzerTab from './components/link-analyzer-tab.js'
|
2020-04-29 08:36:30 +00:00
|
|
|
import HomeTab from './components/home-tab.js'
|
2020-04-23 19:03:12 +00:00
|
|
|
import { socket } from './socket.js'
|
2020-04-28 18:42:22 +00:00
|
|
|
import SettingsTab from './components/settings-tab.js'
|
|
|
|
import MainSearch from './components/main-search.js'
|
|
|
|
import TrackPreview from './track-preview.js'
|
2020-04-23 19:03:12 +00:00
|
|
|
|
|
|
|
/* ===== Globals ====== */
|
|
|
|
window.search_selected = ''
|
|
|
|
window.main_selected = ''
|
|
|
|
window.windows_stack = []
|
|
|
|
|
|
|
|
/* ===== Locals ===== */
|
|
|
|
let currentStack = {}
|
|
|
|
|
2020-04-29 19:46:10 +00:00
|
|
|
// Exporting this function out of the default export
|
|
|
|
// because it's used in components that are needed
|
|
|
|
// in this file too
|
2020-04-23 19:03:12 +00:00
|
|
|
export function artistView(ev) {
|
|
|
|
let id = ev.currentTarget.dataset.id
|
|
|
|
ArtistTab.reset()
|
|
|
|
socket.emit('getTracklist', { type: 'artist', id: id })
|
|
|
|
showTab('artist', id)
|
|
|
|
}
|
|
|
|
|
2020-04-29 19:46:10 +00:00
|
|
|
// Exporting this function out of the default export
|
|
|
|
// because it's used in components that are needed
|
|
|
|
// in this file too
|
2020-04-23 19:03:12 +00:00
|
|
|
export function albumView(ev) {
|
|
|
|
let id = ev.currentTarget.dataset.id
|
|
|
|
TracklistTab.reset()
|
|
|
|
socket.emit('getTracklist', { type: 'album', id: id })
|
|
|
|
showTab('album', id)
|
|
|
|
}
|
|
|
|
|
2020-04-29 19:46:10 +00:00
|
|
|
// Exporting this function out of the default export
|
|
|
|
// because it's used in components that are needed
|
|
|
|
// in this file too
|
2020-04-23 19:03:12 +00:00
|
|
|
export function playlistView(ev) {
|
|
|
|
let id = ev.currentTarget.dataset.id
|
|
|
|
TracklistTab.reset()
|
|
|
|
socket.emit('getTracklist', { type: 'playlist', id: id })
|
|
|
|
showTab('playlist', id)
|
|
|
|
}
|
|
|
|
|
2020-04-28 18:42:22 +00:00
|
|
|
function analyzeLink(link) {
|
2020-04-26 17:33:09 +00:00
|
|
|
console.log('Analyzing: ' + link)
|
|
|
|
LinkAnalyzerTab.reset()
|
|
|
|
socket.emit('analyzeLink', link)
|
2020-04-26 12:27:54 +00:00
|
|
|
}
|
|
|
|
|
2020-04-28 18:42:22 +00:00
|
|
|
function linkListeners() {
|
|
|
|
document.getElementById('search_tab').addEventListener('click', handleTabClick)
|
|
|
|
document.getElementById('sidebar').addEventListener('click', handleSidebarClick)
|
2020-04-23 19:03:12 +00:00
|
|
|
|
2020-04-28 18:42:22 +00:00
|
|
|
const backButtons = Array.from(document.getElementsByClassName('back-button'))
|
2020-04-23 19:03:12 +00:00
|
|
|
|
2020-04-28 18:42:22 +00:00
|
|
|
backButtons.forEach(button => {
|
|
|
|
button.addEventListener('click', backTab)
|
|
|
|
})
|
2020-04-23 19:03:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles click Event on the sidebar and changes tab
|
|
|
|
* according to clicked icon.
|
|
|
|
* Uses event delegation
|
|
|
|
* @param {Event} event
|
|
|
|
* @since 0.1.0
|
|
|
|
*/
|
|
|
|
function handleSidebarClick(event) {
|
2020-04-24 19:54:12 +00:00
|
|
|
if (!(event.target.matches('.main_tablinks') || event.target.parentElement.matches('.main_tablinks'))) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
let sidebarEl = event.target.matches('.main_tablinks') ? event.target : event.target.parentElement
|
|
|
|
let targetID = sidebarEl.getAttribute('id')
|
2020-04-23 19:03:12 +00:00
|
|
|
|
|
|
|
switch (targetID) {
|
|
|
|
case 'main_search_tablink':
|
2020-04-24 19:54:12 +00:00
|
|
|
changeTab(sidebarEl, 'main', 'search_tab')
|
2020-04-23 19:03:12 +00:00
|
|
|
break
|
|
|
|
case 'main_home_tablink':
|
2020-04-24 19:54:12 +00:00
|
|
|
changeTab(sidebarEl, 'main', 'home_tab')
|
2020-04-23 19:03:12 +00:00
|
|
|
break
|
|
|
|
case 'main_charts_tablink':
|
2020-04-24 19:54:12 +00:00
|
|
|
changeTab(sidebarEl, 'main', 'charts_tab')
|
2020-04-23 19:03:12 +00:00
|
|
|
break
|
|
|
|
case 'main_favorites_tablink':
|
2020-04-24 19:54:12 +00:00
|
|
|
changeTab(sidebarEl, 'main', 'favorites_tab')
|
2020-04-23 19:03:12 +00:00
|
|
|
break
|
|
|
|
case 'main_analyzer_tablink':
|
2020-04-24 19:54:12 +00:00
|
|
|
changeTab(sidebarEl, 'main', 'analyzer_tab')
|
2020-04-23 19:03:12 +00:00
|
|
|
break
|
|
|
|
case 'main_settings_tablink':
|
2020-04-24 19:54:12 +00:00
|
|
|
changeTab(sidebarEl, 'main', 'settings_tab')
|
2020-04-23 19:03:12 +00:00
|
|
|
break
|
|
|
|
case 'main_about_tablink':
|
2020-04-24 19:54:12 +00:00
|
|
|
changeTab(sidebarEl, 'main', 'about_tab')
|
2020-04-23 19:03:12 +00:00
|
|
|
break
|
|
|
|
|
|
|
|
default:
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleTabClick(event) {
|
|
|
|
let targetID = event.target.id
|
|
|
|
|
|
|
|
switch (targetID) {
|
|
|
|
case 'search_all_tab':
|
2020-04-24 19:54:12 +00:00
|
|
|
changeTab(event.target, 'search', 'main_search')
|
2020-04-23 19:03:12 +00:00
|
|
|
break
|
|
|
|
case 'search_track_tab':
|
2020-04-24 19:54:12 +00:00
|
|
|
changeTab(event.target, 'search', 'track_search')
|
2020-04-23 19:03:12 +00:00
|
|
|
break
|
|
|
|
case 'search_album_tab':
|
2020-04-24 19:54:12 +00:00
|
|
|
changeTab(event.target, 'search', 'album_search')
|
2020-04-23 19:03:12 +00:00
|
|
|
break
|
|
|
|
case 'search_artist_tab':
|
2020-04-24 19:54:12 +00:00
|
|
|
changeTab(event.target, 'search', 'artist_search')
|
2020-04-23 19:03:12 +00:00
|
|
|
break
|
|
|
|
case 'search_playlist_tab':
|
2020-04-24 19:54:12 +00:00
|
|
|
changeTab(event.target, 'search', 'playlist_search')
|
2020-04-23 19:03:12 +00:00
|
|
|
break
|
|
|
|
|
|
|
|
default:
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-24 19:54:12 +00:00
|
|
|
function changeTab(sidebarEl, section, tabName) {
|
2020-04-23 19:03:12 +00:00
|
|
|
windows_stack = []
|
|
|
|
currentStack = {}
|
|
|
|
var i, tabcontent, tablinks
|
|
|
|
tabcontent = document.getElementsByClassName(section + '_tabcontent')
|
|
|
|
for (i = 0; i < tabcontent.length; i++) {
|
|
|
|
tabcontent[i].style.display = 'none'
|
|
|
|
}
|
|
|
|
tablinks = document.getElementsByClassName(section + '_tablinks')
|
|
|
|
for (i = 0; i < tablinks.length; i++) {
|
|
|
|
tablinks[i].classList.remove('active')
|
|
|
|
}
|
|
|
|
if (tabName == 'settings_tab' && main_selected != 'settings_tab') {
|
|
|
|
SettingsTab.settings = { ...SettingsTab.lastSettings }
|
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementById(tabName).style.display = 'block'
|
|
|
|
|
|
|
|
if ('main' === section) {
|
|
|
|
main_selected = tabName
|
|
|
|
} else if ('search' === section) {
|
|
|
|
search_selected = tabName
|
|
|
|
}
|
|
|
|
|
|
|
|
// Not choosing .currentTarget beacuse the event
|
|
|
|
// is delegated
|
2020-04-24 19:54:12 +00:00
|
|
|
sidebarEl.classList.add('active')
|
2020-04-23 19:03:12 +00:00
|
|
|
|
|
|
|
// Check if you need to load more content in the search tab
|
|
|
|
if (
|
|
|
|
main_selected == 'search_tab' &&
|
|
|
|
['track_search', 'album_search', 'artist_search', 'playlist_search'].indexOf(search_selected) != -1 &&
|
|
|
|
MainSearch.results[search_selected.split('_')[0] + 'Tab'].data.length == 0
|
|
|
|
) {
|
|
|
|
MainSearch.search(search_selected.split('_')[0])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function showTab(type, id, back = false) {
|
|
|
|
if (windows_stack.length == 0) {
|
|
|
|
windows_stack.push({ tab: main_selected })
|
|
|
|
} else if (!back) {
|
|
|
|
windows_stack.push(currentStack)
|
|
|
|
}
|
|
|
|
|
|
|
|
window.tab = type == 'artist' ? 'artist_tab' : 'tracklist_tab'
|
|
|
|
|
|
|
|
currentStack = { type: type, id: id }
|
|
|
|
let tabcontent = document.getElementsByClassName('main_tabcontent')
|
|
|
|
|
|
|
|
for (let i = 0; i < tabcontent.length; i++) {
|
|
|
|
tabcontent[i].style.display = 'none'
|
|
|
|
}
|
|
|
|
document.getElementById(tab).style.display = 'block'
|
2020-04-28 18:42:22 +00:00
|
|
|
TrackPreview.stopStackedTabsPreview()
|
2020-04-23 19:03:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function backTab() {
|
|
|
|
if (windows_stack.length == 1) {
|
|
|
|
document.getElementById(`main_${main_selected}link`).click()
|
|
|
|
} else {
|
|
|
|
let tabObj = windows_stack.pop()
|
|
|
|
if (tabObj.type == 'artist') {
|
|
|
|
ArtistTab.reset()
|
|
|
|
} else {
|
|
|
|
TracklistTab.reset()
|
|
|
|
}
|
|
|
|
socket.emit('getTracklist', { type: tabObj.type, id: tabObj.id })
|
|
|
|
showTab(tabObj.type, tabObj.id, true)
|
|
|
|
}
|
2020-04-28 18:42:22 +00:00
|
|
|
TrackPreview.stopStackedTabsPreview()
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
linkListeners,
|
|
|
|
artistView,
|
|
|
|
albumView,
|
|
|
|
playlistView,
|
|
|
|
analyzeLink
|
2020-04-23 19:03:12 +00:00
|
|
|
}
|