From 3bcc93bb1a7679a0b895d023fd28c527b4d415ca Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 23 Oct 2021 20:04:38 +0200 Subject: [PATCH] Client - use nested routes for user profile --- .../User/ProfileDisplay/UserHeader.vue | 121 ++++++++++++++++++ .../components/User/ProfileDisplay/index.vue | 110 ++-------------- .../User/ProfileEdition/UserInfosEdition.vue | 2 +- .../ProfileEdition/UserPreferencesEdition.vue | 5 +- .../components/User/ProfileEdition/index.vue | 28 ++-- fittrackee_client/src/router/index.ts | 91 +++++++++---- fittrackee_client/src/views/ProfileView.vue | 31 +---- .../src/views/{ => workouts}/AddWorkout.vue | 0 8 files changed, 215 insertions(+), 173 deletions(-) create mode 100644 fittrackee_client/src/components/User/ProfileDisplay/UserHeader.vue rename fittrackee_client/src/views/{ => workouts}/AddWorkout.vue (100%) diff --git a/fittrackee_client/src/components/User/ProfileDisplay/UserHeader.vue b/fittrackee_client/src/components/User/ProfileDisplay/UserHeader.vue new file mode 100644 index 00000000..00f3b3cd --- /dev/null +++ b/fittrackee_client/src/components/User/ProfileDisplay/UserHeader.vue @@ -0,0 +1,121 @@ + + + + + diff --git a/fittrackee_client/src/components/User/ProfileDisplay/index.vue b/fittrackee_client/src/components/User/ProfileDisplay/index.vue index 952912fa..ad4d4916 100644 --- a/fittrackee_client/src/components/User/ProfileDisplay/index.vue +++ b/fittrackee_client/src/components/User/ProfileDisplay/index.vue @@ -1,55 +1,24 @@ @@ -84,62 +49,5 @@ width: 100%; margin: 0 auto 50px auto; } - - .user-header { - display: flex; - align-items: stretch; - - .user-details { - flex-grow: 1; - padding: $default-padding; - display: flex; - flex-direction: column; - align-items: center; - - .user-name { - font-size: 2em; - height: 60%; - } - - .user-stats { - display: flex; - gap: $default-padding * 4; - .user-stat { - display: flex; - flex-direction: column; - align-items: center; - padding-top: $default-padding; - .stat-number, - .stat-label { - padding: 0 $default-padding * 0.5; - } - .stat-number { - font-weight: bold; - font-size: 1.5em; - } - } - } - - @media screen and (max-width: $x-small-limit) { - .user-name { - font-size: 1.5em; - } - - .user-stats { - gap: $default-padding * 2; - .user-stat { - .stat-number { - font-weight: bold; - font-size: 1.2em; - } - - &.hide-small { - display: none; - } - } - } - } - } - } } diff --git a/fittrackee_client/src/components/User/ProfileEdition/UserInfosEdition.vue b/fittrackee_client/src/components/User/ProfileEdition/UserInfosEdition.vue index cb283522..1c0e8050 100644 --- a/fittrackee_client/src/components/User/ProfileEdition/UserInfosEdition.vue +++ b/fittrackee_client/src/components/User/ProfileEdition/UserInfosEdition.vue @@ -81,7 +81,7 @@ - - diff --git a/fittrackee_client/src/components/User/ProfileEdition/index.vue b/fittrackee_client/src/components/User/ProfileEdition/index.vue index a6ba80de..7cc09128 100644 --- a/fittrackee_client/src/components/User/ProfileEdition/index.vue +++ b/fittrackee_client/src/components/User/ProfileEdition/index.vue @@ -1,7 +1,9 @@ diff --git a/fittrackee_client/src/router/index.ts b/fittrackee_client/src/router/index.ts index 8ebb2112..af8ab7c6 100644 --- a/fittrackee_client/src/router/index.ts +++ b/fittrackee_client/src/router/index.ts @@ -1,18 +1,31 @@ import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router' +import Profile from '@/components/User/ProfileDisplay/index.vue' +import UserInfos from '@/components/User/ProfileDisplay/UserInfos.vue' +import UserPreferences from '@/components/User/ProfileDisplay/UserPreferences.vue' +import ProfileEdition from '@/components/User/ProfileEdition/index.vue' +import UserInfosEdition from '@/components/User/ProfileEdition/UserInfosEdition.vue' +import UserPictureEdition from '@/components/User/ProfileEdition/UserPictureEdition.vue' +import UserPreferencesEdition from '@/components/User/ProfileEdition/UserPreferencesEdition.vue' import store from '@/store' import { USER_STORE } from '@/store/constants' -import AddWorkout from '@/views/AddWorkout.vue' import Dashboard from '@/views/DashBoard.vue' import LoginOrRegister from '@/views/LoginOrRegister.vue' import NotFoundView from '@/views/NotFoundView.vue' import PasswordResetView from '@/views/PasswordResetView.vue' import ProfileView from '@/views/ProfileView.vue' import StatisticsView from '@/views/StatisticsView.vue' +import AddWorkout from '@/views/workouts/AddWorkout.vue' import EditWorkout from '@/views/workouts/EditWorkout.vue' import Workout from '@/views/workouts/Workout.vue' import Workouts from '@/views/workouts/WorkoutsView.vue' +const getTabFromPath = (path: string): string => { + const regex = /(\/profile)(\/edit)*(\/*)/ + const tag = path.replace(regex, '').toUpperCase() + return tag === '' ? 'PROFILE' : tag.toUpperCase() +} + const routes: Array = [ { path: '/', @@ -31,12 +44,6 @@ const routes: Array = [ component: LoginOrRegister, props: { action: 'register' }, }, - { - path: '/profile', - name: 'Profile', - component: ProfileView, - props: { edition: false, tab: 'PROFILE' }, - }, { path: '/password-reset/sent', name: 'PasswordEmailSent', @@ -62,28 +69,56 @@ const routes: Array = [ props: { action: 'reset' }, }, { - path: '/profile/edit/picture', - name: 'UserPictureEdition', + path: '/profile', + name: 'Profile', component: ProfileView, - props: { edition: true, tab: 'PICTURE' }, - }, - { - path: '/profile/preferences', - name: 'UserPreferences', - component: ProfileView, - props: { edition: false, tab: 'PREFERENCES' }, - }, - { - path: '/profile/edit/preferences', - name: 'UserPreferencesEdition', - component: ProfileView, - props: { edition: true, tab: 'PREFERENCES' }, - }, - { - path: '/profile/edit', - name: 'ProfileEdition', - component: ProfileView, - props: { edition: true, tab: 'PROFILE' }, + children: [ + { + path: '', + name: 'UserProfile', + component: Profile, + props: (route) => ({ + tab: getTabFromPath(route.path), + }), + children: [ + { + path: '', + name: 'UserInfos', + component: UserInfos, + }, + { + path: 'preferences', + name: 'UserPreferences', + component: UserPreferences, + }, + ], + }, + { + path: 'edit', + name: 'UserProfileEdition', + component: ProfileEdition, + props: (route) => ({ + tab: getTabFromPath(route.path), + }), + children: [ + { + path: '', + name: 'UserInfosEdition', + component: UserInfosEdition, + }, + { + path: 'picture', + name: 'UserPictureEdition', + component: UserPictureEdition, + }, + { + path: 'preferences', + name: 'UserPreferencesEdition', + component: UserPreferencesEdition, + }, + ], + }, + ], }, { path: '/statistics', diff --git a/fittrackee_client/src/views/ProfileView.vue b/fittrackee_client/src/views/ProfileView.vue index c47a725c..119399eb 100644 --- a/fittrackee_client/src/views/ProfileView.vue +++ b/fittrackee_client/src/views/ProfileView.vue @@ -1,41 +1,24 @@ diff --git a/fittrackee_client/src/views/AddWorkout.vue b/fittrackee_client/src/views/workouts/AddWorkout.vue similarity index 100% rename from fittrackee_client/src/views/AddWorkout.vue rename to fittrackee_client/src/views/workouts/AddWorkout.vue