mizzkey/src/client/app/desktop/views/home/user/user.header.vue

280 lines
6.6 KiB
Vue
Raw Normal View History

2018-02-14 16:32:13 +01:00
<template>
2018-03-29 07:48:47 +02:00
<div class="header" :data-is-dark-background="user.bannerUrl != null">
2018-05-07 10:05:05 +02:00
<div class="banner-container" :style="style">
<div class="banner" ref="banner" :style="style" @click="onBannerClick"></div>
2018-04-18 12:47:56 +02:00
<div class="fade"></div>
2018-02-14 16:32:13 +01:00
<div class="title">
<p class="name">
2018-12-06 03:18:13 +01:00
<mk-user-name :user="user"/>
</p>
2018-06-23 15:55:32 +02:00
<div>
2018-09-05 20:21:11 +02:00
<span class="username"><mk-acct :user="user" :detail="true" /></span>
<span v-if="user.isBot" :title="$t('is-bot')"><fa icon="robot"/></span>
2018-06-23 15:55:32 +02:00
</div>
2018-02-14 16:32:13 +01:00
</div>
2018-06-20 12:55:34 +02:00
</div>
<mk-avatar class="avatar" :user="user" :disable-preview="true"/>
<div class="body">
<div class="actions" v-if="$store.getters.isSignedIn">
<template v-if="$store.state.i.id != user.id">
2019-02-14 21:51:22 +01:00
<span class="followed" v-if="user.isFollowed">{{ $t('follows-you') }}</span>
<mk-follow-button :user="user" :inline="true" class="follow"/>
</template>
<ui-button @click="menu" ref="menu" :inline="true"><fa icon="ellipsis-h"/></ui-button>
</div>
2018-06-23 15:55:32 +02:00
<div class="description">
<mfm v-if="user.description" :text="user.description" :author="user" :i="$store.state.i" :custom-emojis="user.emojis"/>
2018-06-23 15:55:32 +02:00
</div>
2018-12-11 12:18:12 +01:00
<div class="fields" v-if="user.fields">
<dl class="field" v-for="(field, i) in user.fields" :key="i">
2018-12-11 18:46:40 +01:00
<dt class="name">
<mfm :text="field.name" :should-break="false" :plain-text="true" :custom-emojis="user.emojis"/>
2018-12-11 18:46:40 +01:00
</dt>
2018-12-11 12:18:12 +01:00
<dd class="value">
<mfm :text="field.value" :author="user" :i="$store.state.i" :custom-emojis="user.emojis"/>
2018-12-11 12:18:12 +01:00
</dd>
</dl>
</div>
2018-10-13 06:25:07 +02:00
<div class="info">
<span class="location" v-if="user.host === null && user.profile.location"><fa icon="map-marker"/> {{ user.profile.location }}</span>
2018-11-09 16:28:50 +01:00
<span class="birthday" v-if="user.host === null && user.profile.birthday"><fa icon="birthday-cake"/> {{ user.profile.birthday.replace('-', $t('year')).replace('-', $t('month')) + $t('day') }} ({{ $t('years-old', { age }) }})</span>
2018-10-13 06:25:07 +02:00
</div>
2018-06-23 15:55:32 +02:00
<div class="status">
<span class="notes-count"><b>{{ user.notesCount | number }}</b>{{ $t('posts') }}</span>
2018-11-09 05:53:44 +01:00
<router-link :to="user | userPage('following')" class="following clickable"><b>{{ user.followingCount | number }}</b>{{ $t('following') }}</router-link>
<router-link :to="user | userPage('followers')" class="followers clickable"><b>{{ user.followersCount | number }}</b>{{ $t('followers') }}</router-link>
2018-06-23 15:55:32 +02:00
</div>
2018-02-14 16:32:13 +01:00
</div>
</div>
</template>
<script lang="ts">
import Vue from 'vue';
import i18n from '../../../../i18n';
2018-06-23 16:18:39 +02:00
import * as age from 's-age';
import XUserMenu from '../../../../common/views/components/user-menu.vue';
2018-02-14 16:32:13 +01:00
export default Vue.extend({
i18n: i18n('desktop/views/pages/user/user.header.vue'),
2018-02-14 16:32:13 +01:00
props: ['user'],
2018-05-07 10:05:05 +02:00
computed: {
style(): any {
if (this.user.bannerUrl == null) return {};
return {
backgroundColor: this.user.bannerColor && this.user.bannerColor.length == 3 ? `rgb(${ this.user.bannerColor.join(',') })` : null,
2018-05-07 10:05:05 +02:00
backgroundImage: `url(${ this.user.bannerUrl })`
};
2018-06-23 16:18:39 +02:00
},
age(): number {
return age(this.user.profile.birthday);
2018-05-07 10:05:05 +02:00
}
},
2018-02-14 16:32:13 +01:00
mounted() {
2018-04-15 11:38:40 +02:00
if (this.user.bannerUrl) {
2018-06-20 18:46:35 +02:00
//window.addEventListener('load', this.onScroll);
//window.addEventListener('scroll', this.onScroll, { passive: true });
//window.addEventListener('resize', this.onScroll);
2018-04-15 11:38:40 +02:00
}
2018-02-14 16:32:13 +01:00
},
beforeDestroy() {
2018-04-15 11:38:40 +02:00
if (this.user.bannerUrl) {
2018-06-20 18:46:35 +02:00
//window.removeEventListener('load', this.onScroll);
//window.removeEventListener('scroll', this.onScroll);
//window.removeEventListener('resize', this.onScroll);
2018-04-15 11:38:40 +02:00
}
2018-02-14 16:32:13 +01:00
},
methods: {
2018-12-27 15:14:30 +01:00
mention() {
this.$post({ mention: this.user });
},
2018-02-14 16:32:13 +01:00
onScroll() {
const banner = this.$refs.banner as any;
const top = window.scrollY;
const z = 1.25; // 奥行き(小さいほど奥)
const pos = -(top / z);
banner.style.backgroundPosition = `center calc(50% - ${pos}px)`;
const blur = top / 32
if (blur <= 10) banner.style.filter = `blur(${blur}px)`;
},
onBannerClick() {
2018-05-27 06:49:09 +02:00
if (!this.$store.getters.isSignedIn || this.$store.state.i.id != this.user.id) return;
2018-02-14 16:32:13 +01:00
this.$updateBanner().then(i => {
2018-03-29 07:48:47 +02:00
this.user.bannerUrl = i.bannerUrl;
2018-02-14 16:32:13 +01:00
});
},
menu() {
this.$root.new(XUserMenu, {
source: this.$refs.menu.$el,
user: this.user
});
}
2018-02-14 16:32:13 +01:00
}
});
</script>
<style lang="stylus" scoped>
2018-09-28 07:26:20 +02:00
.header
2018-09-26 13:28:13 +02:00
background var(--face)
2018-09-22 13:39:12 +02:00
box-shadow var(--shadow)
border-radius var(--round)
2018-02-14 16:32:13 +01:00
overflow hidden
&[data-is-dark-background]
> .banner-container
> .banner
background-color #383838
2018-04-18 12:47:56 +02:00
> .fade
2018-04-29 01:51:17 +02:00
background linear-gradient(transparent, rgba(#000, 0.7))
2018-02-14 16:32:13 +01:00
> .title
color #fff
> .name
text-shadow 0 0 8px #000
> .banner-container
2018-06-20 12:55:34 +02:00
height 250px
2018-02-14 16:32:13 +01:00
overflow hidden
background-size cover
background-position center
> .banner
height 100%
2018-04-15 12:24:21 +02:00
background-color #bfccd0
2018-02-14 16:32:13 +01:00
background-size cover
background-position center
2018-04-18 12:47:56 +02:00
> .fade
position absolute
bottom 0
left 0
width 100%
height 78px
2018-02-14 16:32:13 +01:00
> .title
position absolute
2018-06-20 12:55:34 +02:00
bottom 0
2018-02-14 16:32:13 +01:00
left 0
width 100%
2018-06-20 12:55:34 +02:00
padding 0 0 8px 154px
2018-04-15 11:38:40 +02:00
color #5e6367
2018-02-14 16:32:13 +01:00
> .name
display block
margin 0
2018-06-20 12:55:34 +02:00
line-height 32px
2018-02-14 16:32:13 +01:00
font-weight bold
2018-06-20 12:55:34 +02:00
font-size 1.8em
2018-02-14 16:32:13 +01:00
2018-06-23 15:55:32 +02:00
> div
> *
display inline-block
2018-06-23 16:18:39 +02:00
margin-right 16px
2018-06-23 15:55:32 +02:00
line-height 20px
opacity 0.8
2018-02-14 16:32:13 +01:00
2018-06-23 16:18:39 +02:00
&.username
font-weight bold
2018-06-20 12:55:34 +02:00
> .avatar
display block
position absolute
top 170px
left 16px
z-index 2
width 120px
height 120px
box-shadow 1px 1px 3px rgba(#000, 0.2)
2018-08-12 20:40:50 +02:00
> &.cat::before,
> &.cat::after
border-width 8px
2018-06-20 12:55:34 +02:00
> .body
padding 16px 16px 16px 154px
2018-09-28 07:26:20 +02:00
color var(--text)
2018-06-20 12:55:34 +02:00
> .actions
2019-02-14 21:51:22 +01:00
text-align right
padding-bottom 16px
border-bottom solid 1px var(--faceDivider)
> *
margin-left 8px
> .follow
2019-02-14 21:51:22 +01:00
width 180px
2018-12-11 12:18:12 +01:00
> .fields
margin-top 16px
> .field
display flex
padding 0
margin 0
2018-12-11 18:46:40 +01:00
align-items center
2018-12-11 12:18:12 +01:00
> .name
border-right solid 1px var(--faceDivider)
padding 4px
margin 4px
width 30%
overflow hidden
white-space nowrap
text-overflow ellipsis
font-weight bold
text-align center
> .value
padding 4px
margin 4px
width 70%
overflow hidden
white-space nowrap
text-overflow ellipsis
2018-10-13 06:25:07 +02:00
> .info
margin-top 16px
padding-top 16px
border-top solid 1px var(--faceDivider)
> *
margin-right 16px
2018-06-23 15:55:32 +02:00
> .status
margin-top 16px
padding-top 16px
2018-09-28 07:26:20 +02:00
border-top solid 1px var(--faceDivider)
2018-06-23 15:55:32 +02:00
font-size 80%
> *
display inline-block
padding-right 16px
margin-right 16px
2018-11-09 05:53:44 +01:00
color inherit
2018-06-23 15:55:32 +02:00
&:not(:last-child)
2018-09-28 07:26:20 +02:00
border-right solid 1px var(--faceDivider)
2018-06-23 15:55:32 +02:00
&.clickable
cursor pointer
&:hover
2018-09-28 07:26:20 +02:00
color var(--faceTextButtonHover)
2018-06-23 15:55:32 +02:00
> b
margin-right 4px
font-size 1rem
font-weight bold
2018-09-26 13:19:35 +02:00
color var(--primary)
2018-06-23 15:55:32 +02:00
2018-02-14 16:32:13 +01:00
</style>