Skip to content

Commit ec32081

Browse files
committed
fix(desk): local-storage state state
1 parent 1ddbb9e commit ec32081

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

packages/desktop/composables/state.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@ function setLocalStorage(key: string, payload: any) {
2929
localStorage.setItem(key, value)
3030
}
3131

32-
function getLocalStorage<T = any>(key: string) {
32+
function getLocalStorage<T = any>(key: string, defaultValue?: any) {
3333
let value: any = localStorage.getItem(key)
3434

35+
if (value === null) {
36+
return defaultValue
37+
}
38+
3539
if (['true', 'false'].includes(value)) {
3640
value = value === 'true'
3741
}
@@ -45,7 +49,7 @@ function getLocalStorage<T = any>(key: string) {
4549

4650
export function useState<T = any>(key: string, defaultValue?: T, options?: Options) {
4751
if (options?.localStorage && !states.value.has(key)) {
48-
states.value.set(key, getLocalStorage(key) || defaultValue)
52+
states.value.set(key, getLocalStorage(key, defaultValue))
4953
}
5054

5155
if (!states.value.has(key)) {

packages/desktop/modules/layout/components/LDrawer.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
<script setup lang="ts">
22
import { computed } from 'vue'
33
4-
import { useState } from '@/composables/state'
54
import { useStore as useMenu } from '@/modules/menu/store'
65
import { useStore as useWorkspace } from '@/modules/workspace/store'
76
87
import LDrawerItem from './LDrawerItem.vue'
98
import { useI18n } from 'vue-i18n'
109
import Menu from '@core/entities/menu'
10+
import { useToggleDrawer } from '../composables/drawer'
1111
12-
const drawer = useState('app:drawer', true, {
13-
localStorage: true,
14-
})
12+
const drawer = useToggleDrawer()
1513
1614
// menu
1715
const tm = useI18n()

0 commit comments

Comments
 (0)