2018-07-31 20:09:18 +02:00
|
|
|
const html = require('choo/html');
|
|
|
|
|
2018-08-08 00:40:17 +02:00
|
|
|
module.exports = function(state, emit) {
|
2018-09-14 22:58:19 +02:00
|
|
|
if (!state.capabilities.account) {
|
|
|
|
return null;
|
|
|
|
}
|
2018-08-08 00:40:17 +02:00
|
|
|
const user = state.user;
|
|
|
|
const menu = user.loggedIn
|
|
|
|
? html`
|
2018-09-14 22:58:19 +02:00
|
|
|
<ul
|
|
|
|
class="account_dropdown"
|
|
|
|
onblur=${hideMenu}
|
|
|
|
tabindex="-1">
|
2018-08-08 00:40:17 +02:00
|
|
|
<li class="account_dropdown__text">
|
|
|
|
${user.email}
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<a class="account_dropdown__link" onclick=${logout}>${state.translate(
|
|
|
|
'logOut'
|
|
|
|
)}</a>
|
|
|
|
</li>
|
|
|
|
</ul>`
|
|
|
|
: html`
|
2018-09-14 22:58:19 +02:00
|
|
|
<ul
|
|
|
|
class="account_dropdown"
|
|
|
|
onblur=${hideMenu}
|
|
|
|
tabindex="-1">
|
2018-08-03 21:24:41 +02:00
|
|
|
<li>
|
2018-08-08 00:40:17 +02:00
|
|
|
<a class="account_dropdown__link" onclick=${login}>${state.translate(
|
|
|
|
'signInMenuOption'
|
|
|
|
)}</a>
|
2018-08-03 21:24:41 +02:00
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
`;
|
|
|
|
|
2018-07-31 20:09:18 +02:00
|
|
|
return html`
|
|
|
|
<div class="account">
|
2018-08-08 00:40:17 +02:00
|
|
|
<div class="account__avatar">
|
|
|
|
<img
|
|
|
|
class="account__avatar"
|
|
|
|
src="${user.avatar}"
|
|
|
|
onclick=${avatarClick}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
${menu}
|
2018-07-31 20:09:18 +02:00
|
|
|
</div>`;
|
|
|
|
|
2018-08-03 21:24:41 +02:00
|
|
|
function avatarClick(event) {
|
2018-07-31 20:09:18 +02:00
|
|
|
event.preventDefault();
|
|
|
|
const dropdown = document.querySelector('.account_dropdown');
|
|
|
|
dropdown.classList.toggle('visible');
|
2018-08-03 21:24:41 +02:00
|
|
|
dropdown.focus();
|
|
|
|
}
|
|
|
|
|
2018-08-08 00:40:17 +02:00
|
|
|
function login(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
emit('login');
|
|
|
|
}
|
|
|
|
|
|
|
|
function logout(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
emit('logout');
|
|
|
|
}
|
|
|
|
|
2018-08-03 21:24:41 +02:00
|
|
|
function hideMenu(event) {
|
|
|
|
event.stopPropagation();
|
|
|
|
const dropdown = document.querySelector('.account_dropdown');
|
|
|
|
dropdown.classList.remove('visible');
|
2018-07-31 20:09:18 +02:00
|
|
|
}
|
|
|
|
};
|