sharkey/src/client/app/desktop/views/components/ui.header.account.vue

341 lines
7.5 KiB
Vue
Raw Normal View History

2018-02-12 21:10:16 +09:00
<template>
2018-09-19 02:51:06 +09:00
<div class="account" v-hotkey.global="keymap">
2018-02-12 21:10:16 +09:00
<button class="header" :data-active="isOpen" @click="toggle">
<span class="username">{{ $store.state.i.username }}<template v-if="!isOpen"><fa icon="angle-down"/></template><template v-if="isOpen"><fa icon="angle-up"/></template></span>
2018-05-27 13:49:09 +09:00
<mk-avatar class="avatar" :user="$store.state.i"/>
2018-02-12 21:10:16 +09:00
</button>
2018-02-23 03:33:12 +09:00
<transition name="zoom-in-top">
<div class="menu" v-if="isOpen">
<ul>
<li>
<router-link :to="`/@${ $store.state.i.username }`">
<i><fa icon="user"/></i>
<span>{{ $t('profile') }}</span>
<i><fa icon="angle-right"/></i>
</router-link>
2018-02-23 03:33:12 +09:00
</li>
<li @click="drive">
<p>
<i><fa icon="cloud"/></i>
<span>{{ $t('@.drive') }}</span>
<i><fa icon="angle-right"/></i>
</p>
2018-02-23 03:33:12 +09:00
</li>
2018-04-20 12:38:31 +09:00
<li>
<router-link to="/i/favorites">
<i><fa icon="star"/></i>
<span>{{ $t('favorites') }}</span>
<i><fa icon="angle-right"/></i>
</router-link>
2018-04-20 12:38:31 +09:00
</li>
2018-04-24 21:24:06 +09:00
<li @click="list">
<p>
<i><fa icon="list"/></i>
<span>{{ $t('lists') }}</span>
<i><fa icon="angle-right"/></i>
</p>
2018-04-24 21:24:06 +09:00
</li>
2018-10-13 20:11:00 +09:00
<li @click="followRequests" v-if="($store.state.i.isLocked || $store.state.i.carefulBot)">
<p>
<i><fa :icon="['far', 'envelope']"/></i>
<span>{{ $t('follow-requests') }}<i v-if="$store.state.i.pendingReceivedFollowRequestsCount">{{ $store.state.i.pendingReceivedFollowRequestsCount }}</i></span>
<i><fa icon="angle-right"/></i>
</p>
2018-06-02 13:34:53 +09:00
</li>
2018-02-23 03:33:12 +09:00
</ul>
<ul>
<li>
<router-link to="/i/settings">
<i><fa icon="cog"/></i>
<span>{{ $t('settings') }}</span>
<i><fa icon="angle-right"/></i>
</router-link>
2018-02-23 03:33:12 +09:00
</li>
2018-11-15 04:15:42 +09:00
<li v-if="$store.state.i.isAdmin || $store.state.i.isModerator">
<a href="/admin">
<i><fa icon="terminal"/></i>
<span>{{ $t('admin') }}</span>
<i><fa icon="angle-right"/></i>
</a>
2018-04-20 07:45:37 +09:00
</li>
</ul>
<ul>
2019-02-16 06:50:58 +09:00
<li @click="toggleDeckMode">
<p>
<span>{{ $t('@.deck') }}</span>
<template v-if="$store.state.device.inDeckMode"><i><fa :icon="faHome"/></i></template>
2019-02-16 06:50:58 +09:00
<template v-else><i><fa :icon="faColumns"/></i></template>
</p>
</li>
2018-04-20 07:45:37 +09:00
<li @click="dark">
<p>
<span>{{ $t('dark') }}</span>
<template v-if="$store.state.device.darkmode"><i><fa icon="moon"/></i></template>
<template v-else><i><fa :icon="['far', 'moon']"/></i></template>
</p>
2018-02-23 03:33:12 +09:00
</li>
</ul>
2018-08-23 02:47:12 +09:00
<ul>
<li @click="signout">
<p class="signout">
<i><fa icon="power-off"/></i>
<span>{{ $t('signout') }}</span>
</p>
2018-08-23 02:47:12 +09:00
</li>
</ul>
2018-02-23 03:33:12 +09:00
</div>
</transition>
2018-02-12 21:10:16 +09:00
</div>
</template>
<script lang="ts">
import Vue from 'vue';
import i18n from '../../../i18n';
2018-04-25 22:37:08 +09:00
import MkUserListsWindow from './user-lists-window.vue';
import MkUserListWindow from './user-list-window.vue';
2018-06-02 16:13:32 +09:00
import MkFollowRequestsWindow from './received-follow-requests-window.vue';
2018-02-13 08:24:44 +09:00
import MkSettingsWindow from './settings-window.vue';
2018-02-18 23:51:41 +09:00
import MkDriveWindow from './drive-window.vue';
2018-02-12 21:10:16 +09:00
import contains from '../../../common/scripts/contains';
2019-02-16 06:50:58 +09:00
import { faHome, faColumns } from '@fortawesome/free-solid-svg-icons';
2018-02-12 21:10:16 +09:00
export default Vue.extend({
i18n: i18n('desktop/views/components/ui.header.account.vue'),
2018-02-12 21:10:16 +09:00
data() {
return {
2019-02-16 06:50:58 +09:00
isOpen: false,
faHome, faColumns
2018-02-12 21:10:16 +09:00
};
},
2018-09-19 02:51:06 +09:00
computed: {
keymap(): any {
return {
'a|m': this.toggle
};
}
},
2018-02-12 21:10:16 +09:00
beforeDestroy() {
this.close();
},
methods: {
toggle() {
this.isOpen ? this.close() : this.open();
},
open() {
this.isOpen = true;
for (const el of Array.from(document.querySelectorAll('body *'))) {
2018-02-12 21:10:16 +09:00
el.addEventListener('mousedown', this.onMousedown);
}
2018-02-12 21:10:16 +09:00
},
close() {
this.isOpen = false;
for (const el of Array.from(document.querySelectorAll('body *'))) {
2018-02-12 21:10:16 +09:00
el.removeEventListener('mousedown', this.onMousedown);
}
2018-02-12 21:10:16 +09:00
},
onMousedown(e) {
e.preventDefault();
if (!contains(this.$el, e.target) && this.$el != e.target) this.close();
return false;
},
drive() {
this.close();
2018-11-09 08:13:34 +09:00
this.$root.new(MkDriveWindow);
2018-02-12 21:10:16 +09:00
},
2018-04-25 12:36:54 +09:00
list() {
this.close();
2018-11-09 08:13:34 +09:00
const w = this.$root.new(MkUserListsWindow);
2018-04-25 23:08:40 +09:00
w.$once('choosen', list => {
this.$root.new(MkUserListWindow, {
list
});
2018-04-25 23:08:40 +09:00
});
2018-04-25 12:36:54 +09:00
},
2018-06-02 13:34:53 +09:00
followRequests() {
this.close();
2018-11-09 08:13:34 +09:00
this.$root.new(MkFollowRequestsWindow);
2018-06-02 13:34:53 +09:00
},
2018-02-26 19:23:53 +09:00
signout() {
2018-11-09 18:25:21 +09:00
this.$root.signout();
2018-04-20 07:45:37 +09:00
},
dark() {
2018-05-24 05:28:46 +09:00
this.$store.commit('device/set', {
key: 'darkmode',
value: !this.$store.state.device.darkmode
});
2019-02-16 06:50:58 +09:00
},
toggleDeckMode() {
this.$store.commit('device/set', { key: 'deckMode', value: !this.$store.state.device.inDeckMode });
location.replace('/');
2019-02-16 06:50:58 +09:00
},
2018-02-12 21:10:16 +09:00
}
});
</script>
<style lang="stylus" scoped>
2018-09-27 22:55:17 +09:00
.account
2018-02-12 21:10:16 +09:00
> .header
display block
margin 0
padding 0
2018-09-27 15:19:11 +09:00
color var(--desktopHeaderFg)
2018-02-12 21:10:16 +09:00
border none
background transparent
cursor pointer
*
pointer-events none
&:hover
&[data-active='true']
2018-09-27 15:19:11 +09:00
color var(--desktopHeaderHoverFg)
2018-02-12 21:10:16 +09:00
> .avatar
filter saturate(150%)
> .username
display block
float left
margin 0 12px 0 16px
max-width 16em
line-height 48px
font-weight bold
font-family Meiryo, sans-serif
text-decoration none
2018-10-15 17:43:25 +09:00
@media (max-width 1100px)
display none
[data-icon]
2018-02-12 21:10:16 +09:00
margin-left 8px
> .avatar
display block
float left
min-width 32px
max-width 32px
min-height 32px
max-height 32px
margin 8px 8px 8px 0
border-radius 4px
transition filter 100ms ease
2018-10-15 17:43:25 +09:00
@media (max-width 1100px)
margin-left 8px
2018-02-12 21:10:16 +09:00
> .menu
2018-09-26 20:28:13 +09:00
$bgcolor = var(--face)
2018-02-12 21:10:16 +09:00
display block
position absolute
top 56px
right -2px
width 230px
font-size 0.8em
2018-04-20 07:45:37 +09:00
background $bgcolor
2018-02-12 21:10:16 +09:00
border-radius 4px
2018-12-30 14:00:57 +09:00
box-shadow 0 var(--lineWidth) 4px rgba(#000, 0.25)
2018-02-12 21:10:16 +09:00
&:before
content ""
pointer-events none
display block
position absolute
top -28px
right 12px
border-top solid 14px transparent
border-right solid 14px transparent
2018-04-29 08:51:17 +09:00
border-bottom solid 14px rgba(#000, 0.1)
2018-02-12 21:10:16 +09:00
border-left solid 14px transparent
&:after
content ""
pointer-events none
display block
position absolute
top -27px
right 12px
border-top solid 14px transparent
border-right solid 14px transparent
2018-04-20 07:45:37 +09:00
border-bottom solid 14px $bgcolor
2018-02-12 21:10:16 +09:00
border-left solid 14px transparent
ul
display block
margin 10px 0
padding 0
list-style none
& + ul
padding-top 10px
2018-12-30 14:00:57 +09:00
border-top solid var(--lineWidth) var(--faceDivider)
2018-02-12 21:10:16 +09:00
> li
display block
margin 0
padding 0
> a
> p
display block
z-index 1
padding 0 28px
margin 0
line-height 40px
2018-09-27 22:55:17 +09:00
color var(--text)
2018-02-12 21:10:16 +09:00
cursor pointer
*
pointer-events none
2018-04-20 07:45:37 +09:00
> span:first-child
2018-04-20 12:38:31 +09:00
padding-left 22px
2018-04-20 07:45:37 +09:00
2018-06-02 13:34:53 +09:00
> span:nth-child(2)
> i
margin-left 4px
padding 2px 8px
font-size 90%
2018-06-02 15:51:43 +09:00
font-style normal
2018-09-26 20:19:35 +09:00
background var(--primary)
color var(--primaryForeground)
2018-06-02 13:34:53 +09:00
border-radius 8px
> i:first-child
2018-02-12 21:10:16 +09:00
margin-right 6px
2018-04-20 07:45:37 +09:00
width 16px
2018-02-12 21:10:16 +09:00
> i:last-child
2018-02-12 21:10:16 +09:00
display block
position absolute
top 0
right 8px
z-index 1
padding 0 20px
font-size 1.2em
line-height 40px
&:hover, &:active
text-decoration none
2018-09-26 20:19:35 +09:00
background var(--primary)
color var(--primaryForeground)
2018-02-12 21:10:16 +09:00
2018-02-23 03:33:12 +09:00
&:active
2018-09-26 20:19:35 +09:00
background var(--primaryDarken10)
2018-02-23 03:33:12 +09:00
2018-04-20 12:38:31 +09:00
&.signout
$color = #e64137
&:hover, &:active
background $color
color #fff
&:active
background darken($color, 10%)
2018-02-23 03:33:12 +09:00
.zoom-in-top-enter-active,
.zoom-in-top-leave-active {
transform-origin: center -16px;
}
2018-02-12 21:10:16 +09:00
</style>