Move try/catch and success message from view files to action in module

This commit is contained in:
Angelina Filippova 2019-10-24 23:24:56 +02:00
parent a66bb599ce
commit 453cde8435
22 changed files with 53 additions and 233 deletions

View file

@ -1,5 +1,7 @@
import i18n from '@/lang'
import { fetchSettings, updateSettings, uploadMedia } from '@/api/settings'
import { filterIgnored, parseTuples, valueHasTuples, wrapConfig } from './normalizers'
import { Message } from 'element-ui'
const settings = {
state: {
@ -124,10 +126,17 @@ const settings = {
async SubmitChanges({ getters, commit, state }, data) {
const filteredSettings = filterIgnored(state.settings, state.ignoredIfNotEnabled)
const configs = data || wrapConfig(filteredSettings)
const response = await updateSettings(configs, getters.authHost, getters.token)
if (data) {
try {
const response = await updateSettings(configs, getters.authHost, getters.token)
commit('SET_SETTINGS', response.data.configs)
} catch (_e) {
return
}
Message({
message: i18n.t('settings.success'),
type: 'success',
duration: 5 * 1000
})
},
UpdateSettings({ commit }, { tab, data }) {
commit('UPDATE_SETTINGS', { tab, data })

View file

@ -37,7 +37,6 @@
<script>
import { mapGetters } from 'vuex'
import i18n from '@/lang'
export default {
name: 'ActivityPub',
@ -57,16 +56,8 @@ export default {
updateSetting(value, tab, input) {
this.$store.dispatch('UpdateSettings', { tab, data: { [input]: value }})
},
async onSubmit() {
try {
await this.$store.dispatch('SubmitChanges')
} catch (e) {
return
}
this.$message({
type: 'success',
message: i18n.t('settings.success')
})
onSubmit() {
this.$store.dispatch('SubmitChanges')
}
}
}

View file

@ -232,7 +232,6 @@
<script>
import { mapGetters } from 'vuex'
import i18n from '@/lang'
export default {
name: 'Authentication',
@ -259,16 +258,8 @@ export default {
updateSetting(value, tab, input) {
this.$store.dispatch('UpdateSettings', { tab, data: { [input]: value }})
},
async onSubmit() {
try {
await this.$store.dispatch('SubmitChanges')
} catch (e) {
return
}
this.$message({
type: 'success',
message: i18n.t('settings.success')
})
onSubmit() {
this.$store.dispatch('SubmitChanges')
}
}
}

View file

@ -52,7 +52,6 @@
<script>
import { mapGetters } from 'vuex'
import i18n from '@/lang'
export default {
name: 'AutoLinker',
@ -107,16 +106,8 @@ export default {
updateSetting(value, tab, input) {
this.$store.dispatch('UpdateSettings', { tab, data: { [input]: value }})
},
async onSubmit() {
try {
await this.$store.dispatch('SubmitChanges')
} catch (e) {
return
}
this.$message({
type: 'success',
message: i18n.t('settings.success')
})
onSubmit() {
this.$store.dispatch('SubmitChanges')
}
}
}

View file

@ -33,7 +33,6 @@
<script>
import { mapGetters } from 'vuex'
import i18n from '@/lang'
export default {
name: 'Captcha',
@ -53,16 +52,8 @@ export default {
updateSetting(value, tab, input) {
this.$store.dispatch('UpdateSettings', { tab, data: { [input]: value }})
},
async onSubmit() {
try {
await this.$store.dispatch('SubmitChanges')
} catch (e) {
return
}
this.$message({
type: 'success',
message: i18n.t('settings.success')
})
onSubmit() {
this.$store.dispatch('SubmitChanges')
}
}
}

View file

@ -135,7 +135,6 @@
</template>
<script>
import i18n from '@/lang'
import { mapGetters } from 'vuex'
export default {
@ -157,16 +156,8 @@ export default {
updateSetting(value, tab, input) {
this.$store.dispatch('UpdateSettings', { tab, data: { [input]: value }})
},
async onSubmit() {
try {
await this.$store.dispatch('SubmitChanges')
} catch (e) {
return
}
this.$message({
type: 'success',
message: i18n.t('settings.success')
})
onSubmit() {
this.$store.dispatch('SubmitChanges')
}
}
}

View file

@ -172,7 +172,6 @@
<script>
import { mapGetters } from 'vuex'
import i18n from '@/lang'
import { options } from './options'
import AceEditor from 'vue2-ace-editor'
import 'brace/mode/elixir'
@ -246,16 +245,8 @@ export default {
updateSetting(value, tab, input) {
this.$store.dispatch('UpdateSettings', { tab, data: { [input]: value }})
},
async onSubmit() {
try {
await this.$store.dispatch('SubmitChanges')
} catch (e) {
return
}
this.$message({
type: 'success',
message: i18n.t('settings.success')
})
onSubmit() {
this.$store.dispatch('SubmitChanges')
}
}
}

View file

@ -55,7 +55,6 @@
</template>
<script>
import i18n from '@/lang'
import { mapGetters } from 'vuex'
export default {
@ -82,16 +81,8 @@ export default {
updateSetting(value, tab, input) {
this.$store.dispatch('UpdateSettings', { tab, data: { [input]: value }})
},
async onSubmit() {
try {
await this.$store.dispatch('SubmitChanges')
} catch (e) {
return
}
this.$message({
type: 'success',
message: i18n.t('settings.success')
})
onSubmit() {
this.$store.dispatch('SubmitChanges')
}
}
}

View file

@ -318,7 +318,6 @@
<script>
import { mapGetters } from 'vuex'
import i18n from '@/lang'
import { options } from './options'
export default {
@ -419,16 +418,8 @@ export default {
updateSetting(value, tab, input) {
this.$store.dispatch('UpdateSettings', { tab, data: { [input]: value }})
},
async onSubmit() {
try {
await this.$store.dispatch('SubmitChanges')
} catch (e) {
return
}
this.$message({
type: 'success',
message: i18n.t('settings.success')
})
onSubmit() {
this.$store.dispatch('SubmitChanges')
}
}
}

View file

@ -23,7 +23,6 @@
</template>
<script>
import i18n from '@/lang'
import { mapGetters } from 'vuex'
export default {
@ -43,16 +42,8 @@ export default {
updateSetting(value, tab, input) {
this.$store.dispatch('UpdateSettings', { tab, data: { [input]: value }})
},
async onSubmit() {
try {
await this.$store.dispatch('SubmitChanges')
} catch (e) {
return
}
this.$message({
type: 'success',
message: i18n.t('settings.success')
})
onSubmit() {
this.$store.dispatch('SubmitChanges')
}
}
}

View file

@ -129,7 +129,6 @@
</template>
<script>
import i18n from '@/lang'
import { mapGetters } from 'vuex'
export default {
@ -161,16 +160,8 @@ export default {
updateSetting(value, tab, input) {
this.$store.dispatch('UpdateSettings', { tab, data: { [input]: value }})
},
async onSubmit() {
try {
await this.$store.dispatch('SubmitChanges')
} catch (e) {
return
}
this.$message({
type: 'success',
message: i18n.t('settings.success')
})
onSubmit() {
this.$store.dispatch('SubmitChanges')
}
}
}

View file

@ -337,7 +337,6 @@
</template>
<script>
import i18n from '@/lang'
import { mapGetters } from 'vuex'
import { options } from './options'
@ -396,16 +395,8 @@ export default {
updateSetting(value, tab, input) {
this.$store.dispatch('UpdateSettings', { tab, data: { [input]: value }})
},
async onSubmit() {
try {
await this.$store.dispatch('SubmitChanges')
} catch (e) {
return
}
this.$message({
type: 'success',
message: i18n.t('settings.success')
})
onSubmit() {
this.$store.dispatch('SubmitChanges')
}
}
}

View file

@ -51,7 +51,6 @@
</template>
<script>
import i18n from '@/lang'
import { mapGetters } from 'vuex'
export default {
@ -72,16 +71,8 @@ export default {
updateSetting(value, tab, input) {
this.$store.dispatch('UpdateSettings', { tab, data: { [input]: value }})
},
async onSubmit() {
try {
await this.$store.dispatch('SubmitChanges')
} catch (e) {
return
}
this.$message({
type: 'success',
message: i18n.t('settings.success')
})
onSubmit() {
this.$store.dispatch('SubmitChanges')
}
}
}

View file

@ -173,7 +173,6 @@
<script>
import { mapGetters } from 'vuex'
import i18n from '@/lang'
import { options } from './options'
export default {
@ -212,16 +211,8 @@ export default {
updateSetting(value, tab, input) {
this.$store.dispatch('UpdateSettings', { tab, data: { [input]: value }})
},
async onSubmit() {
try {
await this.$store.dispatch('SubmitChanges')
} catch (e) {
return
}
this.$message({
type: 'success',
message: i18n.t('settings.success')
})
onSubmit() {
this.$store.dispatch('SubmitChanges')
}
}
}

View file

@ -145,7 +145,6 @@
<script>
import { mapGetters } from 'vuex'
import i18n from '@/lang'
import { options } from './options'
export default {
@ -257,16 +256,8 @@ export default {
updateSetting(value, tab, input) {
this.$store.dispatch('UpdateSettings', { tab, data: { [input]: value }})
},
async onSubmit() {
try {
await this.$store.dispatch('SubmitChanges')
} catch (e) {
return
}
this.$message({
type: 'success',
message: i18n.t('settings.success')
})
onSubmit() {
this.$store.dispatch('SubmitChanges')
}
}
}

View file

@ -202,7 +202,6 @@
</template>
<script>
import i18n from '@/lang'
import { mapGetters } from 'vuex'
import { options } from './options'
import AceEditor from 'vue2-ace-editor'
@ -249,16 +248,8 @@ export default {
updateSetting(value, tab, input) {
this.$store.dispatch('UpdateSettings', { tab, data: { [input]: value }})
},
async onSubmit() {
try {
await this.$store.dispatch('SubmitChanges')
} catch (e) {
return
}
this.$message({
type: 'success',
message: i18n.t('settings.success')
})
onSubmit() {
this.$store.dispatch('SubmitChanges')
}
}
}

View file

@ -75,7 +75,6 @@
</template>
<script>
import i18n from '@/lang'
import { mapGetters } from 'vuex'
import { options } from './options'
@ -126,16 +125,8 @@ export default {
updateSetting(value, tab, input) {
this.$store.dispatch('UpdateSettings', { tab, data: { [input]: value }})
},
async onSubmit() {
try {
await this.$store.dispatch('SubmitChanges')
} catch (e) {
return
}
this.$message({
type: 'success',
message: i18n.t('settings.success')
})
onSubmit() {
this.$store.dispatch('SubmitChanges')
}
}
}

View file

@ -52,7 +52,6 @@
<script>
import { mapGetters } from 'vuex'
import i18n from '@/lang'
export default {
name: 'Metadata',
@ -72,16 +71,8 @@ export default {
updateSetting(value, tab, input) {
this.$store.dispatch('UpdateSettings', { tab, data: { [input]: value }})
},
async onSubmit() {
try {
await this.$store.dispatch('SubmitChanges')
} catch (e) {
return
}
this.$message({
type: 'success',
message: i18n.t('settings.success')
})
onSubmit() {
this.$store.dispatch('SubmitChanges')
}
}
}

View file

@ -30,7 +30,6 @@
</template>
<script>
import i18n from '@/lang'
import { mapGetters } from 'vuex'
export default {
@ -65,16 +64,8 @@ export default {
}, {})
this.updateSetting(updatedValue, 'types', 'value')
},
async onSubmit() {
try {
await this.$store.dispatch('SubmitChanges')
} catch (e) {
return
}
this.$message({
type: 'success',
message: i18n.t('settings.success')
})
onSubmit() {
this.$store.dispatch('SubmitChanges')
},
parseMimeTypes(value, inputType, index) {
const updatedValue = this.mimeTypes.reduce((acc, el, i) => {

View file

@ -223,7 +223,6 @@
</template>
<script>
import i18n from '@/lang'
import { mapGetters } from 'vuex'
export default {
@ -379,16 +378,8 @@ export default {
updateSetting(value, tab, input) {
this.$store.dispatch('UpdateSettings', { tab, data: { [input]: value }})
},
async onSubmit() {
try {
await this.$store.dispatch('SubmitChanges')
} catch (e) {
return
}
this.$message({
type: 'success',
message: i18n.t('settings.success')
})
onSubmit() {
this.$store.dispatch('SubmitChanges')
}
}
}

View file

@ -144,7 +144,6 @@
</template>
<script>
import i18n from '@/lang'
import { mapGetters } from 'vuex'
import { options } from './options'
@ -207,16 +206,8 @@ export default {
updateSetting(value, tab, input) {
this.$store.dispatch('UpdateSettings', { tab, data: { [input]: value }})
},
async onSubmit() {
try {
await this.$store.dispatch('SubmitChanges')
} catch (e) {
return
}
this.$message({
type: 'success',
message: i18n.t('settings.success')
})
onSubmit() {
this.$store.dispatch('SubmitChanges')
}
}
}

View file

@ -21,7 +21,6 @@
</template>
<script>
import i18n from '@/lang'
import { mapGetters } from 'vuex'
export default {
@ -41,16 +40,8 @@ export default {
updateSetting(value, tab, input) {
this.$store.dispatch('UpdateSettings', { tab, data: { [input]: value }})
},
async onSubmit() {
try {
await this.$store.dispatch('SubmitChanges')
} catch (e) {
return
}
this.$message({
type: 'success',
message: i18n.t('settings.success')
})
onSubmit() {
this.$store.dispatch('SubmitChanges')
}
}
}