feat: store settings on cookie
This commit is contained in:
parent
87294d1881
commit
c137774b39
@ -8,9 +8,9 @@
|
|||||||
{{ t('repod', 'Playback speed') }}
|
{{ t('repod', 'Playback speed') }}
|
||||||
</label>
|
</label>
|
||||||
<div>
|
<div>
|
||||||
<Minus class="pointer" :size="20" @click="changeRate(-.5)" />
|
<Minus class="pointer" :size="20" @click="changeRate(player.rate - .5)" />
|
||||||
<NcCounterBubble>x{{ player.rate }}</NcCounterBubble>
|
<NcCounterBubble>x{{ player.rate }}</NcCounterBubble>
|
||||||
<Plus class="pointer" :size="20" @click="changeRate(.5)" />
|
<Plus class="pointer" :size="20" @click="changeRate(player.rate + .5)" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</NcAppNavigationSettings>
|
</NcAppNavigationSettings>
|
||||||
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { NcAppNavigationSettings, NcCounterBubble } from '@nextcloud/vue'
|
import { NcAppNavigationSettings, NcCounterBubble } from '@nextcloud/vue'
|
||||||
|
import { getSetting, setSetting } from '../../utils/cookie.js'
|
||||||
import Minus from 'vue-material-design-icons/Minus.vue'
|
import Minus from 'vue-material-design-icons/Minus.vue'
|
||||||
import Plus from 'vue-material-design-icons/Plus.vue'
|
import Plus from 'vue-material-design-icons/Plus.vue'
|
||||||
import Speedometer from 'vue-material-design-icons/Speedometer.vue'
|
import Speedometer from 'vue-material-design-icons/Speedometer.vue'
|
||||||
@ -40,10 +41,17 @@ export default {
|
|||||||
return this.$store.state.player
|
return this.$store.state.player
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
mounted() {
|
||||||
|
const rate = getSetting('rate')
|
||||||
|
if (rate) {
|
||||||
|
this.changeRate(rate)
|
||||||
|
}
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
changeRate(diff) {
|
changeRate(rate) {
|
||||||
if (this.player.rate + diff > 0) {
|
if (rate > 0) {
|
||||||
this.$store.dispatch('player/rate', this.player.rate + diff)
|
this.$store.dispatch('player/rate', rate)
|
||||||
|
setSetting('rate', rate)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
37
src/utils/cookie.js
Normal file
37
src/utils/cookie.js
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
// https://grafikart.fr/tutoriels/javascript-cookies-2079
|
||||||
|
const getCookie = (name) => {
|
||||||
|
const cookies = document.cookie.split('; ')
|
||||||
|
const value = cookies
|
||||||
|
.find(c => c.startsWith(name + '='))
|
||||||
|
?.split('=')[1]
|
||||||
|
if (value === undefined) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return decodeURIComponent(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
const setCookie = (name, value, days) => {
|
||||||
|
const date = new Date()
|
||||||
|
date.setDate(date.getDate() + days)
|
||||||
|
document.cookie = `${name}=${encodeURIComponent(value)}; Expires=${date.toUTCString()} SameSite=Strict;`
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getSetting = (name) => {
|
||||||
|
const cookie = getCookie('repod')
|
||||||
|
try {
|
||||||
|
const settings = JSON.parse(cookie) ?? {}
|
||||||
|
return settings[name]
|
||||||
|
} catch (e) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const setSetting = (name, value) => {
|
||||||
|
const cookie = getCookie('repod')
|
||||||
|
let settings = {}
|
||||||
|
try {
|
||||||
|
settings = JSON.parse(cookie) ?? {}
|
||||||
|
} catch (e) {}
|
||||||
|
settings[name] = value
|
||||||
|
setCookie('repod', JSON.stringify(settings), 100)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user