Refactor ContributionForm to deal with posts with no languages

This commit is contained in:
Matt Rider 2019-06-14 13:30:00 -03:00
parent a099c209a8
commit 614a7eebc1

View File

@ -15,7 +15,7 @@
model="language"
:options="form.languageOptions"
icon="globe"
:placeholder="locale"
:placeholder="form.placeholder"
:label="$t('contribution.languageSelectLabel')"
/>
</ds-flex-item>
@ -64,6 +64,7 @@ export default {
content: '',
language: null,
languageOptions: [],
placeholder: '',
},
formSchema: {
title: { required: true, min: 3, max: 64 },
@ -88,13 +89,15 @@ export default {
this.form.content = contribution.content
this.form.title = contribution.title
this.form.language = this.locale
this.form.placeholder = this.locale
},
},
},
computed: {
locale() {
let locale
locale = locales.find(this.returnLocaleName)
const locale = this.contribution.language
? locales.find(loc => this.contribution.language === loc.code)
: locales.find(loc => this.$i18n.locale() === loc.code)
return locale.name
},
},
@ -137,14 +140,6 @@ export default {
// this.form.content = value
this.$refs.contributionForm.update('content', value)
},
returnLocaleName(locale) {
if (
(this.contribution && this.contribution.language === locale.code) ||
(!this.contribution && this.$i18n.locale() === locale.code)
) {
return locale
}
},
availableLocales() {
orderBy(locales, 'name').map(locale => {
this.form.languageOptions.push({ label: locale.name, value: locale.code })