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 ### Bugfixes
- Fix note titles with special characters producing invalid file names in user export zip file - 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 ## <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 // Re-enable nightmode
if (store.get('nightMode') || Cookies.get('nightMode')) { if (store.get('nightMode') === true) {
$body.addClass('night') $body.addClass('night')
ui.toolbar.night.addClass('active') ui.toolbar.night.addClass('active')
} }
@ -2084,24 +2089,12 @@ $('.ui-delete-modal-confirm').click(function () {
function toggleNightMode () { function toggleNightMode () {
const $body = $('body') const $body = $('body')
const isActive = ui.toolbar.night.hasClass('active') const isActive = store.get('nightMode') === true
if (isActive) { $body.toggleClass('night', !isActive)
$body.removeClass('night') ui.toolbar.night.toggleClass('active', !isActive)
appState.nightMode = false
} else {
$body.addClass('night')
appState.nightMode = true
}
if (store.enabled) {
store.set('nightMode', !isActive) store.set('nightMode', !isActive)
} else {
Cookies.set('nightMode', !isActive, {
expires: 365,
sameSite: window.cookiePolicy,
secure: window.location.protocol === 'https:'
})
}
} }
function emitPermission (_permission) { function emitPermission (_permission) {
if (_permission !== permission) { if (_permission !== permission) {
socket.emit('permission', _permission) socket.emit('permission', _permission)

View file

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