Skip to content

Commit

Permalink
fix: issue with drafts not working correctly and not working after qu…
Browse files Browse the repository at this point in the history
…oting or editing a post
  • Loading branch information
akinsey committed Nov 15, 2021
1 parent bdaa3a1 commit 78291fd
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/components/layout/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ export default {
setup(props, { emit }) {
/* Internal Methods */
const cancel = () => {
v.quoteMode = false
v.editMode = false
if (props.postEditorMode && (props.post || props.quote)) closeEditor()
else emit('close')
}
Expand All @@ -257,13 +259,16 @@ export default {
v.newMessage = { receiver_ids: [], content: { subject: '', body: '' } }
v.threadCopy = { title: '', board_id: v.threadCopy?.data?.board.id }
if (props.postEditorMode) v.threadCopy.title = props?.thread?.title
v.quoteMode = false
v.editMode = false
emit('close')
}
const onPollValidation = ({ valid, poll }) => {
v.threadCopy.pollValid = valid
v.threadCopy.poll = poll
}
const saveDraft = clear => {
if (v.editMode || v.quoteMode) return
let rawText = v.posting.post.body || v.threadCopy.body || v.newMessage.content.body
v.draftTimeout = setTimeout(() => saveDraft(), 10000)
if (clear || rawText.length && v.oldDraft !== rawText) {
Expand All @@ -288,6 +293,7 @@ export default {
}
const loadDraft = () => {
if (v.editMode || v.quoteMode) return
let draftPromise
if (props.postEditorMode || props.threadEditorMode) {
draftPromise = postsApi.getPostDraft
Expand All @@ -305,6 +311,8 @@ export default {
/* View Data */
const v = reactive({
isMinimized: true,
quoteMode: false,
editMode: false,
threadCopy: props.thread || {},
fullscreen: false,
showFormatting: false,
Expand Down Expand Up @@ -355,12 +363,14 @@ export default {
if (p) {
p.title = 'RE:' + props.thread.title
nextTick(() => v.posting.post = p)
if (p.body.length) v.editMode = true
}
})
watch(() => props.quote, p => {
if (p && v.posting?.post?.body) nextTick(() => v.posting.post = { title: 'RE:' + props.thread, body: v.posting.post.body + p.body, thread_id: props.thread.id})
else if (p) nextTick(() => v.posting.post = { title: 'RE:' + props.thread, body: p.body, thread_id: props.thread.id})
if (p) v.quoteMode = true
nextTick(() => v.postEditorEl.focus())
})
Expand All @@ -378,13 +388,17 @@ export default {
})
else nextTick(() => v.messageEditorEl.focus())
}
if (visible && !props.quote && !v.posting.post.body.lenth) {
nextTick(() => {
nextTick(() => {
console.log(v.quoteMode, v.editMode)
if (visible && !v.editMode && !v.quoteMode) {
loadDraft()
saveDraft()
})
}
}
else {
clearTimeout(v.draftTimeout)
v.draftTimeout = null
}
})
})
return { ...toRefs(v), cancel, closeEditor, onPollValidation }
Expand Down

0 comments on commit 78291fd

Please sign in to comment.