feat: migrate to vue 3 (#2689)

---------

Co-authored-by: Joep <jcbuhre@gmail.com>
Co-authored-by: Omar Hussein <omarmohammad1951@gmail.com>
Co-authored-by: Oleg Lobanov <oleg@lobanov.me>
This commit is contained in:
authored and GitHub committed 2024-04-01 17:18:22 +02:00
1 parent 0e3b35b30e
commit 5100e587d7
164 files changed
+12202 -8047

No files matched your search

+116 -101
View File
@@ -3,26 +3,26 @@
<div class="column">
<form class="card" @submit="updateSettings">
<div class="card-title">
<h2>{{ $t("settings.profileSettings") }}</h2>
<h2>{{ t("settings.profileSettings") }}</h2>
</div>
<div class="card-content">
<p>
<input type="checkbox" v-model="hideDotfiles" />
{{ $t("settings.hideDotfiles") }}
<input type="checkbox" name="hideDotfiles" v-model="hideDotfiles" />
{{ t("settings.hideDotfiles") }}
</p>
<p>
<input type="checkbox" v-model="singleClick" />
{{ $t("settings.singleClick") }}
<input type="checkbox" name="singleClick" v-model="singleClick" />
{{ t("settings.singleClick") }}
</p>
<p>
<input type="checkbox" v-model="dateFormat" />
{{ $t("settings.setDateFormat") }}
<input type="checkbox" name="dateFormat" v-model="dateFormat" />
{{ t("settings.setDateFormat") }}
</p>
<h3>{{ $t("settings.language") }}</h3>
<h3>{{ t("settings.language") }}</h3>
<languages
class="input input--block"
:locale.sync="locale"
v-model:locale="locale"
></languages>
</div>
@@ -30,32 +30,37 @@
<input
class="button button--flat"
type="submit"
:value="$t('buttons.update')"
name="submitProfile"
:value="t('buttons.update')"
/>
</div>
</form>
</div>
<div class="column">
<form class="card" v-if="!user.lockPassword" @submit="updatePassword">
<form
class="card"
v-if="!authStore.user?.lockPassword"
@submit="updatePassword"
>
<div class="card-title">
<h2>{{ $t("settings.changePassword") }}</h2>
<h2>{{ t("settings.changePassword") }}</h2>
</div>
<div class="card-content">
<input
:class="passwordClass"
type="password"
:placeholder="$t('settings.newPassword')"
:placeholder="t('settings.newPassword')"
v-model="password"
name="password"
/>
<input
:class="passwordClass"
type="password"
:placeholder="$t('settings.newPasswordConfirm')"
:placeholder="t('settings.newPasswordConfirm')"
v-model="passwordConf"
name="password"
name="passwordConf"
/>
</div>
@@ -63,7 +68,8 @@
<input
class="button button--flat"
type="submit"
:value="$t('buttons.update')"
name="submitPassword"
:value="t('buttons.update')"
/>
</div>
</form>
@@ -71,97 +77,106 @@
</div>
</template>
<script>
import { mapState, mapMutations } from "vuex";
<script setup lang="ts">
import { useAuthStore } from "@/stores/auth";
import { useLayoutStore } from "@/stores/layout";
import { users as api } from "@/api";
import Languages from "@/components/settings/Languages.vue";
import i18n, { rtlLanguages } from "@/i18n";
import { computed, inject, onMounted, ref } from "vue";
import { useI18n } from "vue-i18n";
export default {
name: "settings",
components: {
Languages,
},
data: function () {
return {
password: "",
passwordConf: "",
hideDotfiles: false,
singleClick: false,
dateFormat: false,
locale: "",
const layoutStore = useLayoutStore();
const authStore = useAuthStore();
const { t } = useI18n();
const $showSuccess = inject<IToastSuccess>("$showSuccess")!;
const $showError = inject<IToastError>("$showError")!;
const password = ref<string>("");
const passwordConf = ref<string>("");
const hideDotfiles = ref<boolean>(false);
const singleClick = ref<boolean>(false);
const dateFormat = ref<boolean>(false);
const locale = ref<string>("");
const passwordClass = computed(() => {
const baseClass = "input input--block";
if (password.value === "" && passwordConf.value === "") {
return baseClass;
}
if (password.value === passwordConf.value) {
return `${baseClass} input--green`;
}
return `${baseClass} input--red`;
});
onMounted(() => {
layoutStore.loading = true;
if (authStore.user === null) return false;
locale.value = authStore.user.locale;
hideDotfiles.value = authStore.user.hideDotfiles;
singleClick.value = authStore.user.singleClick;
dateFormat.value = authStore.user.dateFormat;
layoutStore.loading = false;
return true;
});
const updatePassword = async (event: Event) => {
event.preventDefault();
if (
password.value !== passwordConf.value ||
password.value === "" ||
authStore.user === null
) {
return;
}
try {
const data = {
...authStore.user,
id: authStore.user.id,
password: password.value,
};
},
computed: {
...mapState(["user"]),
passwordClass() {
const baseClass = "input input--block";
await api.update(data, ["password"]);
authStore.updateUser(data);
$showSuccess(t("settings.passwordUpdated"));
} catch (e: any) {
$showError(e);
} finally {
password.value = passwordConf.value = "";
}
};
const updateSettings = async (event: Event) => {
event.preventDefault();
if (this.password === "" && this.passwordConf === "") {
return baseClass;
}
try {
if (authStore.user === null) throw new Error("User is not set!");
if (this.password === this.passwordConf) {
return `${baseClass} input--green`;
}
const data = {
...authStore.user,
id: authStore.user.id,
locale: locale.value,
hideDotfiles: hideDotfiles.value,
singleClick: singleClick.value,
dateFormat: dateFormat.value,
};
return `${baseClass} input--red`;
},
},
created() {
this.setLoading(false);
this.locale = this.user.locale;
this.hideDotfiles = this.user.hideDotfiles;
this.singleClick = this.user.singleClick;
this.dateFormat = this.user.dateFormat;
},
methods: {
...mapMutations(["updateUser", "setLoading"]),
async updatePassword(event) {
event.preventDefault();
if (this.password !== this.passwordConf || this.password === "") {
return;
}
try {
const data = { id: this.user.id, password: this.password };
await api.update(data, ["password"]);
this.updateUser(data);
this.$showSuccess(this.$t("settings.passwordUpdated"));
} catch (e) {
this.$showError(e);
}
},
async updateSettings(event) {
event.preventDefault();
try {
const data = {
id: this.user.id,
locale: this.locale,
hideDotfiles: this.hideDotfiles,
singleClick: this.singleClick,
dateFormat: this.dateFormat,
};
const shouldReload =
rtlLanguages.includes(data.locale) !==
rtlLanguages.includes(i18n.locale);
await api.update(data, [
"locale",
"hideDotfiles",
"singleClick",
"dateFormat",
]);
this.updateUser(data);
if (shouldReload) {
location.reload();
}
this.$showSuccess(this.$t("settings.settingsUpdated"));
} catch (e) {
this.$showError(e);
}
},
},
await api.update(data, [
"locale",
"hideDotfiles",
"singleClick",
"dateFormat",
]);
authStore.updateUser(data);
$showSuccess(t("settings.settingsUpdated"));
} catch (err) {
if (err instanceof Error) {
$showError(err);
}
}
};
</script>