Skip to content

Commit

Permalink
feat: memorize autoSave state (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
btea authored Sep 10, 2024
1 parent 46e6465 commit 666e0cd
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ import { useStore } from './composables/store'
const loading = ref(true)
const replRef = ref<InstanceType<typeof Repl>>()

const AUTO_SAVE_KEY = 'auto-save-state'
function getAutoSaveState() {
return JSON.parse(localStorage.getItem(AUTO_SAVE_KEY) || 'true')
}
function setAutoSaveState(value: boolean) {
localStorage.setItem(AUTO_SAVE_KEY, JSON.stringify(value))
}

const autoSave = ref(getAutoSaveState())

const previewOptions = {
headHTML: `
<script src="https://cdn.jsdelivr.net/npm/@unocss/runtime"><\/script>
Expand Down Expand Up @@ -55,12 +65,15 @@ watchEffect(() =>
const refreshPreview = () => {
replRef.value?.reload()
}

watch(autoSave, setAutoSaveState)
</script>

<template>
<div v-if="!loading" antialiased>
<Header :store="store" @refresh="refreshPreview" />
<Repl
v-model="autoSave"
ref="replRef"
:theme="dark ? 'dark' : 'light'"
:preview-theme="true"
Expand Down

0 comments on commit 666e0cd

Please sign in to comment.