From 1ff3b8376694353031972d281daeb76084e8d374 Mon Sep 17 00:00:00 2001 From: Jai A Date: Sun, 6 Dec 2020 17:41:45 -0700 Subject: [PATCH] File input fixes --- components/FileInput.vue | 41 ++++++++++++++++++++++++-- components/ProjectCard.vue | 4 +-- pages/dashboard/moderation.vue | 53 +++++++++++++++++++++++++--------- pages/dashboard/projects.vue | 9 +++++- pages/mod/_id/edit.vue | 6 ++-- pages/mod/_id/versions.vue | 8 ++--- pages/mod/create.vue | 14 ++++----- 7 files changed, 101 insertions(+), 34 deletions(-) diff --git a/components/FileInput.vue b/components/FileInput.vue index dc51c1a49..b864221a9 100644 --- a/components/FileInput.vue +++ b/components/FileInput.vue @@ -1,13 +1,13 @@ @@ -29,6 +29,41 @@ export default { default: null, }, }, + data() { + return { + text: this.prompt, + files: [], + } + }, + methods: { + onChange(files, shouldNotReset) { + if (!shouldNotReset) this.files = files.target.files + + const length = this.files.length + if (length === 0) { + this.text = this.prompt + } else if (length === 1) { + this.text = '1 file selected' + } else if (length > 1) { + this.text = length + ' files selected' + } + this.$emit('change', this.files) + }, + addFile(e) { + const droppedFiles = e.dataTransfer.files + + if (!this.multiple) this.files = [] + + if (!droppedFiles) return + ;[...droppedFiles].forEach((f) => { + this.files.push(f) + }) + + if (!this.multiple && this.files.length > 0) this.files = [this.files[0]] + + if (this.files.length > 0) this.onChange(null, true) + }, + }, } diff --git a/components/ProjectCard.vue b/components/ProjectCard.vue index 3edc9df2c..ea969cc50 100644 --- a/components/ProjectCard.vue +++ b/components/ProjectCard.vue @@ -95,9 +95,7 @@
- - Edit - +
diff --git a/pages/dashboard/moderation.vue b/pages/dashboard/moderation.vue index 82bf434ff..82114abeb 100644 --- a/pages/dashboard/moderation.vue +++ b/pages/dashboard/moderation.vue @@ -18,6 +18,7 @@ Moderation + @@ -44,7 +45,20 @@ :edit-mode="true" :status="mod.status" :is-modrinth="true" - /> + > + + +

Versions

@@ -82,11 +96,6 @@ export default { config ) - res = await axios.get( - `https://api.modrinth.com/api/v1/mods?ids=${JSON.stringify(res.data)}`, - config - ) - const mods = res.data res = await axios.get( @@ -94,18 +103,32 @@ export default { config ) - res = await axios.get( - `https://api.modrinth.com/api/v1/versions?ids=${JSON.stringify( - res.data - )}`, - config - ) - return { mods, versions: res.data, } }, + methods: { + async changeModStatus(id, status) { + const config = { + headers: { + Authorization: this.$auth.getToken('local') + ? this.$auth.getToken('local') + : '', + }, + } + + await axios.patch( + `https://api.modrinth.com/api/v1/mod/${id}`, + { + status, + }, + config + ) + + await this.$router.go(0) + }, + }, } @@ -120,4 +143,8 @@ export default { font-weight: var(--font-weight-extrabold); } } + +.button { + margin: 0.25rem 0; +} diff --git a/pages/dashboard/projects.vue b/pages/dashboard/projects.vue index df614501c..e457feb19 100644 --- a/pages/dashboard/projects.vue +++ b/pages/dashboard/projects.vue @@ -18,6 +18,7 @@ Moderation + @@ -47,7 +48,11 @@ :edit-mode="true" :status="mod.status" :is-modrinth="true" - /> + > + + Edit + + @@ -57,6 +62,7 @@ import axios from 'axios' import EthicalAd from '@/components/EthicalAd' import ModCard from '@/components/ProjectCard' +import MFooter from '@/components/MFooter' import ModIcon from '~/assets/images/sidebar/mod.svg?inline' import ModerationIcon from '~/assets/images/sidebar/admin.svg?inline' @@ -67,6 +73,7 @@ export default { ModCard, ModIcon, ModerationIcon, + MFooter, }, async asyncData(data) { const config = { diff --git a/pages/mod/_id/edit.vue b/pages/mod/_id/edit.vue index 9baef637f..95f629e17 100644 --- a/pages/mod/_id/edit.vue +++ b/pages/mod/_id/edit.vue @@ -393,7 +393,7 @@ export default { license_id: this.license.short, client_side: this.clientSideType.id, server_side: this.serverSideType.id, - slug: this.mod.mod_slug, + slug: this.mod.slug, } if (this.isProcessing) { @@ -431,9 +431,9 @@ export default { this.$nuxt.$loading.finish() }, - showPreviewImage(e) { + showPreviewImage(files) { const reader = new FileReader() - this.icon = e.target.files[0] + this.icon = files[0] reader.readAsDataURL(this.icon) reader.onload = (event) => { diff --git a/pages/mod/_id/versions.vue b/pages/mod/_id/versions.vue index bd75c2e86..dbc06f2d1 100644 --- a/pages/mod/_id/versions.vue +++ b/pages/mod/_id/versions.vue @@ -280,12 +280,12 @@ export default { } }, methods: { - updateVersionFiles(e) { - this.createdVersion.raw_files = e.target.files + updateVersionFiles(files) { + this.createdVersion.raw_files = files const newFileParts = [] - for (let i = 0; i < e.target.files.length; i++) { - newFileParts.push(e.target.files[i].name.concat('-' + i)) + for (let i = 0; i < files.length; i++) { + newFileParts.push(files[i].name.concat('-' + i)) } this.createdVersion.file_parts = newFileParts diff --git a/pages/mod/create.vue b/pages/mod/create.vue index 51e68c84b..4d9b7427f 100644 --- a/pages/mod/create.vue +++ b/pages/mod/create.vue @@ -434,8 +434,8 @@ placeholder="Select one" track-by="short" label="name" - :options="availableLicenses" :searchable="true" + :options="availableLicenses" :close-on-select="true" :show-labels="false" /> @@ -627,9 +627,9 @@ export default { this.$nuxt.$loading.finish() }, - showPreviewImage(e) { + showPreviewImage(files) { const reader = new FileReader() - this.icon = e.target.files[0] + this.icon = files[0] reader.readAsDataURL(this.icon) reader.onload = (event) => { @@ -637,12 +637,12 @@ export default { } }, - updateVersionFiles(e) { - this.versions[this.currentVersionIndex].raw_files = e.target.files + updateVersionFiles(files) { + this.versions[this.currentVersionIndex].raw_files = files const newFileParts = [] - for (let i = 0; i < e.target.files.length; i++) { - newFileParts.push(e.target.files[i].name.concat('-' + i)) + for (let i = 0; i < files.length; i++) { + newFileParts.push(files[i].name.concat('-' + i)) } this.versions[this.currentVersionIndex].file_parts = newFileParts