2021-07-25 13:03:34 +02:00
|
|
|
<template>
|
|
|
|
<div id="nav">
|
2021-08-07 18:10:32 +02:00
|
|
|
<div class="nav-container">
|
2021-08-04 09:10:00 +02:00
|
|
|
<div class="nav-app-name">
|
2021-08-07 18:10:32 +02:00
|
|
|
<div class="nav-item app-name" @click="$router.push('/')">
|
|
|
|
FitTrackee
|
|
|
|
</div>
|
2021-07-25 17:08:22 +02:00
|
|
|
</div>
|
2021-08-04 09:10:00 +02:00
|
|
|
<div class="nav-icon-open" :class="{ 'menu-open': isMenuOpen }">
|
|
|
|
<i class="fa fa-bars hamburger-icon" @click="openMenu()"></i>
|
2021-07-25 17:08:22 +02:00
|
|
|
</div>
|
2021-08-04 09:10:00 +02:00
|
|
|
<div class="nav-items" :class="{ 'menu-open': isMenuOpen }">
|
|
|
|
<div class="nav-items-close">
|
2021-08-04 13:59:51 +02:00
|
|
|
<div class="app-name">FitTrackee</div>
|
2021-08-04 09:10:00 +02:00
|
|
|
<i
|
|
|
|
class="fa fa-close close-icon nav-item"
|
|
|
|
:class="{ 'menu-closed': !isMenuOpen }"
|
|
|
|
@click="closeMenu()"
|
|
|
|
></i>
|
|
|
|
</div>
|
|
|
|
<div class="nav-items-app-menu" @click="closeMenu()">
|
2021-08-04 20:22:08 +02:00
|
|
|
<div class="nav-items-group" v-if="isAuthenticated">
|
|
|
|
<router-link class="nav-item" to="/">{{
|
|
|
|
t('dashboard.DASHBOARD')
|
|
|
|
}}</router-link>
|
2021-08-18 17:10:16 +02:00
|
|
|
<div class="nav-item">
|
|
|
|
{{ capitalize(t('workouts.WORKOUT', 1)) }}
|
|
|
|
</div>
|
2021-08-04 20:22:08 +02:00
|
|
|
<div class="nav-item">{{ t('statistics.STATISTICS') }}</div>
|
|
|
|
<div class="nav-item">{{ t('administration.ADMIN') }}</div>
|
|
|
|
<div class="nav-item">{{ t('workouts.ADD_WORKOUT') }}</div>
|
2021-08-14 19:59:22 +02:00
|
|
|
<div class="nav-item nav-separator" />
|
2021-08-04 20:22:08 +02:00
|
|
|
</div>
|
2021-08-04 09:10:00 +02:00
|
|
|
</div>
|
|
|
|
<div class="nav-items-user-menu">
|
2021-08-04 20:22:08 +02:00
|
|
|
<div class="nav-items-group" v-if="isAuthenticated">
|
2021-08-14 19:59:22 +02:00
|
|
|
<div class="nav-item nav-profile-img">
|
2021-08-14 18:06:50 +02:00
|
|
|
<img
|
|
|
|
v-if="authUserPictureUrl !== ''"
|
2021-08-14 19:59:22 +02:00
|
|
|
class="nav-profile-user-img"
|
2021-08-14 18:06:50 +02:00
|
|
|
alt="User picture"
|
|
|
|
:src="authUserPictureUrl"
|
|
|
|
/>
|
|
|
|
<div v-else class="no-picture">
|
|
|
|
<i class="fa fa-user-circle-o" aria-hidden="true" />
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-08-11 21:24:23 +02:00
|
|
|
<div class="nav-item">{{ authUser.username }}</div>
|
2021-08-14 18:58:59 +02:00
|
|
|
<div class="nav-item nav-link" @click="logout">
|
|
|
|
{{ t('user.LOGOUT') }}
|
|
|
|
</div>
|
2021-08-04 20:22:08 +02:00
|
|
|
</div>
|
|
|
|
<div class="nav-items-group" v-else>
|
2021-08-08 11:49:01 +02:00
|
|
|
<router-link class="nav-item" to="/login" @click="closeMenu">{{
|
|
|
|
t('user.LOGIN')
|
|
|
|
}}</router-link>
|
2021-08-14 19:59:22 +02:00
|
|
|
<router-link class="nav-item" to="/register" @click="closeMenu">{{
|
|
|
|
t('user.REGISTER')
|
|
|
|
}}</router-link>
|
2021-08-04 20:22:08 +02:00
|
|
|
</div>
|
2021-08-04 13:59:51 +02:00
|
|
|
<Dropdown
|
|
|
|
v-if="availableLanguages && language"
|
|
|
|
class="nav-item"
|
|
|
|
:options="availableLanguages"
|
|
|
|
:selected="language"
|
|
|
|
@selected="updateLanguage"
|
|
|
|
>
|
|
|
|
<i class="fa fa-language"></i>
|
|
|
|
</Dropdown>
|
2021-08-04 09:10:00 +02:00
|
|
|
</div>
|
2021-07-25 17:08:22 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-07-25 13:03:34 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2021-08-11 22:12:02 +02:00
|
|
|
import { ComputedRef, computed, defineComponent, ref } from 'vue'
|
2021-08-04 09:53:17 +02:00
|
|
|
import { useI18n } from 'vue-i18n'
|
2021-08-04 13:59:51 +02:00
|
|
|
|
2021-08-21 18:34:06 +02:00
|
|
|
import Dropdown from '@/components/Common/Dropdown.vue'
|
2021-08-11 22:12:02 +02:00
|
|
|
import { ROOT_STORE, USER_STORE } from '@/store/constants'
|
2021-08-21 18:36:44 +02:00
|
|
|
import { IDropdownOption } from '@/types/forms'
|
|
|
|
import { IAuthUserProfile } from '@/types/user'
|
2021-08-11 22:21:26 +02:00
|
|
|
import { useStore } from '@/use/useStore'
|
2021-08-18 17:10:16 +02:00
|
|
|
import { capitalize, getApiUrl } from '@/utils'
|
2021-07-25 13:03:34 +02:00
|
|
|
|
2021-07-25 13:23:25 +02:00
|
|
|
export default defineComponent({
|
|
|
|
name: 'NavBar',
|
2021-08-04 13:59:51 +02:00
|
|
|
components: {
|
|
|
|
Dropdown,
|
|
|
|
},
|
2021-07-25 17:08:22 +02:00
|
|
|
setup() {
|
2021-08-04 13:59:51 +02:00
|
|
|
const { t, locale, availableLocales } = useI18n()
|
|
|
|
const store = useStore()
|
2021-08-14 18:06:50 +02:00
|
|
|
|
2021-08-04 13:59:51 +02:00
|
|
|
const availableLanguages = availableLocales.map((l) => {
|
|
|
|
return { label: l.toUpperCase(), value: l }
|
|
|
|
})
|
2021-08-11 22:12:02 +02:00
|
|
|
const authUser: ComputedRef<IAuthUserProfile> = computed(
|
|
|
|
() => store.getters[USER_STORE.GETTERS.AUTH_USER_PROFILE]
|
|
|
|
)
|
|
|
|
const isAuthenticated: ComputedRef<boolean> = computed(
|
|
|
|
() => store.getters[USER_STORE.GETTERS.IS_AUTHENTICATED]
|
|
|
|
)
|
2021-08-14 18:06:50 +02:00
|
|
|
const authUserPictureUrl: ComputedRef<string> = computed(() =>
|
|
|
|
isAuthenticated.value && authUser.value.picture
|
|
|
|
? `${getApiUrl()}/users/${
|
|
|
|
authUser.value.username
|
|
|
|
}/picture?${Date.now()}`
|
|
|
|
: ''
|
|
|
|
)
|
2021-08-11 22:12:02 +02:00
|
|
|
const language: ComputedRef<string> = computed(
|
|
|
|
() => store.getters[ROOT_STORE.GETTERS.LANGUAGE]
|
|
|
|
)
|
2021-07-25 17:08:22 +02:00
|
|
|
let isMenuOpen = ref(false)
|
2021-08-14 18:06:50 +02:00
|
|
|
|
2021-07-25 17:08:22 +02:00
|
|
|
function openMenu() {
|
|
|
|
isMenuOpen.value = true
|
|
|
|
}
|
|
|
|
function closeMenu() {
|
|
|
|
isMenuOpen.value = false
|
|
|
|
}
|
2021-08-04 13:59:51 +02:00
|
|
|
function updateLanguage(option: IDropdownOption) {
|
|
|
|
locale.value = option.value.toString()
|
2021-08-11 22:12:02 +02:00
|
|
|
store.commit(ROOT_STORE.MUTATIONS.UPDATE_LANG, option.value)
|
2021-08-04 13:59:51 +02:00
|
|
|
}
|
2021-08-14 18:58:59 +02:00
|
|
|
function logout() {
|
|
|
|
store.dispatch(USER_STORE.ACTIONS.LOGOUT)
|
|
|
|
}
|
2021-08-04 13:59:51 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
availableLanguages,
|
2021-08-11 22:12:02 +02:00
|
|
|
authUser,
|
2021-08-14 18:06:50 +02:00
|
|
|
authUserPictureUrl,
|
2021-08-11 22:12:02 +02:00
|
|
|
isAuthenticated,
|
2021-08-04 13:59:51 +02:00
|
|
|
isMenuOpen,
|
2021-08-11 22:12:02 +02:00
|
|
|
language,
|
2021-08-04 13:59:51 +02:00
|
|
|
t,
|
2021-08-18 17:10:16 +02:00
|
|
|
capitalize,
|
2021-08-04 13:59:51 +02:00
|
|
|
openMenu,
|
|
|
|
closeMenu,
|
|
|
|
updateLanguage,
|
2021-08-14 18:58:59 +02:00
|
|
|
logout,
|
2021-08-04 13:59:51 +02:00
|
|
|
}
|
2021-07-25 17:08:22 +02:00
|
|
|
},
|
2021-07-25 13:23:25 +02:00
|
|
|
})
|
2021-07-25 13:03:34 +02:00
|
|
|
</script>
|
|
|
|
|
2021-07-25 17:08:22 +02:00
|
|
|
<style scoped lang="scss">
|
2021-08-04 09:10:00 +02:00
|
|
|
@import '~@/scss/base';
|
|
|
|
|
2021-07-25 17:08:22 +02:00
|
|
|
#nav {
|
2021-08-04 09:10:00 +02:00
|
|
|
background: var(--nav-bar-background-color);
|
2021-07-25 17:08:22 +02:00
|
|
|
display: flex;
|
2021-08-04 09:10:00 +02:00
|
|
|
padding: 15px 10px;
|
2021-07-25 17:08:22 +02:00
|
|
|
|
2021-08-07 18:10:32 +02:00
|
|
|
.nav-container {
|
|
|
|
display: flex;
|
|
|
|
|
|
|
|
margin-left: auto;
|
|
|
|
margin-right: auto;
|
|
|
|
padding: 0 15px 15px 15px;
|
|
|
|
max-width: $container-width;
|
|
|
|
width: 100%;
|
|
|
|
|
|
|
|
border-bottom: solid 1px var(--nav-border-color);
|
|
|
|
}
|
|
|
|
|
2021-07-25 17:08:22 +02:00
|
|
|
a {
|
|
|
|
&.router-link-exact-active {
|
2021-08-04 09:10:00 +02:00
|
|
|
color: var(--nav-bar-link-active);
|
2021-08-14 19:59:22 +02:00
|
|
|
font-weight: bold;
|
2021-07-25 17:08:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.app-name {
|
|
|
|
font-size: 1.2em;
|
|
|
|
font-weight: bold;
|
2021-08-04 09:10:00 +02:00
|
|
|
margin-right: 10px;
|
2021-08-07 18:10:32 +02:00
|
|
|
|
|
|
|
&:hover {
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
2021-07-25 17:08:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
.fa {
|
|
|
|
font-size: 1.2em;
|
|
|
|
}
|
|
|
|
|
|
|
|
.nav-icon-open {
|
|
|
|
display: none;
|
|
|
|
}
|
2021-08-04 13:59:51 +02:00
|
|
|
|
2021-07-25 17:08:22 +02:00
|
|
|
.hamburger-icon,
|
|
|
|
.close-icon {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
.nav-items {
|
|
|
|
display: flex;
|
|
|
|
flex: 1;
|
|
|
|
justify-content: space-between;
|
2021-08-14 18:06:50 +02:00
|
|
|
line-height: 1.8em;
|
2021-07-25 17:08:22 +02:00
|
|
|
width: 100%;
|
|
|
|
|
|
|
|
.nav-items-close {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
2021-08-04 13:59:51 +02:00
|
|
|
.nav-items-app-menu,
|
|
|
|
.nav-items-user-menu {
|
|
|
|
display: flex;
|
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
|
|
|
}
|
|
|
|
|
2021-08-04 20:22:08 +02:00
|
|
|
.nav-items-group {
|
|
|
|
display: flex;
|
|
|
|
}
|
2021-07-25 17:08:22 +02:00
|
|
|
.nav-item {
|
2021-08-04 13:59:51 +02:00
|
|
|
padding: 0 10px;
|
|
|
|
|
|
|
|
&.dropdown-wrapper {
|
|
|
|
width: 60px;
|
|
|
|
}
|
|
|
|
|
|
|
|
::v-deep(.dropdown-list) {
|
|
|
|
margin-left: -10px;
|
|
|
|
padding-left: 10px;
|
|
|
|
width: 75px;
|
|
|
|
}
|
2021-07-25 17:08:22 +02:00
|
|
|
}
|
2021-08-14 18:06:50 +02:00
|
|
|
|
2021-08-14 18:58:59 +02:00
|
|
|
.nav-link {
|
|
|
|
color: var(--app-a-color);
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
|
2021-08-14 18:06:50 +02:00
|
|
|
.nav-profile-img {
|
|
|
|
margin-bottom: -$default-padding;
|
2021-08-14 19:59:22 +02:00
|
|
|
.nav-profile-user-img {
|
|
|
|
border-radius: 50%;
|
|
|
|
height: 32px;
|
|
|
|
width: 32px;
|
|
|
|
object-fit: cover;
|
|
|
|
}
|
|
|
|
.no-picture {
|
|
|
|
color: var(--app-a-color);
|
|
|
|
font-size: 1.7em;
|
|
|
|
}
|
2021-08-14 18:06:50 +02:00
|
|
|
}
|
2021-08-14 19:59:22 +02:00
|
|
|
|
|
|
|
.nav-separator {
|
|
|
|
display: none;
|
2021-08-14 18:06:50 +02:00
|
|
|
}
|
2021-07-25 17:08:22 +02:00
|
|
|
}
|
|
|
|
|
2021-08-04 09:10:00 +02:00
|
|
|
@media screen and (max-width: $medium-limit) {
|
2021-07-25 17:08:22 +02:00
|
|
|
.hamburger-icon {
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
.nav-icon-open {
|
|
|
|
display: block;
|
|
|
|
text-align: right;
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
.nav-icon-open.menu-open {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
.close-icon {
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
.close-icon.menu-closed {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
.nav-items {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
.nav-items.menu-open {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
justify-content: flex-start;
|
|
|
|
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
right: 0;
|
|
|
|
bottom: 0;
|
|
|
|
left: 0;
|
|
|
|
|
2021-08-04 09:10:00 +02:00
|
|
|
background: var(--nav-bar-background-color);
|
2021-07-25 17:08:22 +02:00
|
|
|
|
|
|
|
.nav-items-close,
|
|
|
|
.nav-items-app-menu,
|
|
|
|
.nav-items-user-menu {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
}
|
|
|
|
|
|
|
|
.nav-items-close {
|
|
|
|
align-items: center;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
|
|
.app-name {
|
2021-08-04 13:59:51 +02:00
|
|
|
padding: 15px 25px;
|
2021-07-25 17:08:22 +02:00
|
|
|
}
|
|
|
|
}
|
2021-08-04 13:59:51 +02:00
|
|
|
|
2021-08-04 20:22:08 +02:00
|
|
|
.nav-items-group {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
}
|
|
|
|
|
2021-08-04 13:59:51 +02:00
|
|
|
.nav-item {
|
|
|
|
padding: 7px 25px;
|
|
|
|
}
|
2021-08-14 19:59:22 +02:00
|
|
|
|
|
|
|
.nav-profile-img {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
.nav-separator {
|
|
|
|
display: flex;
|
|
|
|
border-top: solid 1px var(--nav-border-color);
|
|
|
|
margin: 0 $default-margin * 2;
|
|
|
|
padding: 0;
|
|
|
|
}
|
2021-07-25 17:08:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|