summaryrefslogtreecommitdiff
path: root/src/web/app/desktop/views/pages/user/user.header.vue
blob: 54f431fd2e6bcec75245914ec863ea5320d24b38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<template>
<div class="header" :data-is-dark-background="user.bannerUrl != null">
	<div class="banner-container" :style="user.bannerUrl ? `background-image: url(${user.bannerUrl}?thumbnail&size=2048)` : ''">
		<div class="banner" ref="banner" :style="user.bannerUrl ? `background-image: url(${user.bannerUrl}?thumbnail&size=2048)` : ''" @click="onBannerClick"></div>
	</div>
	<div class="fade"></div>
	<div class="container">
		<img class="avatar" :src="`${user.avatarUrl}?thumbnail&size=150`" alt="avatar"/>
		<div class="title">
			<p class="name">{{ user.name }}</p>
			<p class="username">@{{ acct }}</p>
			<p class="location" v-if="user.host === null && user.account.profile.location">%fa:map-marker%{{ user.account.profile.location }}</p>
		</div>
		<footer>
			<router-link :to="`/@${acct}`" :data-active="$parent.page == 'home'">%fa:home%概要</router-link>
			<router-link :to="`/@${acct}/media`" :data-active="$parent.page == 'media'">%fa:image%メディア</router-link>
			<router-link :to="`/@${acct}/graphs`" :data-active="$parent.page == 'graphs'">%fa:chart-bar%グラフ</router-link>
		</footer>
	</div>
</div>
</template>

<script lang="ts">
import Vue from 'vue';
import getAcct from '../../../../../../common/user/get-acct';

export default Vue.extend({
	props: ['user'],
	computed: {
		acct() {
			return getAcct(this.user);
		}
	},
	mounted() {
		window.addEventListener('load', this.onScroll);
		window.addEventListener('scroll', this.onScroll);
		window.addEventListener('resize', this.onScroll);
	},
	beforeDestroy() {
		window.removeEventListener('load', this.onScroll);
		window.removeEventListener('scroll', this.onScroll);
		window.removeEventListener('resize', this.onScroll);
	},
	methods: {
		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() {
			if (!(this as any).os.isSignedIn || (this as any).os.i.id != this.user.id) return;

			(this as any).apis.updateBanner((this as any).os.i, i => {
				this.user.bannerUrl = i.bannerUrl;
			});
		}
	}
});
</script>

<style lang="stylus" scoped>
@import '~const.styl'

.header
	$banner-height = 320px
	$footer-height = 58px

	overflow hidden
	background #f7f7f7
	box-shadow 0 1px 1px rgba(0, 0, 0, 0.075)

	&[data-is-dark-background]
		> .banner-container
			> .banner
				background-color #383838

		> .fade
			background linear-gradient(transparent, rgba(0, 0, 0, 0.7))

		> .container
			> .title
				color #fff

				> .name
					text-shadow 0 0 8px #000

	> .banner-container
		height $banner-height
		overflow hidden
		background-size cover
		background-position center

		> .banner
			height 100%
			background-color #f5f5f5
			background-size cover
			background-position center

	> .fade
		$fade-hight = 78px

		position absolute
		top ($banner-height - $fade-hight)
		left 0
		width 100%
		height $fade-hight

	> .container
		max-width 1200px
		margin 0 auto

		> .avatar
			display block
			position absolute
			bottom 16px
			left 16px
			z-index 2
			width 160px
			height 160px
			margin 0
			border solid 3px #fff
			border-radius 8px
			box-shadow 1px 1px 3px rgba(0, 0, 0, 0.2)

		> .title
			position absolute
			bottom $footer-height
			left 0
			width 100%
			padding 0 0 8px 195px
			color #656565
			font-family '游ゴシック', 'YuGothic', 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', 'Meiryo', 'メイリオ', sans-serif

			> .name
				display block
				margin 0
				line-height 40px
				font-weight bold
				font-size 2em

			> .username
			> .location
				display inline-block
				margin 0 16px 0 0
				line-height 20px
				opacity 0.8

				> i
					margin-right 4px

		> footer
			z-index 1
			height $footer-height
			padding-left 195px

			> a
				display inline-block
				margin 0
				padding 0 16px
				height $footer-height
				line-height $footer-height
				color #555

				&[data-active]
					border-bottom solid 4px $theme-color

				> i
					margin-right 6px

			> button
				display block
				position absolute
				top 0
				right 0
				margin 8px
				padding 0
				width $footer-height - 16px
				line-height $footer-height - 16px - 2px
				font-size 1.2em
				color #777
				border solid 1px #eee
				border-radius 4px

				&:hover
					color #555
					border solid 1px #ddd

</style>