frontend/src/views/SettingsGeneral.vue

135 lines
3.7 KiB
Vue

<template>
<div id="settings-general">
<div class="box">
<div class="title">{{ $t("settings.general.title") }}</div>
<hr />
<div class="subtitle">{{ $t("settings.general.about") }}</div>
<form @submit.prevent="saveDesc">
<b-field :label="$t('settings.general.description')">
<b-input
type="textarea"
:placeholder="
$t('settings.general.hi') + ' ' + $store.state.user.username
"
maxlength="256"
v-model="settings.description.value"
:error="settings.description.error"
></b-input>
</b-field>
<b-button
type="is-info"
:loading="settings.description.loading"
@click="saveDescription"
>
{{ $t("settings.general.saveDesc") }}
</b-button>
</form>
<form @submit.prevent="savePref">
<b-field label="Developer Mode">
<b-switch
type="is-info"
true-value="true"
false-value="false"
v-model="settings.preferences.developerMode"
>{{ settings.preferences.developerMode }}</b-switch>
</b-field>
<b-button
type="is-info"
:loading="settings.preferences.loading"
@click="savepreferences"
>
{{ $t("settings.general.savePref") }}
</b-button>
</form>
</div>
</div>
</template>
<script>
export default {
name: "SettingsGeneral",
data() {
return {
settings: {
description: {
value: this.$store.state.user.description,
loading: false,
error: "",
},
preferences: {
developerMode: this.$store.state.user.developerMode,
loading: false,
error: "",
},
},
};
},
methods: {
clearErrors() {
this.settings.description.error = "";
this.settings.preferences.error = "";
},
changesSaved() {
this.$buefy.snackbar.open({
duration: 5000,
message: "Changes saved.",
type: "is-success",
position: "is-bottom-left",
actionText: "Ok",
queue: false,
});
},
saveDescription() {
this.clearErrors();
this.settings.description.loading = true;
this.axios
.put(
process.env.VUE_APP_API_ENDPOINT +
process.env.VUE_APP_API_VERSION +
"/users/preferences",
{
description: this.settings.description.value,
}
)
.then(() => {
this.settings.description.loading = false;
this.changesSaved();
})
.catch((err) => {
this.settings.description.loading = false;
AjaxErrorHandler(this.$store)(err);
});
},
savepreferences() {
this.clearErrors();
this.settings.preferences.loading = true;
this.axios
.put(
process.env.VUE_APP_API_ENDPOINT +
process.env.VUE_APP_API_VERSION +
"/users/preferences",
{
developerMode: this.settings.preferences.developerMode,
}
)
.then(() => {
this.axios
.get(
process.env.VUE_APP_API_ENDPOINT +
process.env.VUE_APP_API_VERSION +
"/userinfo"
)
.then((res) => {
this.$store.commit("setDevMode", res.data.developerMode);
});
this.settings.description.loading = false;
this.changesSaved();
})
.catch((err) => {
this.settings.preferences.loading = false;
AjaxErrorHandler(this.$store)(err);
});
},
},
};
</script>