diff --git a/src/editor/EditorContainer.vue b/src/editor/EditorContainer.vue index 35ab9d2f..fb06a160 100644 --- a/src/editor/EditorContainer.vue +++ b/src/editor/EditorContainer.vue @@ -2,21 +2,36 @@ import FileSelector from './FileSelector.vue' import Message from '../Message.vue' import { debounce } from '../utils' -import { inject, ref } from 'vue' +import { inject, ref, watch } from 'vue' import { Store } from '../store' import MessageToggle from './MessageToggle.vue' import type { EditorComponentType } from './types' +const SHOW_ERROR_KEY = 'repl_show_error' + const props = defineProps<{ editorComponent: EditorComponentType }>() const store = inject('store') as Store -const showMessage = ref(true) +const showMessage = ref(getItem()) const onChange = debounce((code: string) => { store.state.activeFile.code = code }, 250) + +function setItem() { + localStorage.setItem(SHOW_ERROR_KEY, showMessage.value ? 'true' : 'false') +} + +function getItem() { + const item = localStorage.getItem(SHOW_ERROR_KEY) + return !(item === 'false') +} + +watch(showMessage, () => { + setItem() +})