From 03710de7f8c39e9c9ea00b3d766387853ab617cd Mon Sep 17 00:00:00 2001 From: trba1810 Date: Fri, 25 Aug 2023 03:01:39 +0200 Subject: [PATCH] fixed issue with theme --- src/Web/Pages/wwwroot/js/theme.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Web/Pages/wwwroot/js/theme.js b/src/Web/Pages/wwwroot/js/theme.js index 3b90eda..548b187 100644 --- a/src/Web/Pages/wwwroot/js/theme.js +++ b/src/Web/Pages/wwwroot/js/theme.js @@ -1,6 +1,14 @@ -const theme = localStorage.getItem('theme') - ?? matchMedia('(prefers-color-scheme: dark)').matches +const choice = localStorage.getItem('theme'); +if (choice != null) { + document.body.setAttribute('data-theme', choice) +} +else { + const theme = localStorage.getItem('theme') + ?? matchMedia('(prefers-color-scheme: dark)').matches ? 'Dark' : 'Light'; -if (theme === 'Dark') { - document.body.setAttribute('data-theme', theme); -} \ No newline at end of file + if (theme === 'Dark') { + document.body.setAttribute('data-theme', theme); + } +} + +