Skip to content

Commit ab4b7cd

Browse files
chenxchsxzz
andauthored
feat: memorize show error state (#117)
Co-authored-by: 三咲智子 Kevin Deng <sxzz@sxzz.moe>
1 parent 434d64a commit ab4b7cd

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/editor/EditorContainer.vue

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,36 @@
22
import FileSelector from './FileSelector.vue'
33
import Message from '../Message.vue'
44
import { debounce } from '../utils'
5-
import { inject, ref } from 'vue'
5+
import { inject, ref, watch } from 'vue'
66
import { Store } from '../store'
77
import MessageToggle from './MessageToggle.vue'
88
import type { EditorComponentType } from './types'
99
10+
const SHOW_ERROR_KEY = 'repl_show_error'
11+
1012
const props = defineProps<{
1113
editorComponent: EditorComponentType
1214
}>()
1315
1416
const store = inject('store') as Store
15-
const showMessage = ref(true)
17+
const showMessage = ref(getItem())
1618
1719
const onChange = debounce((code: string) => {
1820
store.state.activeFile.code = code
1921
}, 250)
22+
23+
function setItem() {
24+
localStorage.setItem(SHOW_ERROR_KEY, showMessage.value ? 'true' : 'false')
25+
}
26+
27+
function getItem() {
28+
const item = localStorage.getItem(SHOW_ERROR_KEY)
29+
return !(item === 'false')
30+
}
31+
32+
watch(showMessage, () => {
33+
setItem()
34+
})
2035
</script>
2136

2237
<template>

0 commit comments

Comments
 (0)