Skip to content

Commit 42fc770

Browse files
committed
feat: editor auto saving
1 parent 8239938 commit 42fc770

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

packages/client/internals/Editor.vue

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
<script setup lang="ts">
2-
import { useEventListener } from '@vueuse/core'
3-
import { computed, watch, ref, onMounted, onUnmounted } from 'vue'
2+
import { useEventListener, throttledWatch } from '@vueuse/core'
3+
import { computed, watch, ref, onMounted } from 'vue'
44
import { activeElement, showEditor, editorWidth } from '../state'
55
import { useCodeMirror } from '../setup/codemirror'
66
import { currentRoute, currentSlideId } from '../logic/nav'
77
import { useDynamicSlideInfo } from '../logic/note'
88
9-
const clicks = ref<'content' | 'note'>('content')
10-
const offsetRight = ref(0)
9+
const tab = ref<'content' | 'note'>('content')
1110
const content = ref('')
1211
const note = ref('')
1312
const dirty = ref(false)
@@ -85,20 +84,12 @@ onMounted(() => {
8584
)
8685
})
8786
88-
onMounted(() => {
89-
offsetRight.value = editorWidth.value
90-
})
91-
onUnmounted(() => {
92-
offsetRight.value = 0
93-
})
94-
9587
const handlerDown = ref(false)
9688
function onHandlerDown() {
9789
handlerDown.value = true
9890
}
9991
function updateWidth(v: number) {
10092
editorWidth.value = Math.min(Math.max(200, v), window.innerWidth - 200)
101-
offsetRight.value = editorWidth.value
10293
}
10394
useEventListener('pointermove', (e) => {
10495
if (handlerDown.value)
@@ -117,6 +108,15 @@ const editorLink = computed(() => {
117108
? `vscode://file/${slide.file}:${slide.start}`
118109
: undefined
119110
})
111+
112+
throttledWatch(
113+
[content, note],
114+
() => {
115+
if (dirty.value)
116+
save()
117+
},
118+
{ throttle: 500 },
119+
)
120120
</script>
121121

122122
<template>
@@ -132,20 +132,20 @@ const editorLink = computed(() => {
132132
>
133133
<div class="flex pb-2 text-xl -mt-1">
134134
<div class="mr-4 rounded flex">
135-
<button class="icon-btn" :class="clicks === 'content' ? 'text-primary' : ''" @click="clicks='content'">
135+
<button class="icon-btn" :class="tab === 'content' ? 'text-primary' : ''" @click="tab='content'">
136136
<carbon:account />
137137
</button>
138-
<button class="icon-btn" :class="clicks === 'note' ? 'text-primary' : ''" @click="clicks='note'">
138+
<button class="icon-btn" :class="tab === 'note' ? 'text-primary' : ''" @click="tab='note'">
139139
<carbon:align-box-bottom-right />
140140
</button>
141141
</div>
142142
<span class="text-2xl pt-1">
143-
{{ clicks === 'content' ? 'Slide' : 'Note' }}
143+
{{ tab === 'content' ? 'Slide' : 'Note' }}
144144
</span>
145145
<div class="flex-auto"></div>
146-
<button class="icon-btn" :class="{ disabled: !dirty }" @click="save">
146+
<!-- <button class="icon-btn" :class="{ disabled: !dirty }" @click="save">
147147
<carbon:save />
148-
</button>
148+
</button> -->
149149
<button class="icon-btn">
150150
<a :href="editorLink" target="_blank">
151151
<carbon:launch />
@@ -156,10 +156,10 @@ const editorLink = computed(() => {
156156
</button>
157157
</div>
158158
<div class="h-full overflow-auto">
159-
<div v-show="clicks === 'content'" class="h-full overflow-auto">
159+
<div v-show="tab === 'content'" class="h-full overflow-auto">
160160
<textarea ref="contentInput" />
161161
</div>
162-
<div v-show="clicks === 'note'" class="h-full overflow-auto">
162+
<div v-show="tab === 'note'" class="h-full overflow-auto">
163163
<textarea ref="noteInput" />
164164
</div>
165165
</div>

0 commit comments

Comments
 (0)