deemixer/public/js/modules/components/settings-tab.js

66 lines
1.7 KiB
JavaScript
Raw Normal View History

2020-04-28 18:42:22 +00:00
import { toast } from '../toasts.js'
import { socket } from '../socket.js'
const SettingsTab = new Vue({
data() {
return {
settings: { tags: {} },
2020-04-23 19:03:12 +00:00
lastSettings: {},
lastCredentials: {},
spotifyFeatures: {},
2020-05-03 15:02:31 +00:00
defaultSettings: {}
}
},
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 }
socket.emit('saveSettings', this.lastSettings, this.lastCredentials)
},
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
},
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
},
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 15:02:31 +00:00
resetSettings(){
this.settings = { ...this.defaultSettings }
}
2020-04-23 19:03:12 +00:00
},
mounted() {
socket.on('init_settings', this.initSettings)
socket.on('updateSettings', this.updateSettings)
}
}).$mount('#settings_tab')
export default SettingsTab