feat: possibility to deactivate logs and saving this choice to localStorage

This commit is contained in:
Roberto Tonino 2021-06-04 23:16:19 +02:00
parent d12d18874e
commit 0f35bd5478
7 changed files with 59 additions and 13 deletions

File diff suppressed because one or more lines are too long

View File

@ -24,7 +24,7 @@ import { computed } from '@vue/composition-api'
export default { export default {
name: 'Logs', name: 'Logs',
setup() { setup() {
const messages = useLogs() const { messages } = useLogs()
const logMessages = computed(() => messages.value.slice(0, 50).reverse()) const logMessages = computed(() => messages.value.slice(0, 50).reverse())
return { return {

View File

@ -52,6 +52,7 @@ import { formatSingleTrack, formatAlbums, formatArtist, formatPlaylist } from '@
import { standardizeData } from '@/data/standardize' import { standardizeData } from '@/data/standardize'
import { useMainSearch } from '@/use/main-search' import { useMainSearch } from '@/use/main-search'
import { useSearch } from '@/use/search' import { useSearch } from '@/use/search'
import { useLogs } from '@/use/logs'
const resetObj = { data: [], next: 0, total: 0, hasLoaded: false } const resetObj = { data: [], next: 0, total: 0, hasLoaded: false }

View File

@ -98,6 +98,20 @@
</ul> </ul>
</div> </div>
<BaseAccordion class="settings-group">
<template #title>
<h3 class="settings-group__header">
<i class="material-icons">description</i>
{{ $t('settings.logs.title') }}
</h3>
</template>
<label class="with-checkbox">
<input v-model="areLogsActive" type="checkbox" />
<span class="checkbox-text">{{ $t('settings.logs.areLogsActive') }}</span>
</label>
</BaseAccordion>
<BaseAccordion class="settings-group"> <BaseAccordion class="settings-group">
<template #title> <template #title>
<h3 class="settings-group__header"> <h3 class="settings-group__header">
@ -807,12 +821,18 @@ import BaseAccordion from '@/components/globals/BaseAccordion.vue'
import TemplateVariablesList from '@components/settings/TemplateVariablesList.vue' import TemplateVariablesList from '@components/settings/TemplateVariablesList.vue'
import { fetchData, postToServer } from '@/utils/api' import { fetchData, postToServer } from '@/utils/api'
import { getFormItem } from '@/utils/forms' import { getFormItem } from '@/utils/forms'
import { useLogs } from '@/use/logs'
export default { export default {
components: { components: {
BaseAccordion, BaseAccordion,
TemplateVariablesList TemplateVariablesList
}, },
setup() {
const { areLogsActive, saveLogsSettings } = useLogs()
return { areLogsActive, saveLogsSettings }
},
data() { data() {
return { return {
flags, flags,
@ -951,6 +971,8 @@ export default {
localStorage.setItem('locale', newLocale) localStorage.setItem('locale', newLocale)
}, },
saveSettings() { saveSettings() {
this.saveLogsSettings()
this.lastSettings = JSON.parse(JSON.stringify(this.settings)) this.lastSettings = JSON.parse(JSON.stringify(this.settings))
this.lastCredentials = JSON.parse(JSON.stringify(this.spotifyFeatures)) this.lastCredentials = JSON.parse(JSON.stringify(this.spotifyFeatures))

View File

@ -390,6 +390,10 @@ const en = {
update: 'Settings updated!', update: 'Settings updated!',
reset: 'Settings reset to default!', reset: 'Settings reset to default!',
ARLcopied: 'ARL copied to clipboard' ARLcopied: 'ARL copied to clipboard'
},
logs: {
title: 'Logs',
areLogsActive: 'Active'
} }
}, },
sidebar: { sidebar: {

View File

@ -393,6 +393,10 @@ const it = {
update: 'Impostazioni aggiornate!', update: 'Impostazioni aggiornate!',
reset: 'Impostazioni di default ripristinate!', reset: 'Impostazioni di default ripristinate!',
ARLcopied: 'ARL copiato negli appunti' ARLcopied: 'ARL copiato negli appunti'
},
logs: {
title: 'Log',
areLogsActive: 'Attivi'
} }
}, },
sidebar: { sidebar: {

View File

@ -1,14 +1,27 @@
import { ref } from '@vue/composition-api' import { ref, watch } from '@vue/composition-api'
import { socket } from '@/utils/socket' import { socket } from '@/utils/socket'
const messages = ref([]) const messages = ref([])
const cached = localStorage.getItem('areLogsActive')
const areLogsActive = ref(cached ? cached === 'true' : false)
const saveLogsSettings = () => {
localStorage.setItem('areLogsActive', areLogsActive.value)
}
socket.addEventListener('message', event => { socket.addEventListener('message', event => {
const newMessage = JSON.parse(event.data) if (!areLogsActive.value) {
return
}
const newMessage = JSON.parse(event.data)
messages.value.push(Object.freeze(newMessage)) messages.value.push(Object.freeze(newMessage))
}) })
export const useLogs = () => { export const useLogs = () => {
return messages return {
messages,
areLogsActive,
saveLogsSettings
}
} }