koel/resources/assets/js/components/user/UserBadge.vue

76 lines
1.5 KiB
Vue
Raw Normal View History

2022-04-15 14:24:30 +00:00
<template>
2022-05-15 15:25:02 +00:00
<span class="profile" id="userBadge" v-if="currentUser">
<a class="view-profile" data-testid="view-profile-link" href="/#/profile" title="View/edit user profile">
2022-05-15 15:25:02 +00:00
<img :alt="`Avatar of ${currentUser.name}`" :src="currentUser.avatar" class="avatar"/>
<span class="name">{{ currentUser.name }}</span>
2022-04-15 14:24:30 +00:00
</a>
<a
2022-04-23 21:48:19 +00:00
title="Log out"
2022-04-15 14:24:30 +00:00
class="logout control"
data-testid="btn-logout"
href
role="button"
2022-04-23 21:48:19 +00:00
@click.prevent="logout"
2022-04-15 14:24:30 +00:00
>
2022-07-15 07:23:55 +00:00
<icon :icon="faSignOutAlt"/>
2022-04-15 14:24:30 +00:00
</a>
</span>
</template>
2022-04-15 17:00:08 +00:00
<script lang="ts" setup>
2022-07-15 07:23:55 +00:00
import { faSignOutAlt } from '@fortawesome/free-solid-svg-icons'
2022-04-15 14:24:30 +00:00
import { eventBus } from '@/utils'
2022-05-15 15:25:02 +00:00
import { useAuthorization } from '@/composables'
2022-04-15 14:24:30 +00:00
2022-05-15 15:25:02 +00:00
const { currentUser } = useAuthorization()
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
const logout = () => eventBus.emit('LOG_OUT')
2022-04-15 14:24:30 +00:00
</script>
<style lang="scss">
#userBadge {
@include vertical-center();
justify-content: flex-end;
position: relative;
.avatar {
width: 24px;
height: 24px;
border-radius: 50%;
margin-right: .5rem;
}
.view-profile {
height: 100%;
@include vertical-center();
}
.logout {
height: 100%;
padding: 0 1.25rem;
@include vertical-center();
}
2022-04-15 17:00:08 +00:00
@media only screen and (max-width: 667px) {
2022-04-15 14:24:30 +00:00
flex: 0 0 96px;
margin-right: 0;
padding-right: 0;
align-content: stretch;
.name {
display: none;
}
.view-profile, .logout {
flex: 0 0 40px;
font-size: 1.4rem;
margin-right: 0;
@include vertical-center();
}
}
}
</style>