-
Notifications
You must be signed in to change notification settings - Fork 2
WIP: Обновление страницы профиля #354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Maya-Borenko
wants to merge
4
commits into
main
Choose a base branch
from
borenkomd/issue-166
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| <script setup lang="ts"> | ||
| defineProps<{ | ||
| name: string; | ||
| description: string; | ||
| picture: string; | ||
| }>(); | ||
| </script> | ||
|
|
||
| <template> | ||
| <v-card | ||
| class="achievement-card bg-grey-lighten-4 rounded-lg pa-3 ma-2 d-flex flex-column align-center cursor-pointer" | ||
| elevation="0" | ||
| > | ||
| <v-avatar class="rounded-circle overflow-hidden mt-1" size="64"> | ||
| <v-img :src="picture" :alt="name" cover aspect-ratio="1" /> | ||
| </v-avatar> | ||
| <p class="text-body-1 mt-2 text-center"> | ||
| {{ name }} | ||
| </p> | ||
| <v-tooltip activator="parent" location="bottom"> | ||
| <p color="on-surface">{{ description }}</p> | ||
| </v-tooltip> | ||
| </v-card> | ||
| </template> | ||
|
|
||
| <style scoped> | ||
| .achievement-card { | ||
| width: 136px; | ||
| height: 144px; | ||
| transition: transform 0.2s ease; | ||
| } | ||
|
|
||
| .achievement-card:hover { | ||
| transform: translateY(-4px); | ||
| } | ||
| </style> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <script setup lang="ts"> | ||
| import AchievementElement from './AchievementElement.vue'; | ||
| defineProps<{ | ||
| achievements: Array<{ | ||
| id: number; | ||
| name: string; | ||
| description: string; | ||
| picture: string; | ||
| }>; | ||
| isLoading: boolean; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Лоадеры класс |
||
| }>(); | ||
| </script> | ||
|
|
||
| <template> | ||
| <v-slide-group v-if="achievements.length > 0" :show-arrows="false" class="me-n2 pt-9 pb-2"> | ||
| <v-slide-group-item v-for="item in achievements" :key="item.id"> | ||
| <AchievementElement | ||
| :name="item.name" | ||
| :description="item.description" | ||
| :picture="item.picture" | ||
| /> | ||
| </v-slide-group-item> | ||
| </v-slide-group> | ||
|
|
||
| <div v-else-if="isLoading" class="d-flex justify-center py-8"> | ||
| <v-progress-circular indeterminate color="primary" /> | ||
| </div> | ||
|
|
||
| <div v-else class="text-center text-grey-darken-2 py-8"> | ||
| <p class="text-body-1 mb-0">У тебя еще нет достижений в приложении :(</p> | ||
| </div> | ||
| </template> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <script setup lang="ts"> | ||
| defineProps<{ | ||
| userName: string; | ||
| photoUrl: string; | ||
| }>(); | ||
| </script> | ||
|
|
||
| <template> | ||
| <div class="d-flex flex-row align-center ga-8"> | ||
| <v-avatar size="120" class="flex-shrink-0"> | ||
| <v-img :src="photoUrl" :alt="userName" cover /> | ||
| </v-avatar> | ||
| <h2> | ||
| {{ userName }} | ||
| </h2> | ||
| </div> | ||
| </template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <script setup lang="ts"> | ||
| import { UserdataArrayDataItem } from '@/models'; | ||
| defineProps<{ | ||
| name: string; | ||
| data: UserdataArrayDataItem[]; | ||
| }>(); | ||
| </script> | ||
|
|
||
| <template> | ||
| <div class="pa-5 mb-4 rounded-lg bg-grey-lighten-4"> | ||
| <h3>{{ name }}</h3> | ||
| <div v-for="{ param, value } of data" :key="param" class="mt-4"> | ||
| <div class="text-caption"> | ||
| {{ param }} | ||
| </div> | ||
| <div class="text-body-1 text-break"> | ||
| {{ value.name }} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
BatuevIO marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| <script setup lang="ts"> | ||
| import { VuConfig } from '@profcomff/ui-kit'; | ||
| import UserInfo from '@/modules/profile/ui/UserInfo.vue'; | ||
| import UserHeader from '@/modules/profile/ui/UserHeader.vue'; | ||
| import Placeholder from '@/assets/profile_image_placeholder.webp'; | ||
| import { apiClient, AuthApi, UserdataApi } from '@/api'; | ||
| import { useRouter, useRoute } from 'vue-router'; | ||
| import { UserdataArray, UserdataCategoryName, UserdataParams, AchievementGet } from '@/models'; | ||
| import UserAchievements from '@/modules/profile/ui/UserAchievements.vue'; | ||
| import IrdomLayout from '@/components/IrdomLayout.vue'; | ||
| import { useProfileStore } from '@/store/profile'; | ||
| import { UserdataConverter } from '@/utils/UserdataConverter'; | ||
| import { ToolbarActionItem } from '@/components/IrdomToolbar.vue'; | ||
| import { useToolbar } from '@/store/toolbar'; | ||
| import { onMounted, ref, computed } from 'vue'; | ||
| import { getPictureUrl } from '@/utils/achievement'; | ||
|
|
||
| const profileStore = useProfileStore(); | ||
| const router = useRouter(); | ||
| const route = useRoute(); | ||
| const toolbar = useToolbar(); | ||
|
|
||
| const isOwnProfile = !('id' in route.params) || route.params.id === undefined; | ||
|
|
||
| const buttons: ToolbarActionItem[] = []; | ||
|
|
||
| if (isOwnProfile) { | ||
| buttons.push({ | ||
| icon: 'settings', | ||
| ariaLabel: 'Настройки', | ||
| onClick: () => router.push('/profile/settings'), | ||
| }); | ||
| } | ||
|
|
||
| toolbar.setup({ | ||
| title: 'Профиль', | ||
| actions: buttons, | ||
| }); | ||
|
|
||
| enum UserdataLoadingState { | ||
| Loading = 1, | ||
| Ready = 2, | ||
| Error = 3, | ||
| } | ||
|
|
||
| const userdata = ref<UserdataArray>([]); | ||
| const userdataLoadingState = ref<UserdataLoadingState>(UserdataLoadingState.Loading); | ||
| const fullName = ref(''); | ||
| const photoUrl = ref(''); | ||
|
|
||
| const userId = ref<number>(-1); | ||
| const achievements = ref<AchievementGet[]>([]); | ||
| const achievementsIsLoading = ref(true); | ||
|
|
||
| const toolbarAction: ToolbarActionItem[] = [ | ||
| { | ||
| icon: 'edit', | ||
| ariaLabel: 'Редактировать профиль', | ||
| onClick: () => router.push('/profile/edit'), | ||
| }, | ||
| { | ||
| icon: 'settings', | ||
| ariaLabel: 'Настройки', | ||
| onClick: () => router.push('/profile/settings'), | ||
| }, | ||
| ]; | ||
|
|
||
| const loadUserdata = async () => { | ||
| if (!profileStore.token) { | ||
| await apiClient.GET('/auth/me'); | ||
| } | ||
|
|
||
| userdataLoadingState.value = UserdataLoadingState.Loading; | ||
|
|
||
| const { data: me } = await (isOwnProfile | ||
| ? AuthApi.getMe(['auth_methods', 'groups', 'indirect_groups', 'session_scopes', 'user_scopes']) | ||
| : AuthApi.getById(Number(route.params.id), [ | ||
| 'auth_methods', | ||
| 'groups', | ||
| 'indirect_groups', | ||
| 'scopes', | ||
| ])); | ||
|
|
||
| if (me) { | ||
| userId.value = me.id; | ||
| getUserInfo(); | ||
| loadAchievements(); | ||
| } | ||
| }; | ||
|
|
||
| const getUserInfo = async () => { | ||
| const { data } = await UserdataApi.getUser(userId.value); | ||
| if (data) { | ||
| fullName.value = | ||
| data.items.find( | ||
| item => | ||
| item.category === UserdataCategoryName.PersonalInfo && | ||
| item.param === UserdataParams.FullName | ||
| )?.value ?? 'Безымянный'; | ||
| photoUrl.value = | ||
| data.items.find( | ||
| item => | ||
| item.category === UserdataCategoryName.PersonalInfo && item.param === UserdataParams.Photo | ||
| )?.value ?? Placeholder; | ||
|
|
||
| userdata.value = UserdataConverter.flatToArray(data); | ||
| userdataLoadingState.value = UserdataLoadingState.Ready; | ||
| } else { | ||
| fullName.value = 'Безымянный'; | ||
| photoUrl.value = Placeholder; | ||
| userdataLoadingState.value = UserdataLoadingState.Error; | ||
| } | ||
| }; | ||
|
|
||
| const loadAchievements = async () => { | ||
| try { | ||
| const resp = await apiClient.GET('/achievement/user/{user_id}', { | ||
| params: { path: { user_id: userId.value } }, | ||
| }); | ||
| if (resp.data) { | ||
| achievements.value = resp.data.achievement; | ||
| } | ||
| } catch (error) { | ||
| console.error('Failed to load achievements:', error); | ||
| } finally { | ||
| achievementsIsLoading.value = false; | ||
| } | ||
| }; | ||
|
|
||
| const preparedAchievements = computed(() => { | ||
| return achievements.value.map(achievement => ({ | ||
| id: achievement.id, | ||
| name: achievement.name, | ||
| description: achievement.description, | ||
| picture: getPictureUrl(achievement.picture), | ||
| })); | ||
| }); | ||
|
|
||
| onMounted(async () => { | ||
| loadUserdata(); | ||
| }); | ||
| </script> | ||
|
|
||
| <template> | ||
| <v-theme-provider :class="VuConfig"> | ||
| <v-defaults-provider :defaults="VuConfig.defaults"> | ||
| <IrdomLayout | ||
| :toolbar-actions="toolbarAction" | ||
| title="Профиль" | ||
| class-name="profile-toolbar" | ||
| centered-toolbar | ||
| > | ||
| <div class="pa-3"> | ||
| <UserHeader :user-name="fullName" :photo-url="photoUrl" /> | ||
|
|
||
| <UserAchievements | ||
| :achievements="preparedAchievements" | ||
| :is-loading="achievementsIsLoading" | ||
| /> | ||
|
|
||
| <div v-if="userdataLoadingState === UserdataLoadingState.Ready"> | ||
| <h2 class="mb-3 mt-4">Основная информация</h2> | ||
| <div v-for="{ name, data } of userdata" :key="name" class="mb-4"> | ||
| <UserInfo :name="name" :data="data" /> | ||
| </div> | ||
| </div> | ||
|
|
||
| <FullscreenLoader v-else-if="userdataLoadingState === UserdataLoadingState.Loading" /> | ||
| <h2 v-else>Не удалось загрузить данные профиля</h2> | ||
| </div> | ||
| </IrdomLayout> | ||
| </v-defaults-provider> | ||
| </v-theme-provider> | ||
| </template> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Можно вынести в отдельный тип (он наверное уже есть), и в единичный компонент прокинуть через Omit