Fix project settings not allowing you to remove links & trim certain project fields (#895)

* Fix project settings not allowing you to remove links

* Trim project fields

Closes #850
This commit is contained in:
Prospector
2023-01-11 10:00:42 -08:00
committed by GitHub
parent cda18fb957
commit de212322e2
4 changed files with 19 additions and 13 deletions

View File

@@ -153,10 +153,10 @@ export default {
formData.append( formData.append(
'data', 'data',
JSON.stringify({ JSON.stringify({
title: this.name, title: this.name.trim(),
project_type: projectType.actual, project_type: projectType.actual,
slug: this.slug, slug: this.slug,
description: this.description, description: this.description.trim(),
body: `# Placeholder description body: `# Placeholder description
This is your new ${projectType.display}, ${ This is your new ${projectType.display}, ${
this.name this.name
@@ -235,9 +235,11 @@ Questions? [Join the Modrinth Discord for support!](https://discord.gg/EUHuJHt)`
updatedName() { updatedName() {
if (!this.manualSlug) { if (!this.manualSlug) {
this.slug = this.name this.slug = this.name
.trim()
.toLowerCase() .toLowerCase()
.replaceAll(' ', '-') .replaceAll(' ', '-')
.replaceAll(/[^a-zA-Z0-9!@$()`.+,_"-]/g, '') .replaceAll(/[^a-zA-Z0-9!@$()`.+,_"-]/g, '')
.replaceAll(/--+/gm, '-')
} }
}, },
}, },

View File

@@ -323,13 +323,13 @@ export default {
const data = {} const data = {}
if (this.name !== this.project.title) { if (this.name !== this.project.title) {
data.title = this.name data.title = this.name.trim()
} }
if (this.slug !== this.project.slug) { if (this.slug !== this.project.slug) {
data.slug = this.slug data.slug = this.slug.trim()
} }
if (this.summary !== this.project.description) { if (this.summary !== this.project.description) {
data.description = this.summary data.description = this.summary.trim()
} }
if (this.clientSide !== this.project.client_side) { if (this.clientSide !== this.project.client_side) {
data.client_side = this.clientSide data.client_side = this.clientSide

View File

@@ -189,16 +189,17 @@ export default {
const data = {} const data = {}
if (this.checkDifference(this.issuesUrl, this.project.issues_url)) { if (this.checkDifference(this.issuesUrl, this.project.issues_url)) {
data.issues_url = this.issuesUrl data.issues_url = this.issuesUrl === '' ? null : this.issuesUrl.trim()
} }
if (this.checkDifference(this.sourceUrl, this.project.source_url)) { if (this.checkDifference(this.sourceUrl, this.project.source_url)) {
data.source_url = this.sourceUrl data.source_url = this.sourceUrl === '' ? null : this.sourceUrl.trim()
} }
if (this.checkDifference(this.wikiUrl, this.project.wiki_url)) { if (this.checkDifference(this.wikiUrl, this.project.wiki_url)) {
data.wiki_url = this.wikiUrl data.wiki_url = this.wikiUrl === '' ? null : this.wikiUrl.trim()
} }
if (this.checkDifference(this.discordUrl, this.project.discord_url)) { if (this.checkDifference(this.discordUrl, this.project.discord_url)) {
data.discord_url = this.discordUrl data.discord_url =
this.discordUrl === '' ? null : this.discordUrl.trim()
} }
const donationLinks = this.donationLinks.filter( const donationLinks = this.donationLinks.filter(
@@ -267,11 +268,14 @@ export default {
url: null, url: null,
}) })
}, },
checkDifference(a, b) { checkDifference(newLink, existingLink) {
if (!a && !b) { if (newLink === '' && existingLink !== null) {
return true
}
if (!newLink && !existingLink) {
return false return false
} }
return a !== b return newLink !== existingLink
}, },
}, },
} }

View File

@@ -323,7 +323,7 @@ export default {
.data .data
const data = { const data = {
user_id: user.id, user_id: user.id.trim(),
} }
await this.$axios.post( await this.$axios.post(