summaryrefslogtreecommitdiff
path: root/src/client/app/desktop/views/components/user-preview.vue
blob: 788881ead5f349c51593d533e9c69a4cf770374a (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
<template>
<div class="mk-user-preview">
	<template v-if="u != null">
		<div class="banner" :style="u.bannerUrl ? `background-image: url(${u.bannerUrl}?thumbnail&size=512)` : ''"></div>
		<mk-avatar class="avatar" :user="u" :disable-preview="true"/>
		<div class="title">
			<router-link class="name" :to="u | userPage">{{ u | userName }}</router-link>
			<p class="username"><mk-acct :user="u"/></p>
		</div>
		<div class="description">{{ u.description }}</div>
		<div class="status">
			<div>
				<p>%i18n:@notes%</p><a>{{ u.notesCount }}</a>
			</div>
			<div>
				<p>%i18n:@following%</p><a>{{ u.followingCount }}</a>
			</div>
			<div>
				<p>%i18n:@followers%</p><a>{{ u.followersCount }}</a>
			</div>
		</div>
		<mk-follow-button v-if="$store.getters.isSignedIn && user.id != $store.state.i.id" :user="u"/>
	</template>
</div>
</template>

<script lang="ts">
import Vue from 'vue';
import * as anime from 'animejs';
import parseAcct from '../../../../../acct/parse';

export default Vue.extend({
	props: {
		user: {
			type: [Object, String],
			required: true
		}
	},
	data() {
		return {
			u: null
		};
	},
	mounted() {
		if (typeof this.user == 'object') {
			this.u = this.user;
			this.$nextTick(() => {
				this.open();
			});
		} else {
			const query = this.user[0] == '@' ?
				parseAcct(this.user.substr(1)) :
				{ userId: this.user };

			(this as any).api('users/show', query).then(user => {
				this.u = user;
				this.open();
			});
		}
	},
	methods: {
		open() {
			anime({
				targets: this.$el,
				opacity: 1,
				'margin-top': 0,
				duration: 200,
				easing: 'easeOutQuad'
			});
		},
		close() {
			anime({
				targets: this.$el,
				opacity: 0,
				'margin-top': '-8px',
				duration: 200,
				easing: 'easeOutQuad',
				complete: () => this.$destroy()
			});
		}
	}
});
</script>

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

root(isDark)
	position absolute
	z-index 2048
	margin-top -8px
	width 250px
	background isDark ? #282c37 : #fff
	background-clip content-box
	border solid 1px rgba(#000, 0.1)
	border-radius 4px
	overflow hidden
	opacity 0

	> .banner
		height 84px
		background-color isDark ? #1c1e26 : #f5f5f5
		background-size cover
		background-position center

	> .avatar
		display block
		position absolute
		top 62px
		left 13px
		z-index 2
		width 58px
		height 58px
		border solid 3px isDark ? #282c37 : #fff
		border-radius 8px

	> .title
		display block
		padding 8px 0 8px 82px

		> .name
			display inline-block
			margin 0
			font-weight bold
			line-height 16px
			color isDark ? #fff : #656565

		> .username
			display block
			margin 0
			line-height 16px
			font-size 0.8em
			color isDark ? #606984 : #999

	> .description
		padding 0 16px
		font-size 0.7em
		color isDark ? #9ea4ad : #555

	> .status
		padding 8px 16px

		> div
			display inline-block
			width 33%

			> p
				margin 0
				font-size 0.7em
				color #aaa

			> a
				font-size 1em
				color $theme-color

	> .mk-follow-button
		position absolute
		top 92px
		right 8px

.mk-user-preview[data-darkmode]
	root(true)

.mk-user-preview:not([data-darkmode])
	root(false)

</style>