use localSetting to store a global state of user choices

This commit is contained in:
lesion
2023-02-03 21:55:33 +01:00
parent 3eacc7ea33
commit f2376997b8
6 changed files with 60 additions and 61 deletions

View File

@@ -4,7 +4,7 @@
ref='cal'
v-model='selectedDate'
title-position='left'
:is-dark="settings['theme.is_dark']"
:is-dark="is_dark"
:columns="!$vuetify.breakpoint.smAndDown ? 2 : 1"
@input='click'
@update:from-page='updatePage'
@@ -15,20 +15,14 @@
aria-label='Calendar'
is-expanded
is-inline)
//- template(v-slot="{ inputValue, inputEvents }")
v-btn#calendarButton(v-on='inputEvents' text tile :color='selectedDate ? "primary" : "" ') {{inputValue || $t('common.calendar')}}
v-icon(v-if='selectedDate' v-text='mdiClose' right small icon @click.prevent.stop='selectedDate = null')
v-icon(v-else v-text='mdiChevronDown' right small icon)
.calh.d-flex.justify-center.align-center(slot='placeholder')
v-progress-circular(indeterminate)
//- v-btn#calendarButton(text tile) {{$t('common.calendar')}}
//- v-icon(v-text='mdiChevronDown' right small icon)
</template>
</template>
<script>
import { mapState } from 'vuex'
import { mapState, mapGetters } from 'vuex'
import dayjs from 'dayjs'
import { mdiChevronDown, mdiClose } from '@mdi/js'
import { attributesFromEvents } from '../assets/helper'
@@ -46,6 +40,7 @@ export default {
},
computed: {
...mapState(['settings', 'events']),
...mapGetters(['is_dark']),
attributes () {
return attributesFromEvents(this.events)
}

View File

@@ -17,15 +17,13 @@ v-card.h-event.event.d-flex(itemscope itemtype="https://schema.org/Event")
</template>
<script>
import { mapState } from 'vuex'
import { mapGetters } from 'vuex'
import MyPicture from '~/components/MyPicture'
import { mdiRepeat, mdiCalendar, mdiMapMarker } from '@mdi/js'
export default {
data({ $store }) {
return { mdiRepeat, mdiMapMarker, mdiCalendar,
hide_thumbs: this.$cookies.get('theme.hide_thumbs') || $store.state.settings.hide_thumbs
}
return { mdiRepeat, mdiMapMarker, mdiCalendar }
},
components: {
MyPicture
@@ -34,6 +32,6 @@ export default {
event: { type: Object, default: () => ({}) },
lazy: Boolean
},
computed: mapState(['settings'])
computed: mapGetters(['hide_thumbs'])
}
</script>

View File

@@ -1,48 +1,31 @@
<template lang="pug">
div.p-0.m-0.d-flex.justify-end(:key='reload')
v-icon.ml-5(@click='_is_dark()' v-text='mdiContrastCircle')
v-icon.ml-5(@click='_hide_thumbs()' v-if="!hide_thumbs" v-text='!hide_thumbs_icon ? mdiViewList : mdiViewModule')
div.p-0.m-0.d-flex.justify-end
v-icon.ml-5(@click='toggleDark' v-text='mdiContrastCircle')
v-icon.ml-5(@click='toggleHideThumbs' v-text='hide_thumbs ? mdiViewList : mdiViewModule')
</template>
<script>
import { mapActions, mapState } from 'vuex'
import { mapActions, mapGetters } from 'vuex'
import { mdiViewModule, mdiViewList, mdiContrastCircle } from '@mdi/js'
export default {
name: 'ThemeView',
data ({ $store }) {
return {
mdiViewModule, mdiViewList, mdiContrastCircle,
hide_thumbs: $store.state.settings.hide_thumbs,
hide_thumbs_icon: $store.state.settings.hide_thumbs || this.$cookies.get('theme.hide_thumbs'),
reload: 0
}
data () {
return { mdiViewModule, mdiViewList, mdiContrastCircle }
},
computed: {
...mapGetters(['hide_thumbs', 'is_dark']),
},
methods: {
...mapState(['settings']),
async _is_dark() {
...mapActions(['setLocalSetting']),
async toggleDark() {
this.$vuetify.theme.dark = !this.$vuetify.theme.dark
await this.$cookies.set('theme.is_dark', this.$vuetify.theme.dark, {
path: '/',
maxAge: 60 * 60 * 24 * 7
})
},
async _hide_thumbs() {
let theme_hide_thumbs = await this.$cookies.get('theme.hide_thumbs')
if (theme_hide_thumbs != null) {
theme_hide_thumbs = !theme_hide_thumbs
} else {
theme_hide_thumbs = !this.settings.hide_thumbs
}
await this.$cookies.set('theme.hide_thumbs', theme_hide_thumbs, {
path: '/',
maxAge: 60 * 60 * 24 * 7
})
this.hide_thumbs_icon = theme_hide_thumbs
this.reload++
this.$root.$emit('layout_loaded', true)
this.setLocalSetting({ key: 'theme.is_dark', value: !this.is_dark })
},
async toggleHideThumbs() {
this.setLocalSetting({ key: 'hide_thumbs', value: !this.hide_thumbs })
}
}
}
</script>