File input fixes

This commit is contained in:
Jai A
2020-12-06 17:41:45 -07:00
parent 40eca1727e
commit 1ff3b83766
7 changed files with 101 additions and 34 deletions

View File

@@ -1,13 +1,13 @@
<template> <template>
<label class="button"> <label class="button" @drop.prevent="addFile" @dragover.prevent>
<span> <span>
{{ prompt }} {{ text }}
</span> </span>
<input <input
type="file" type="file"
:multiple="multiple" :multiple="multiple"
:accept="accept" :accept="accept"
@change="(files) => $emit('change', files)" @change="onChange"
/> />
</label> </label>
</template> </template>
@@ -29,6 +29,41 @@ export default {
default: null, 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)
},
},
} }
</script> </script>

View File

@@ -95,9 +95,7 @@
</div> </div>
</div> </div>
<div v-if="editMode" class="buttons"> <div v-if="editMode" class="buttons">
<nuxt-link class="button column" :to="'/mod/' + id + '/edit'"> <slot />
Edit
</nuxt-link>
</div> </div>
</div> </div>
</template> </template>

View File

@@ -18,6 +18,7 @@
Moderation Moderation
</nuxt-link> </nuxt-link>
</div> </div>
<m-footer class="footer" />
<client-only> <client-only>
<EthicalAd type="image" /> <EthicalAd type="image" />
</client-only> </client-only>
@@ -44,7 +45,20 @@
:edit-mode="true" :edit-mode="true"
:status="mod.status" :status="mod.status"
:is-modrinth="true" :is-modrinth="true"
/> >
<button
class="button column approve"
@click="changeModStatus(mod.id, 'approved')"
>
Approve
</button>
<button
class="button column reject"
@click="changeModStatus(mod.id, 'rejected')"
>
Reject
</button>
</ModCard>
<div class="section-header"> <div class="section-header">
<h3 class="column-grow-1">Versions</h3> <h3 class="column-grow-1">Versions</h3>
</div> </div>
@@ -82,11 +96,6 @@ export default {
config config
) )
res = await axios.get(
`https://api.modrinth.com/api/v1/mods?ids=${JSON.stringify(res.data)}`,
config
)
const mods = res.data const mods = res.data
res = await axios.get( res = await axios.get(
@@ -94,18 +103,32 @@ export default {
config config
) )
res = await axios.get(
`https://api.modrinth.com/api/v1/versions?ids=${JSON.stringify(
res.data
)}`,
config
)
return { return {
mods, mods,
versions: res.data, 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)
},
},
} }
</script> </script>
@@ -120,4 +143,8 @@ export default {
font-weight: var(--font-weight-extrabold); font-weight: var(--font-weight-extrabold);
} }
} }
.button {
margin: 0.25rem 0;
}
</style> </style>

View File

@@ -18,6 +18,7 @@
Moderation Moderation
</nuxt-link> </nuxt-link>
</div> </div>
<m-footer class="footer" />
<client-only> <client-only>
<EthicalAd type="image" /> <EthicalAd type="image" />
</client-only> </client-only>
@@ -47,7 +48,11 @@
:edit-mode="true" :edit-mode="true"
:status="mod.status" :status="mod.status"
:is-modrinth="true" :is-modrinth="true"
/> >
<nuxt-link class="button column" :to="'/mod/' + mod.id + '/edit'">
Edit
</nuxt-link>
</ModCard>
</div> </div>
</div> </div>
</div> </div>
@@ -57,6 +62,7 @@
import axios from 'axios' import axios from 'axios'
import EthicalAd from '@/components/EthicalAd' import EthicalAd from '@/components/EthicalAd'
import ModCard from '@/components/ProjectCard' import ModCard from '@/components/ProjectCard'
import MFooter from '@/components/MFooter'
import ModIcon from '~/assets/images/sidebar/mod.svg?inline' import ModIcon from '~/assets/images/sidebar/mod.svg?inline'
import ModerationIcon from '~/assets/images/sidebar/admin.svg?inline' import ModerationIcon from '~/assets/images/sidebar/admin.svg?inline'
@@ -67,6 +73,7 @@ export default {
ModCard, ModCard,
ModIcon, ModIcon,
ModerationIcon, ModerationIcon,
MFooter,
}, },
async asyncData(data) { async asyncData(data) {
const config = { const config = {

View File

@@ -393,7 +393,7 @@ export default {
license_id: this.license.short, license_id: this.license.short,
client_side: this.clientSideType.id, client_side: this.clientSideType.id,
server_side: this.serverSideType.id, server_side: this.serverSideType.id,
slug: this.mod.mod_slug, slug: this.mod.slug,
} }
if (this.isProcessing) { if (this.isProcessing) {
@@ -431,9 +431,9 @@ export default {
this.$nuxt.$loading.finish() this.$nuxt.$loading.finish()
}, },
showPreviewImage(e) { showPreviewImage(files) {
const reader = new FileReader() const reader = new FileReader()
this.icon = e.target.files[0] this.icon = files[0]
reader.readAsDataURL(this.icon) reader.readAsDataURL(this.icon)
reader.onload = (event) => { reader.onload = (event) => {

View File

@@ -280,12 +280,12 @@ export default {
} }
}, },
methods: { methods: {
updateVersionFiles(e) { updateVersionFiles(files) {
this.createdVersion.raw_files = e.target.files this.createdVersion.raw_files = files
const newFileParts = [] const newFileParts = []
for (let i = 0; i < e.target.files.length; i++) { for (let i = 0; i < files.length; i++) {
newFileParts.push(e.target.files[i].name.concat('-' + i)) newFileParts.push(files[i].name.concat('-' + i))
} }
this.createdVersion.file_parts = newFileParts this.createdVersion.file_parts = newFileParts

View File

@@ -434,8 +434,8 @@
placeholder="Select one" placeholder="Select one"
track-by="short" track-by="short"
label="name" label="name"
:options="availableLicenses"
:searchable="true" :searchable="true"
:options="availableLicenses"
:close-on-select="true" :close-on-select="true"
:show-labels="false" :show-labels="false"
/> />
@@ -627,9 +627,9 @@ export default {
this.$nuxt.$loading.finish() this.$nuxt.$loading.finish()
}, },
showPreviewImage(e) { showPreviewImage(files) {
const reader = new FileReader() const reader = new FileReader()
this.icon = e.target.files[0] this.icon = files[0]
reader.readAsDataURL(this.icon) reader.readAsDataURL(this.icon)
reader.onload = (event) => { reader.onload = (event) => {
@@ -637,12 +637,12 @@ export default {
} }
}, },
updateVersionFiles(e) { updateVersionFiles(files) {
this.versions[this.currentVersionIndex].raw_files = e.target.files this.versions[this.currentVersionIndex].raw_files = files
const newFileParts = [] const newFileParts = []
for (let i = 0; i < e.target.files.length; i++) { for (let i = 0; i < files.length; i++) {
newFileParts.push(e.target.files[i].name.concat('-' + i)) newFileParts.push(files[i].name.concat('-' + i))
} }
this.versions[this.currentVersionIndex].file_parts = newFileParts this.versions[this.currentVersionIndex].file_parts = newFileParts