File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed
report-viewer/report-viewer/src/stores Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -7,10 +7,18 @@ import {
7
7
FileSortingOptions
8
8
} from '@jplag/ui-components/widget'
9
9
import { defineStore } from 'pinia'
10
- import { ref } from 'vue'
10
+ import { computed , ref } from 'vue'
11
11
12
12
export const uiStore = defineStore ( 'uiStore' , ( ) => {
13
- const useDarkMode = ref ( false )
13
+ const _useDarkMode = ref ( getDefaultUseDarkModeOption ( ) )
14
+ const useDarkMode = computed ( {
15
+ get : ( ) => _useDarkMode . value ,
16
+ set : ( v : boolean ) => {
17
+ localStorage . setItem ( USE_DARK_MODE_KEYWORD , v ? 'true' : 'false' )
18
+ _useDarkMode . value = v
19
+ }
20
+ } )
21
+
14
22
const distributionChartConfig = ref < DistributionChartConfig > ( {
15
23
metric : MetricJsonIdentifier . AVERAGE_SIMILARITY ,
16
24
xScale : 'linear' ,
@@ -31,3 +39,14 @@ export const uiStore = defineStore('uiStore', () => {
31
39
fileSorting
32
40
}
33
41
} )
42
+
43
+ const USE_DARK_MODE_KEYWORD = 'jplag:use-dark-mode'
44
+
45
+ function getDefaultUseDarkModeOption ( ) {
46
+ const local = localStorage . getItem ( USE_DARK_MODE_KEYWORD )
47
+ if ( local !== null ) {
48
+ return local === 'true'
49
+ }
50
+
51
+ return window . matchMedia && window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches
52
+ }
You can’t perform that action at this time.
0 commit comments