You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
2.2 KiB
Vue

<template>
<NuxtLayout name="edit">
<template #content>
<div class="mb-2 flex w-full">
<el-input
v-model="note.title"
placeholder="untitled"
@change="submit()" />
</div>
<el-tabs type="border-card">
<el-tab-pane label="Text">
<el-input
v-model="input"
:autosize="{ minRows: 40 }"
type="textarea"
placeholder="Please input" />
</el-tab-pane>
<el-tab-pane label="Markdown">
<CardMarkdownRenderer
:content="note.description"
:state="'description'" />
</el-tab-pane>
</el-tabs>
</template>
</NuxtLayout>
</template>
<script setup lang="ts">
definePageMeta({
middleware: ['auth'],
})
import 'highlight.js/styles/github-dark-dimmed.css'
type Mode = 'text' | 'md'
const note = useNote()
const route = useRoute()
const router = useRouter()
const isLoading = ref<Boolean>(false)
const isSubmitting = ref<Boolean>(false)
const isDeleting = ref<Boolean>(false)
const comp = ref<Mode>('text')
const { textarea: noteTextArea, input } = useTextareaAutosize()
const toggleComp = (name: Mode) => {
comp.value = name
}
const { refresh } = await useFetch('/api/note', {
method: 'GET',
query: {
id: route.params.id,
},
onResponse({ response }) {
console.log('Response: ', response)
if (response.status === 500) {
console.log(`Error: ${response._data.message}`)
router.push('/notes')
return
}
note.value.title = response._data.note.title
note.value.description = response._data.note.description
input.value = note.value.description
},
})
const submitTimeout = ref()
const submit = async () => {
isSubmitting.value = true
if (submitTimeout.value) clearTimeout(submitTimeout.value)
submitTimeout.value = setTimeout(async () => {
await submitNote(note.value, route.params.id)
isSubmitting.value = false
}, 1000)
}
const remove = async () => {
isDeleting.value = true
await deleteNote(route.params.id)
isDeleting.value = false
}
onMounted(() => {
isLoading.value = true
refresh()
isLoading.value = false
})
watch(
() => input.value,
() => {
note.value.description = input.value
}
)
</script>
<style scoped>
:deep(.el-tabs__header) {
position: sticky;
top: 0;
z-index: 100;
}
</style>