summaryrefslogtreecommitdiff
path: root/src/client/app/desktop/views/pages/user/user.profile.vue
blob: 4d45b2433c3177742da64fe27ad8121bdb7c80ad (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
<template>
<div class="profile" v-if="$store.getters.isSignedIn">
	<div class="friend-form" v-if="$store.state.i.id != user.id">
		<mk-follow-button :user="user" block/>
		<p class="followed" v-if="user.isFollowed">{{ $t('follows-you') }}</p>
		<p class="stalk" v-if="user.isFollowing">
			<span v-if="user.isStalking">{{ $t('stalking') }} <a @click="unstalk"><fa icon="meh"/> {{ $t('unstalk') }}</a></span>
			<span v-if="!user.isStalking"><a @click="stalk"><fa icon="user-secret"/> {{ $t('stalk') }}</a></span>
		</p>
	</div>
	<div class="action-form">
		<ui-button @click="user.isMuted ? unmute() : mute()" v-if="$store.state.i.id != user.id">
			<span v-if="user.isMuted"><fa icon="eye"/> {{ $t('unmute') }}</span>
			<span v-else><fa :icon="['far', 'eye-slash']"/> {{ $t('mute') }}</span>
		</ui-button>
		<ui-button @click="user.isBlocking ? unblock() : block()" v-if="$store.state.i.id != user.id">
			<span v-if="user.isBlocking"><fa icon="ban"/> {{ $t('unblock') }}</span>
			<span v-else><fa icon="ban"/> {{ $t('block') }}</span>
		</ui-button>
		<ui-button @click="list"><fa icon="list"/> {{ $t('push-to-a-list') }}</ui-button>
	</div>
</div>
</template>

<script lang="ts">
import Vue from 'vue';
import i18n from '../../../../i18n';
import MkUserListsWindow from '../../components/user-lists-window.vue';

export default Vue.extend({
	i18n: i18n('desktop/views/pages/user/user.profile.vue'),
	props: ['user'],

	methods: {
		stalk() {
			this.$root.api('following/stalk', {
				userId: this.user.id
			}).then(() => {
				this.user.isStalking = true;
			}, () => {
				alert('error');
			});
		},

		unstalk() {
			this.$root.api('following/unstalk', {
				userId: this.user.id
			}).then(() => {
				this.user.isStalking = false;
			}, () => {
				alert('error');
			});
		},

		mute() {
			this.$root.api('mute/create', {
				userId: this.user.id
			}).then(() => {
				this.user.isMuted = true;
			}, () => {
				alert('error');
			});
		},

		unmute() {
			this.$root.api('mute/delete', {
				userId: this.user.id
			}).then(() => {
				this.user.isMuted = false;
			}, () => {
				alert('error');
			});
		},

		block() {
			this.$root.alert({
				type: 'warning',
				text: this.$t('block-confirm'),
				showCancelButton: true
			}).then(res => {
				if (!res) return;

				this.$root.api('blocking/create', {
					userId: this.user.id
				}).then(() => {
					this.user.isBlocking = true;
				}, () => {
					alert('error');
				});
			});
		},

		unblock() {
			this.$root.api('blocking/delete', {
				userId: this.user.id
			}).then(() => {
				this.user.isBlocking = false;
			}, () => {
				alert('error');
			});
		},

		list() {
			const w = this.$root.new(MkUserListsWindow);
			w.$once('choosen', async list => {
				w.close();
				await this.$root.api('users/lists/push', {
					listId: list.id,
					userId: this.user.id
				});
				this.$root.alert({
					type: 'success',
					title: 'Done!',
					text: this.$t('list-pushed', {
						user: this.user.name,
						list: list.title
					})
				});
			});
		}
	}
});
</script>

<style lang="stylus" scoped>
.profile
	background var(--face)
	box-shadow var(--shadow)
	border-radius var(--round)

	> *:first-child
		border-top none !important

	> .friend-form
		padding 16px
		text-align center
		border-bottom solid 1px var(--faceDivider)

		> .followed
			margin 12px 0 0 0
			padding 0
			text-align center
			line-height 24px
			font-size 0.8em
			color #71afc7
			background #eefaff
			border-radius 4px

		> .stalk
			margin 12px 0 0 0

	> .action-form
		padding 16px
		text-align center

		> *
			width 100%

			&:not(:last-child)
				margin-bottom 12px

</style>