2020-04-28 18:42:22 +00:00
|
|
|
import { toast } from '../toasts.js'
|
|
|
|
import { socket } from '../socket.js'
|
2020-04-21 20:20:19 +00:00
|
|
|
|
2020-04-22 20:06:59 +00:00
|
|
|
const SettingsTab = new Vue({
|
2020-05-03 20:08:59 +00:00
|
|
|
data: () => ({
|
|
|
|
settings: { tags: {} },
|
|
|
|
lastSettings: {},
|
|
|
|
spotifyFeatures: {},
|
2020-05-05 13:08:04 +00:00
|
|
|
lastCredentials: {},
|
|
|
|
defaultSettings: {},
|
|
|
|
lastUser: '',
|
|
|
|
spotifyUser: ''
|
2020-05-03 20:08:59 +00:00
|
|
|
}),
|
|
|
|
computed: {
|
|
|
|
darkMode: {
|
|
|
|
get() {
|
|
|
|
return 'true' === localStorage.getItem('darkMode')
|
|
|
|
},
|
|
|
|
set(wantDarkMode) {
|
|
|
|
document.documentElement.setAttribute('data-theme', wantDarkMode ? 'dark' : 'default')
|
|
|
|
localStorage.setItem('darkMode', wantDarkMode)
|
|
|
|
}
|
2020-05-05 11:07:34 +00:00
|
|
|
},
|
|
|
|
slimDownloads: {
|
|
|
|
get() {
|
|
|
|
return 'true' === localStorage.getItem('slimDownloads')
|
|
|
|
},
|
|
|
|
set(wantSlimDownloads) {
|
|
|
|
if (wantSlimDownloads)
|
|
|
|
document.getElementById("download_list").classList.add("slim")
|
|
|
|
else
|
|
|
|
document.getElementById("download_list").classList.remove("slim")
|
|
|
|
localStorage.setItem('slimDownloads', wantSlimDownloads)
|
|
|
|
}
|
2020-04-21 20:20:19 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
copyARLtoClipboard() {
|
|
|
|
let copyText = this.$refs.loginInput
|
|
|
|
|
|
|
|
copyText.setAttribute('type', 'text')
|
|
|
|
copyText.select()
|
|
|
|
copyText.setSelectionRange(0, 99999)
|
|
|
|
document.execCommand('copy')
|
|
|
|
copyText.setAttribute('type', 'password')
|
|
|
|
|
|
|
|
toast('ARL copied to clipboard', 'assignment')
|
|
|
|
},
|
|
|
|
saveSettings() {
|
2020-04-23 19:03:12 +00:00
|
|
|
this.lastSettings = { ...SettingsTab.settings }
|
|
|
|
this.lastCredentials = { ...SettingsTab.spotifyFeatures }
|
2020-05-05 13:08:04 +00:00
|
|
|
let changed = false
|
|
|
|
if (this.lastUser != this.spotifyUser){
|
|
|
|
// force cloning without linking
|
|
|
|
this.lastUser = (' ' + this.spotifyUser).slice(1)
|
|
|
|
localStorage.setItem('spotifyUser', this.lastUser)
|
|
|
|
changed = true
|
|
|
|
}
|
|
|
|
socket.emit('saveSettings', this.lastSettings, this.lastCredentials, changed ? this.lastUser : false)
|
2020-04-23 19:03:12 +00:00
|
|
|
},
|
2020-05-03 20:08:59 +00:00
|
|
|
loadSettings(settings, spotifyCredentials, defaults = null) {
|
2020-05-03 15:02:31 +00:00
|
|
|
if (defaults) this.defaultSettings = { ...defaults }
|
2020-04-23 19:03:12 +00:00
|
|
|
this.lastSettings = { ...settings }
|
|
|
|
this.lastCredentials = { ...spotifyCredentials }
|
|
|
|
this.settings = settings
|
|
|
|
this.spotifyFeatures = spotifyCredentials
|
2020-04-21 20:20:19 +00:00
|
|
|
},
|
|
|
|
login() {
|
|
|
|
let arl = this.$refs.loginInput.value
|
|
|
|
if (arl != '' && arl != localStorage.getItem('arl')) {
|
|
|
|
socket.emit('login', arl, true)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
logout() {
|
|
|
|
socket.emit('logout')
|
2020-04-23 19:03:12 +00:00
|
|
|
},
|
2020-05-03 14:21:37 +00:00
|
|
|
initSettings(settings, credentials, defaults) {
|
|
|
|
this.loadSettings(settings, credentials, defaults)
|
2020-04-23 19:03:12 +00:00
|
|
|
toast('Settings loaded!', 'settings')
|
|
|
|
},
|
|
|
|
updateSettings(settings, credentials) {
|
|
|
|
this.loadSettings(settings, credentials)
|
|
|
|
toast('Settings updated!', 'settings')
|
2020-05-03 14:21:37 +00:00
|
|
|
},
|
2020-05-03 20:08:59 +00:00
|
|
|
resetSettings() {
|
2020-05-03 15:02:31 +00:00
|
|
|
this.settings = { ...this.defaultSettings }
|
|
|
|
}
|
2020-04-23 19:03:12 +00:00
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
socket.on('init_settings', this.initSettings)
|
|
|
|
socket.on('updateSettings', this.updateSettings)
|
2020-05-05 13:08:04 +00:00
|
|
|
let spotyUser = localStorage.getItem('spotifyUser')
|
|
|
|
if (spotyUser){
|
|
|
|
this.lastUser = spotyUser
|
|
|
|
this.spotifyUser = spotyUser
|
|
|
|
}
|
2020-04-21 20:20:19 +00:00
|
|
|
}
|
|
|
|
}).$mount('#settings_tab')
|
|
|
|
|
2020-04-22 20:06:59 +00:00
|
|
|
export default SettingsTab
|