ability to move attachments around when making a new post

This commit is contained in:
Henry Jameson 2021-08-15 21:04:49 +03:00
parent 830a03a0d1
commit 0507eb6550
7 changed files with 59 additions and 7 deletions

View file

@ -42,6 +42,8 @@ const Attachment = {
'size', 'size',
'setMedia', 'setMedia',
'remove', 'remove',
'shiftUp',
'shiftDn',
'edit' 'edit'
], ],
data () { data () {
@ -154,6 +156,12 @@ const Attachment = {
onRemove () { onRemove () {
this.remove && this.remove(this.attachment) this.remove && this.remove(this.attachment)
}, },
onShiftUp () {
this.shiftUp && this.shiftUp(this.attachment)
},
onShiftDn () {
this.shiftDn && this.shiftDn(this.attachment)
},
stopFlash () { stopFlash () {
this.$refs.flash.closePlayer() this.$refs.flash.closePlayer()
}, },

View file

@ -30,7 +30,7 @@
</button> </button>
</div> </div>
<div <div
v-if="size !== 'hide' && !hideDescription && (edit || localDescription)" v-if="size !== 'hide' && !hideDescription && (edit || localDescription || showDescription)"
class="description-container" class="description-container"
:class="{ '-static': !edit }" :class="{ '-static': !edit }"
> >
@ -83,6 +83,7 @@
v-if="type === 'flash' && flashLoaded" v-if="type === 'flash' && flashLoaded"
class="button-unstyled attachment-button" class="button-unstyled attachment-button"
@click.prevent="stopFlash" @click.prevent="stopFlash"
:title="$t('status.attachment_stop_flash')"
> >
<FAIcon icon="stop" /> <FAIcon icon="stop" />
</button> </button>
@ -98,6 +99,7 @@
v-if="!useModal" v-if="!useModal"
class="button-unstyled attachment-button" class="button-unstyled attachment-button"
@click.prevent="openModalForce" @click.prevent="openModalForce"
:title="$t('status.show_attachment_in_modal')"
> >
<FAIcon icon="search-plus" /> <FAIcon icon="search-plus" />
</button> </button>
@ -105,13 +107,31 @@
v-if="nsfw && hideNsfwLocal" v-if="nsfw && hideNsfwLocal"
class="button-unstyled attachment-button" class="button-unstyled attachment-button"
@click.prevent="toggleHidden" @click.prevent="toggleHidden"
:title="$t('status.hide_attachment')"
> >
<FAIcon icon="times" /> <FAIcon icon="times" />
</button> </button>
<button
v-if="shiftUp"
class="button-unstyled attachment-button"
@click.prevent="onShiftUp"
:title="$t('status.move_up')"
>
<FAIcon icon="chevron-left" />
</button>
<button
v-if="shiftDn"
class="button-unstyled attachment-button"
@click.prevent="onShiftDn"
:title="$t('status.move_down')"
>
<FAIcon icon="chevron-right" />
</button>
<button <button
v-if="remove" v-if="remove"
class="button-unstyled attachment-button" class="button-unstyled attachment-button"
@click.prevent="onRemove" @click.prevent="onRemove"
:title="$t('status.remove_attachment')"
> >
<FAIcon icon="trash-alt" /> <FAIcon icon="trash-alt" />
</button> </button>
@ -209,7 +229,7 @@
</span> </span>
</div> </div>
<div <div
v-if="size !== 'hide' && !hideDescription && (edit || localDescription)" v-if="size !== 'hide' && !hideDescription && (edit || (localDescription && showDescription))"
class="description-container" class="description-container"
:class="{ '-static': !edit }" :class="{ '-static': !edit }"
> >

View file

@ -12,6 +12,8 @@ const Gallery = {
'size', 'size',
'editable', 'editable',
'removeAttachment', 'removeAttachment',
'shiftUpAttachment',
'shiftDnAttachment',
'editAttachment', 'editAttachment',
'grid' 'grid'
], ],

View file

@ -6,8 +6,8 @@
> >
<div class="gallery-rows"> <div class="gallery-rows">
<div <div
v-for="(row, index) in rows" v-for="(row, rowIndex) in rows"
:key="index" :key="rowIndex"
class="gallery-row" class="gallery-row"
:style="rowStyle(row)" :style="rowStyle(row)"
:class="{ '-audio': row.audio, '-minimal': row.minimal, '-grid': grid }" :class="{ '-audio': row.audio, '-minimal': row.minimal, '-grid': grid }"
@ -16,8 +16,8 @@
class="gallery-row-inner" class="gallery-row-inner"
:class="{ '-grid': grid }" :class="{ '-grid': grid }"
> >
<attachment <Attachment
v-for="attachment in row.items" v-for="(attachment, attachmentIndex) in row.items"
:key="attachment.id" :key="attachment.id"
class="gallery-item" class="gallery-item"
:nsfw="nsfw" :nsfw="nsfw"
@ -26,6 +26,8 @@
:size="size" :size="size"
:editable="editable" :editable="editable"
:remove="removeAttachment" :remove="removeAttachment"
:shiftUp="!(attachmentIndex === 0 && rowIndex === 0) && shiftUpAttachment"
:shiftDn="!(attachmentIndex === row.items.length - 1 && rowIndex === rows.length - 1) && shiftDnAttachment"
:edit="editAttachment" :edit="editAttachment"
:description="descriptions && descriptions[attachment.id]" :description="descriptions && descriptions[attachment.id]"
:hide-description="size === 'small' || tooManyAttachments && hidingLong" :hide-description="size === 'small' || tooManyAttachments && hidingLong"

View file

@ -391,9 +391,20 @@ const PostStatusForm = {
this.$emit('resize') this.$emit('resize')
}, },
editAttachment (fileInfo, newText) { editAttachment (fileInfo, newText) {
console.log(fileInfo, newText)
this.newStatus.mediaDescriptions[fileInfo.id] = newText this.newStatus.mediaDescriptions[fileInfo.id] = newText
}, },
shiftUpMediaFile (fileInfo) {
const { files } = this.newStatus
const index = this.newStatus.files.indexOf(fileInfo)
files.splice(index, 1)
files.splice(index - 1, 0, fileInfo)
},
shiftDnMediaFile (fileInfo) {
const { files } = this.newStatus
const index = this.newStatus.files.indexOf(fileInfo)
files.splice(index, 1)
files.splice(index + 1, 0, fileInfo)
},
uploadFailed (errString, templateArgs) { uploadFailed (errString, templateArgs) {
templateArgs = templateArgs || {} templateArgs = templateArgs || {}
this.error = this.$t('upload.error.base') + ' ' + this.$t('upload.error.' + errString, templateArgs) this.error = this.$t('upload.error.base') + ' ' + this.$t('upload.error.' + errString, templateArgs)

View file

@ -298,6 +298,8 @@
:editable="true" :editable="true"
:edit-attachment="editAttachment" :edit-attachment="editAttachment"
:remove-attachment="removeMediaFile" :remove-attachment="removeMediaFile"
:shift-up-attachment="newStatus.files.length > 1 && shiftUpMediaFile"
:shift-dn-attachment="newStatus.files.length > 1 && shiftDnMediaFile"
@play="$emit('mediaplay', attachment.id)" @play="$emit('mediaplay', attachment.id)"
@pause="$emit('mediapause', attachment.id)" @pause="$emit('mediapause', attachment.id)"
/> />

View file

@ -721,6 +721,13 @@
"many_attachments": "Post has {number} attachment(s)", "many_attachments": "Post has {number} attachment(s)",
"collapse_attachments": "Collapse attachments", "collapse_attachments": "Collapse attachments",
"show_all_attachments": "Show all attachments", "show_all_attachments": "Show all attachments",
"show_attachment_in_modal": "Show in media modal",
"show_attachment_description": "Preview description (open attachment for full description)",
"hide_attachment": "Hide attachment",
"remove_attachment": "Remove attachment",
"attachment_stop_flash": "Stop Flash player",
"move_up": "Shift attachment left",
"move_down": "Shift attachment right",
"open_gallery": "Open gallery" "open_gallery": "Open gallery"
}, },
"user_card": { "user_card": {