Skip to content

Commit

Permalink
fix(storage): null typing in destr object
Browse files Browse the repository at this point in the history
  • Loading branch information
Novout committed Sep 5, 2022
1 parent 7650a0d commit eb8cc97
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/better-write-app/src/use/raw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ export const useRaw = () => {
}
}

const menu = async (e: MouseEvent, index: number) => {
const menu = async (e: MouseEvent | TouchEvent, index: number) => {
ABSOLUTE.entity.menu = false

EDITOR.actives.entity.index = index
Expand All @@ -450,7 +450,7 @@ export const useRaw = () => {
return
}

e?.preventDefault()
if (e) e?.preventDefault()

await nextTick

Expand Down
14 changes: 9 additions & 5 deletions packages/better-write-app/src/use/storage/local.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import destr from 'destr'
import { ProjectObject } from 'better-write-types'
import { Maybe, ProjectObject } from 'better-write-types'
import { useToast } from 'vue-toastification'
import { useEnv } from '../env'
import i18n from '@/lang'
Expand All @@ -22,8 +22,10 @@ export const useLocalStorage = () => {
localStorage.setItem(name, JSON.stringify(obj))
}

const get = (name: string) => {
return destr((localStorage as any).getItem(name))
const get = (name: string): Maybe<ProjectObject> => {
const item = localStorage.getItem(name)

return item ? destr(item) : undefined
}

const setProject = (obj: ProjectObject) => {
Expand All @@ -32,8 +34,10 @@ export const useLocalStorage = () => {
} catch (e) {}
}

const getProject = (): ProjectObject => {
return storage.support(get(env.projectLocalStorage()))
const getProject = (): Maybe<ProjectObject> => {
const project = get(env.projectLocalStorage())

return project ? storage.support(project) : undefined
}

const onSaveProject = async (event: boolean = true) => {
Expand Down

0 comments on commit eb8cc97

Please sign in to comment.