2023-02-07 13:50:24 +00:00
|
|
|
<template>
|
|
|
|
<q-page>
|
|
|
|
<StandardCenteredPage v-if="user">
|
|
|
|
<h3>{{ user?.name }}</h3>
|
2023-02-16 07:11:48 +00:00
|
|
|
|
2023-02-07 13:50:24 +00:00
|
|
|
<p>{{ user?.email }}</p>
|
|
|
|
<p v-if="isOwnUser">This is your account!</p>
|
2023-02-16 07:11:48 +00:00
|
|
|
|
|
|
|
<hr>
|
|
|
|
|
2023-02-16 17:11:03 +00:00
|
|
|
<div v-if="userPrivate">
|
|
|
|
This account is private.
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div v-if="recentSubmissions.length > 0">
|
|
|
|
<h4 class="text-center">{{ $t('userPage.recentLifts') }}</h4>
|
|
|
|
<q-list separator>
|
|
|
|
<ExerciseSubmissionListItem
|
|
|
|
v-for="sub in recentSubmissions"
|
|
|
|
:submission="sub"
|
|
|
|
:key="sub.id"
|
|
|
|
/>
|
|
|
|
</q-list>
|
|
|
|
</div>
|
2023-02-16 07:11:48 +00:00
|
|
|
|
2023-02-07 13:50:24 +00:00
|
|
|
</StandardCenteredPage>
|
2023-02-08 07:30:16 +00:00
|
|
|
<StandardCenteredPage v-if="userNotFound">
|
|
|
|
<h3>{{ $t('userPage.notFound.title') }}</h3>
|
|
|
|
<p>{{ $t('userPage.notFound.description') }}</p>
|
|
|
|
</StandardCenteredPage>
|
2023-02-07 13:50:24 +00:00
|
|
|
</q-page>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
import StandardCenteredPage from 'components/StandardCenteredPage.vue';
|
2023-02-16 17:11:03 +00:00
|
|
|
import {onMounted, ref, Ref} from 'vue';
|
2023-02-07 13:50:24 +00:00
|
|
|
import {User} from 'src/api/main/auth';
|
|
|
|
import api from 'src/api/main';
|
|
|
|
import {useRoute} from 'vue-router';
|
|
|
|
import {useAuthStore} from 'stores/auth-store';
|
2023-02-16 17:11:03 +00:00
|
|
|
import {useI18n} from 'vue-i18n';
|
|
|
|
import {useQuasar} from 'quasar';
|
|
|
|
import {showApiErrorToast} from 'src/utils';
|
|
|
|
import {ExerciseSubmission} from 'src/api/main/submission';
|
|
|
|
import ExerciseSubmissionListItem from 'components/ExerciseSubmissionListItem.vue';
|
2023-02-07 13:50:24 +00:00
|
|
|
|
|
|
|
const route = useRoute();
|
|
|
|
const authStore = useAuthStore();
|
2023-02-16 17:11:03 +00:00
|
|
|
const i18n = useI18n();
|
|
|
|
const quasar = useQuasar();
|
2023-02-07 13:50:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The user that this page displays information about.
|
|
|
|
*/
|
|
|
|
const user: Ref<User | undefined> = ref();
|
2023-02-16 17:11:03 +00:00
|
|
|
const recentSubmissions: Ref<ExerciseSubmission[]> = ref([]);
|
2023-02-07 13:50:24 +00:00
|
|
|
const isOwnUser = ref(false);
|
2023-02-08 07:30:16 +00:00
|
|
|
const userNotFound = ref(false);
|
2023-02-16 17:11:03 +00:00
|
|
|
const userPrivate = ref(false);
|
2023-02-08 07:30:16 +00:00
|
|
|
|
2023-02-07 13:50:24 +00:00
|
|
|
onMounted(async () => {
|
|
|
|
const userId = route.params.userId as string;
|
2023-02-08 07:30:16 +00:00
|
|
|
try {
|
|
|
|
user.value = await api.auth.getUser(userId, authStore);
|
|
|
|
} catch (error: any) {
|
2023-02-16 17:11:03 +00:00
|
|
|
if (error.response && error.response.status === 404) {
|
2023-02-08 07:30:16 +00:00
|
|
|
userNotFound.value = true;
|
2023-02-16 17:11:03 +00:00
|
|
|
} else {
|
|
|
|
showApiErrorToast(i18n, quasar);
|
2023-02-08 07:30:16 +00:00
|
|
|
}
|
|
|
|
}
|
2023-02-16 07:11:48 +00:00
|
|
|
isOwnUser.value = authStore.loggedIn && user.value?.id === authStore.user?.id;
|
2023-02-16 17:11:03 +00:00
|
|
|
|
|
|
|
// If the user exists, try and fetch their latest submissions, and handle a 403 forbidden as private.
|
|
|
|
if (user.value) {
|
|
|
|
try {
|
|
|
|
recentSubmissions.value = await api.users.getRecentSubmissions(user.value?.id, authStore);
|
|
|
|
} catch (error: any) {
|
|
|
|
if (error.response && error.response.status === 403) {
|
|
|
|
userPrivate.value = true;
|
|
|
|
} else {
|
|
|
|
showApiErrorToast(i18n, quasar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-02-07 13:50:24 +00:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
|
|
</style>
|