mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-19 13:19:41 +02:00
* automated docs update * recipe rating component * recipe partial updates - closes #25 * use Vue.delete to update store * format * arrow functions * fix tests * format * initial context menu * localize * add confirmation dialog * context menu * fix bare exception * update line length * format all file with prettier * update changelog * download as json * update python dependencies * update javascript dependencies Co-authored-by: hay-kot <hay-kot@pm.me>
79 lines
1.6 KiB
Vue
79 lines
1.6 KiB
Vue
<template>
|
|
<v-form ref="file">
|
|
<input ref="uploader" class="d-none" type="file" @change="onFileChanged" />
|
|
<v-btn :loading="isSelecting" @click="onButtonClick" color="accent" :text="textBtn">
|
|
<v-icon left> {{ icon }}</v-icon>
|
|
{{ text ? text : defaultText }}
|
|
</v-btn>
|
|
</v-form>
|
|
</template>
|
|
|
|
<script>
|
|
const UPLOAD_EVENT = "uploaded";
|
|
import { api } from "@/api";
|
|
export default {
|
|
props: {
|
|
post: {
|
|
type: Boolean,
|
|
default: true,
|
|
},
|
|
url: String,
|
|
text: String,
|
|
icon: { default: "mdi-cloud-upload" },
|
|
fileName: { default: "archive" },
|
|
textBtn: {
|
|
default: true,
|
|
},
|
|
},
|
|
data: () => ({
|
|
file: null,
|
|
isSelecting: false,
|
|
}),
|
|
|
|
computed: {
|
|
defaultText() {
|
|
return this.$t("general.upload");
|
|
},
|
|
},
|
|
|
|
methods: {
|
|
async upload() {
|
|
if (this.file != null) {
|
|
this.isSelecting = true;
|
|
|
|
if (!this.post) {
|
|
this.$emit(UPLOAD_EVENT, this.file);
|
|
this.isSelecting = false;
|
|
return;
|
|
}
|
|
|
|
let formData = new FormData();
|
|
formData.append(this.fileName, this.file);
|
|
|
|
if (await api.utils.uploadFile(this.url, formData)) {
|
|
this.$emit(UPLOAD_EVENT);
|
|
}
|
|
this.isSelecting = false;
|
|
}
|
|
},
|
|
onButtonClick() {
|
|
this.isSelecting = true;
|
|
window.addEventListener(
|
|
"focus",
|
|
() => {
|
|
this.isSelecting = false;
|
|
},
|
|
{ once: true }
|
|
);
|
|
|
|
this.$refs.uploader.click();
|
|
},
|
|
onFileChanged(e) {
|
|
this.file = e.target.files[0];
|
|
this.upload();
|
|
},
|
|
},
|
|
};
|
|
</script>
|
|
|
|
<style></style>
|