add automatic updating

This commit is contained in:
Shpuld Shpuldson 2020-06-28 15:14:01 +03:00
parent 0287d5c07e
commit 3c47036101
2 changed files with 13 additions and 8 deletions

View file

@ -6,7 +6,7 @@ import PollForm from '../poll/poll_form.vue'
import StatusContent from '../status_content/status_content.vue' import StatusContent from '../status_content/status_content.vue'
import fileTypeService from '../../services/file_type/file_type.service.js' import fileTypeService from '../../services/file_type/file_type.service.js'
import { findOffset } from '../../services/offset_finder/offset_finder.service.js' import { findOffset } from '../../services/offset_finder/offset_finder.service.js'
import { reject, map, uniqBy } from 'lodash' import { reject, map, uniqBy, debounce } from 'lodash'
import suggestor from '../emoji_input/suggestor.js' import suggestor from '../emoji_input/suggestor.js'
import { mapGetters } from 'vuex' import { mapGetters } from 'vuex'
import Checkbox from '../checkbox/checkbox.vue' import Checkbox from '../checkbox/checkbox.vue'
@ -228,6 +228,7 @@ const PostStatusForm = {
el.style.height = 'auto' el.style.height = 'auto'
el.style.height = undefined el.style.height = undefined
this.error = null this.error = null
this.closePreview()
} else { } else {
this.error = data.error this.error = data.error
} }
@ -262,16 +263,25 @@ const PostStatusForm = {
this.previewLoading = false this.previewLoading = false
}) })
}, },
debouncePreviewStatus: debounce(function (newStatus) {
this.previewStatus(newStatus)
}, 750),
autoPreview () {
this.previewLoading = true
this.debouncePreviewStatus(this.newStatus)
},
closePreview () { closePreview () {
this.preview = null this.preview = null
this.previewLoading = false this.previewLoading = false
}, },
addMediaFile (fileInfo) { addMediaFile (fileInfo) {
this.newStatus.files.push(fileInfo) this.newStatus.files.push(fileInfo)
this.autoPreview()
}, },
removeMediaFile (fileInfo) { removeMediaFile (fileInfo) {
let index = this.newStatus.files.indexOf(fileInfo) let index = this.newStatus.files.indexOf(fileInfo)
this.newStatus.files.splice(index, 1) this.newStatus.files.splice(index, 1)
this.autoPreview()
}, },
uploadFailed (errString, templateArgs) { uploadFailed (errString, templateArgs) {
templateArgs = templateArgs || {} templateArgs = templateArgs || {}
@ -287,6 +297,7 @@ const PostStatusForm = {
return fileTypeService.fileType(fileInfo.mimetype) return fileTypeService.fileType(fileInfo.mimetype)
}, },
paste (e) { paste (e) {
this.autoPreview()
this.resize(e) this.resize(e)
if (e.clipboardData.files.length > 0) { if (e.clipboardData.files.length > 0) {
// prevent pasting of file as text // prevent pasting of file as text
@ -321,6 +332,7 @@ const PostStatusForm = {
} }
}, },
onEmojiInputInput (e) { onEmojiInputInput (e) {
this.autoPreview()
this.$nextTick(() => { this.$nextTick(() => {
this.resize(this.$refs['textarea']) this.resize(this.$refs['textarea'])
}) })

View file

@ -35,13 +35,6 @@
v-if="previewLoading" v-if="previewLoading"
class="icon-spin3 animate-spin" class="icon-spin3 animate-spin"
/> />
<a
v-else
class="preview-update"
@click.stop.prevent="previewStatus(newStatus)"
>
{{ $t('status.preview_update') }}
</a>
<a <a
class="preview-close" class="preview-close"
@click.stop.prevent="closePreview" @click.stop.prevent="closePreview"