Move mod pages to nuxt child (#201)

* Move mod pages to nuxt child

* Minor fixes

* Fix lockfile
This commit is contained in:
Geometrically
2021-05-10 21:35:03 -07:00
committed by GitHub
parent d914b38f9f
commit 0e338ef453
10 changed files with 1070 additions and 1415 deletions

View File

@@ -1,17 +1,5 @@
<template>
<ModPage
:mod="mod"
:versions="versions"
:featured-versions="featuredVersions"
:members="members"
:current-member="currentMember"
:link-bar="[
['Versions', 'versions'],
[version.name, 'versions/' + version.id],
['Edit Version', 'versions/' + version.id + '/edit'],
]"
:user-follows="userFollows"
>
<div>
<div class="new-version">
<div class="controls">
<button class="brand-button" title="Save version" @click="saveVersion">
@@ -111,106 +99,87 @@
</div>
</div>
</div>
</ModPage>
</div>
</template>
<script>
import axios from 'axios'
import Multiselect from 'vue-multiselect'
import ModPage from '~/components/layout/ModPage'
export default {
components: {
ModPage,
Multiselect,
},
auth: false,
props: {
mod: {
type: Object,
default() {
return {}
},
},
versions: {
type: Array,
default() {
return []
},
},
members: {
type: Array,
default() {
return [{}]
},
},
currentMember: {
type: Object,
default() {
return null
},
},
},
async fetch() {
this.version = this.versions.find(
(x) => x.id === this.$route.params.version
)
if (!this.version.changelog && this.version.changelog_url) {
this.version.changelog = (
await axios.get(this.version.changelog_url)
).data
}
},
async asyncData(data) {
try {
const mod = (
await axios.get(
`https://api.modrinth.com/api/v1/mod/${data.params.id}`,
data.$auth.headers
)
).data
const [
members,
versions,
featuredVersions,
selectableLoaders,
selectableVersions,
userFollows,
] = (
const [selectableLoaders, selectableVersions] = (
await Promise.all([
axios.get(`https://api.modrinth.com/api/v1/team/${mod.team}/members`),
axios.get(`https://api.modrinth.com/api/v1/mod/${mod.id}/version`),
axios.get(
`https://api.modrinth.com/api/v1/mod/${mod.id}/version?featured=true`
),
axios.get(`https://api.modrinth.com/api/v1/tag/loader`),
axios.get(`https://api.modrinth.com/api/v1/tag/game_version`),
axios.get(
data.$auth.user
? `https://api.modrinth.com/api/v1/user/${data.$auth.user.id}/follows`
: `https://api.modrinth.com`,
data.$auth.headers
),
])
).map((it) => it.data)
const users = (
await axios.get(
`https://api.modrinth.com/api/v1/users?ids=${JSON.stringify(
members.map((it) => it.user_id)
)}`,
data.$auth.headers
)
).data
users.forEach((it) => {
const index = members.findIndex((x) => x.user_id === it.id)
members[index].avatar_url = it.avatar_url
members[index].name = it.username
})
const version = versions.find((x) => x.id === data.params.version)
version.author = members.find((x) => x.user_id === version.author_id)
let primaryFile = version.files.find((file) => file.primary)
if (!primaryFile) {
primaryFile = version.files[0]
}
const currentMember = data.$auth.user
? members.find((x) => x.user_id === data.$auth.user.id)
: null
if (!version.changelog && version.changelog_url) {
version.changelog = (await axios.get(version.changelog_url)).data
}
return {
mod,
versions,
featuredVersions,
members,
version,
primaryFile,
currentMember,
selectableLoaders,
selectableVersions,
userFollows: userFollows.name ? null : userFollows,
}
} catch {
data.error({
statusCode: 404,
message: 'Version not found',
message: 'Unable to fetch versions or loaders',
})
}
},
data() {
return {
version: {},
}
},
mounted() {
this.$emit('update:link-bar', [
['Versions', 'versions'],
[this.version.name, 'versions/' + this.version.id],
['Edit Version', 'versions/' + this.version.id + '/edit'],
])
},
methods: {
async saveVersion() {
this.$nuxt.$loading.start()
@@ -222,7 +191,9 @@ export default {
this.$auth.headers
)
await this.$router.replace(
`/mod/${this.mod.id}/version/${this.version.id}`
`/mod/${this.mod.slug ? this.mod.slug : this.mod.id}/version/${
this.version.id
}`
)
} catch (err) {
this.$notify({