Allow uploading single emojis from URL

This commit is contained in:
Ekaterina Vaartis 2025-08-06 20:02:15 +03:00 committed by vaartis
commit ec635426c3
2 changed files with 50 additions and 21 deletions

View file

@ -27,17 +27,26 @@
class="emoji" class="emoji"
/> />
<div <div v-if="newUpload" class="emoji-tab-popover-new-upload">
v-if="newUpload" <h4>{{ $t('admin_dash.emoji.emoji_source') }}</h4>
class="emoji-tab-popover-input"
> <div class="emoji-tab-popover-input">
<input <input
type="file" type="file"
accept="image/*" accept="image/*"
class="emoji-tab-popover-file input" class="emoji-tab-popover-file input"
@change="uploadFile = $event.target.files" @change="uploadFile = $event.target.files"
> >
</div>
<div class="emoji-tab-popover-input ">
<input
v-model="uploadURL"
:placeholder="$t('admin_dash.emoji.upload_url')"
class="emoji-data-input input"
>
</div>
</div> </div>
<div> <div>
<div class="emoji-tab-popover-input"> <div class="emoji-tab-popover-input">
<label> <label>
@ -62,11 +71,14 @@
</label> </label>
</div> </div>
<div class="emoji-tab-popover-input" v-if="remote !== undefined"> <div
v-if="remote !== undefined"
class="emoji-tab-popover-input"
>
<label> <label>
{{ $t('admin_dash.emoji.copy_to') }} {{ $t('admin_dash.emoji.copy_to') }}
<Select <SelectComponent
v-model="copyToPack" v-model="copyToPack"
class="form-control" class="form-control"
> >
@ -84,7 +96,7 @@
> >
{{ listPackName }} {{ listPackName }}
</option> </option>
</Select> </SelectComponent>
</label> </label>
</div> </div>
@ -97,7 +109,7 @@
class="button button-default btn" class="button button-default btn"
type="button" type="button"
:disabled="saveButtonDisabled" :disabled="saveButtonDisabled"
@click="(newUpload || this.remote !== undefined) ? uploadEmoji() : saveEditedEmoji()" @click="(newUpload || remote !== undefined) ? uploadEmoji() : saveEditedEmoji()"
> >
{{ $t('admin_dash.emoji.save') }} {{ $t('admin_dash.emoji.save') }}
</button> </button>
@ -137,10 +149,10 @@
import Popover from 'components/popover/popover.vue' import Popover from 'components/popover/popover.vue'
import ConfirmModal from 'components/confirm_modal/confirm_modal.vue' import ConfirmModal from 'components/confirm_modal/confirm_modal.vue'
import StillImage from 'components/still-image/still-image.vue' import StillImage from 'components/still-image/still-image.vue'
import Select from 'components/select/select.vue' import SelectComponent from 'components/select/select.vue'
export default { export default {
components: { Popover, ConfirmModal, StillImage, Select }, components: { Popover, ConfirmModal, StillImage, SelectComponent },
inject: ['emojiAddr'], inject: ['emojiAddr'],
props: { props: {
placement: { placement: {
@ -171,16 +183,19 @@ export default {
// Only exists for emojis from remote packs // Only exists for emojis from remote packs
remote: { remote: {
type: Object type: Object,
default: undefined
}, },
knownLocalPacks: { knownLocalPacks: {
type: Object type: Object,
default: undefined
} }
}, },
emits: ['updatePackFiles', 'displayError'], emits: ['updatePackFiles', 'displayError'],
data () { data () {
return { return {
uploadFile: [], uploadFile: [],
uploadURL: "",
editedShortcode: this.shortcode, editedShortcode: this.shortcode,
editedFile: this.file, editedFile: this.file,
deleteModalVisible: false, deleteModalVisible: false,
@ -191,6 +206,8 @@ export default {
emojiPreview () { emojiPreview () {
if (this.newUpload && this.uploadFile.length > 0) { if (this.newUpload && this.uploadFile.length > 0) {
return URL.createObjectURL(this.uploadFile[0]) return URL.createObjectURL(this.uploadFile[0])
} else if (this.newUpload && this.uploadURL != "") {
return this.uploadURL
} else if (!this.newUpload) { } else if (!this.newUpload) {
return this.emojiAddr(this.file) return this.emojiAddr(this.file)
} }
@ -202,7 +219,7 @@ export default {
}, },
saveButtonDisabled() { saveButtonDisabled() {
if (this.remote === undefined) if (this.remote === undefined)
return this.newUpload ? this.uploadFile.length == 0 : !this.isEdited return this.newUpload ? (this.uploadURL === "" && this.uploadFile.length == 0) : !this.isEdited
else else
return this.copyToPack === "" return this.copyToPack === ""
} }
@ -226,7 +243,8 @@ export default {
let packName = this.remote === undefined ? this.packName : this.copyToPack let packName = this.remote === undefined ? this.packName : this.copyToPack
this.$store.state.api.backendInteractor.addNewEmojiFile({ this.$store.state.api.backendInteractor.addNewEmojiFile({
packName: packName, packName: packName,
file: this.remote === undefined ? this.uploadFile[0] : this.emojiAddr(this.file), file: this.remote === undefined ?
(this.uploadURL !== "" ? this.uploadURL : this.uploadFile[0]) : this.emojiAddr(this.file),
shortcode: this.editedShortcode, shortcode: this.editedShortcode,
filename: this.editedFile filename: this.editedFile
}).then(resp => resp.json()).then(resp => { }).then(resp => resp.json()).then(resp => {
@ -271,13 +289,22 @@ export default {
padding-right: 0.5em; padding-right: 0.5em;
padding-bottom: 0.5em; padding-bottom: 0.5em;
.emoji-tab-popover-new-upload {
margin-bottom: 2em;
}
.emoji { .emoji {
width: 32px; width: 32px;
height: 32px; height: 32px;
} }
.Select { .SelectComponent {
display: inline-block; display: inline-block;
} }
h4 {
margin-bottom: 1em;
margin-top: 1em;
}
} }
</style> </style>

View file

@ -1205,6 +1205,8 @@
"adding_new": "Adding new emoji", "adding_new": "Adding new emoji",
"shortcode": "Shortcode", "shortcode": "Shortcode",
"filename": "Filename", "filename": "Filename",
"emoji_source": "Emoji file source",
"upload_url": "Upload from URL",
"new_shortcode": "Shortcode, leave blank to infer", "new_shortcode": "Shortcode, leave blank to infer",
"new_filename": "Filename, leave blank to infer", "new_filename": "Filename, leave blank to infer",
"delete_confirm": "Are you sure you want to delete {0}?", "delete_confirm": "Are you sure you want to delete {0}?",