fix(night-mode): migrate cookie solution to store only

Signed-off-by: Erik Michelson <michelson@uni-bremen.de>
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
Erik Michelson 2023-02-19 21:01:13 +01:00 committed by David Mehren
parent 9055214418
commit 057777f31f
3 changed files with 13 additions and 20 deletions

View file

@ -4,6 +4,7 @@
### Bugfixes
- Fix note titles with special characters producing invalid file names in user export zip file
- Fix night-mode toggle not working when page is loaded with night-mode enabled
## <i class="fa fa-tag"></i> 1.9.6 <i class="fa fa-calendar-o"></i> 2022-11-06

View file

@ -658,8 +658,13 @@ $(document).ready(function () {
})
}
if (Cookies.get('nightMode') !== undefined) {
store.set('nightMode', Cookies.get('nightMode') === 'true')
Cookies.remove('nightMode')
}
// Re-enable nightmode
if (store.get('nightMode') || Cookies.get('nightMode')) {
if (store.get('nightMode') === true) {
$body.addClass('night')
ui.toolbar.night.addClass('active')
}
@ -2084,24 +2089,12 @@ $('.ui-delete-modal-confirm').click(function () {
function toggleNightMode () {
const $body = $('body')
const isActive = ui.toolbar.night.hasClass('active')
if (isActive) {
$body.removeClass('night')
appState.nightMode = false
} else {
$body.addClass('night')
appState.nightMode = true
}
if (store.enabled) {
const isActive = store.get('nightMode') === true
$body.toggleClass('night', !isActive)
ui.toolbar.night.toggleClass('active', !isActive)
store.set('nightMode', !isActive)
} else {
Cookies.set('nightMode', !isActive, {
expires: 365,
sameSite: window.cookiePolicy,
secure: window.location.protocol === 'https:'
})
}
}
function emitPermission (_permission) {
if (_permission !== permission) {
socket.emit('permission', _permission)

View file

@ -2,8 +2,7 @@ import modeType from './modeType'
const state = {
syncscroll: true,
currentMode: modeType.view,
nightMode: false
currentMode: modeType.view
}
export default state