summaryrefslogtreecommitdiff
path: root/src/client/app/desktop/views/components/ui.sidebar.vue
blob: d1ceec51984f71ae4ebe8c293562851ed155b834 (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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
<template>
<div class="header" :class="navbar" :data-shadow="$store.state.device.useShadow">
	<div class="body">
		<div class="post">
			<button @click="post" :title="$t('title')"><fa icon="pencil-alt"/></button>
		</div>

		<div class="nav" v-if="$store.getters.isSignedIn">
			<div class="home" :class="{ active: $route.name == 'index' }" @click="goToTop">
				<router-link to="/"><fa icon="home"/></router-link>
			</div>
			<div class="featured" :class="{ active: $route.name == 'featured' }">
				<router-link to="/featured"><fa :icon="faNewspaper"/></router-link>
			</div>
			<div class="explore" :class="{ active: $route.name == 'explore' || $route.name == 'explore-tag' }">
				<router-link to="/explore"><fa :icon="faHashtag"/></router-link>
			</div>
			<div class="game">
				<a @click="game"><fa icon="gamepad"/><template v-if="hasGameInvitations"><fa icon="circle"/></template></a>
			</div>
		</div>

		<div class="nav bottom" v-if="$store.getters.isSignedIn">
			<div>
				<a @click="drive"><fa icon="cloud"/></a>
			</div>
			<div ref="notificationsButton" :class="{ active: showNotifications }">
				<a @click="notifications"><fa :icon="['far', 'bell']"/></a>
			</div>
			<div class="messaging">
				<a @click="messaging"><fa icon="comments"/><template v-if="hasUnreadMessagingMessage"><fa icon="circle"/></template></a>
			</div>
			<div>
				<a @click="settings"><fa icon="cog"/></a>
			</div>
			<div class="signout">
				<a @click="signout"><fa icon="power-off"/></a>
			</div>
			<div>
				<router-link to="/i/favorites"><fa icon="star"/></router-link>
			</div>
			<div v-if="($store.state.i.isLocked || $store.state.i.carefulBot)">
				<a @click="followRequests"><fa :icon="['far', 'envelope']"/><i v-if="$store.state.i.pendingReceivedFollowRequestsCount">{{ $store.state.i.pendingReceivedFollowRequestsCount }}</i></a>
			</div>
			<div class="account">
				<router-link :to="`/@${ $store.state.i.username }`">
					<mk-avatar class="avatar" :user="$store.state.i"/>
				</router-link>
			</div>
			<div>
				<template v-if="$store.state.device.inDeckMode">
					<a @click="toggleDeckMode(false)"><fa icon="home"/></a>
				</template>
				<template v-else>
					<a @click="toggleDeckMode(true)"><fa icon="columns"/></a>
				</template>
			</div>
			<div>
				<a @click="dark"><template v-if="$store.state.device.darkmode"><fa icon="moon"/></template><template v-else><fa :icon="['far', 'moon']"/></template></a>
			</div>
		</div>
	</div>

	<transition :name="`slide-${navbar}`">
		<div class="notifications" v-if="showNotifications" ref="notifications" :class="navbar" :data-shadow="$store.state.device.useShadow">
			<mk-notifications/>
		</div>
	</transition>
</div>
</template>

<script lang="ts">
import Vue from 'vue';
import i18n from '../../../i18n';
import MkSettingsWindow from './settings-window.vue';
import MkDriveWindow from './drive-window.vue';
import MkMessagingWindow from './messaging-window.vue';
import MkGameWindow from './game-window.vue';
import contains from '../../../common/scripts/contains';
import { faNewspaper, faHashtag } from '@fortawesome/free-solid-svg-icons';

export default Vue.extend({
	i18n: i18n('desktop/views/components/ui.sidebar.vue'),
	data() {
		return {
			hasGameInvitations: false,
			connection: null,
			showNotifications: false,
			faNewspaper, faHashtag
		};
	},

	computed: {
		hasUnreadMessagingMessage(): boolean {
			return this.$store.getters.isSignedIn && this.$store.state.i.hasUnreadMessagingMessage;
		},

		navbar(): string {
			return this.$store.state.device.navbar;
		},
	},

	mounted() {
		if (this.$store.getters.isSignedIn) {
			this.connection = this.$root.stream.useSharedConnection('main');

			this.connection.on('reversiInvited', this.onReversiInvited);
			this.connection.on('reversiNoInvites', this.onReversiNoInvites);
		}
	},

	beforeDestroy() {
		if (this.$store.getters.isSignedIn) {
			this.connection.dispose();
		}
	},

	methods: {
		toggleDeckMode(deck) {
			this.$store.commit('device/set', { key: 'deckMode', value: deck });
			location.replace('/');
		},

		onReversiInvited() {
			this.hasGameInvitations = true;
		},

		onReversiNoInvites() {
			this.hasGameInvitations = false;
		},

		messaging() {
			this.$root.new(MkMessagingWindow);
		},

		game() {
			this.$root.new(MkGameWindow);
		},

		post() {
			this.$post();
		},

		drive() {
			this.$root.new(MkDriveWindow);
		},

		list() {
			this.$root.new(MkUserListsWindow);
		},

		followRequests() {
			this.$root.new(MkFollowRequestsWindow);
		},

		settings() {
			this.$root.new(MkSettingsWindow);
		},

		signout() {
			this.$root.signout();
		},

		notifications() {
			this.showNotifications ? this.closeNotifications() : this.openNotifications();
		},

		openNotifications() {
			this.showNotifications = true;
			for (const el of Array.from(document.querySelectorAll('body *'))) {
				el.addEventListener('mousedown', this.onMousedown);
			}
		},

		closeNotifications() {
			this.showNotifications = false;
			for (const el of Array.from(document.querySelectorAll('body *'))) {
				el.removeEventListener('mousedown', this.onMousedown);
			}
		},

		onMousedown(e) {
			e.preventDefault();
			if (
				!contains(this.$refs.notifications, e.target) &&
				this.$refs.notifications != e.target &&
				!contains(this.$refs.notificationsButton, e.target) &&
				this.$refs.notificationsButton != e.target
			) {
				this.closeNotifications();
			}
			return false;
		},

		dark() {
			this.$store.commit('device/set', {
				key: 'darkmode',
				value: !this.$store.state.device.darkmode
			});
		},

		goToTop() {
			window.scrollTo({
				top: 0,
				behavior: 'smooth'
			});
		}
	}
});
</script>

<style lang="stylus" scoped>
.header
	$width = 68px

	position fixed
	top 0
	z-index 1000
	width $width
	height 100%

	&.left
		left 0

		&[data-shadow]
			box-shadow 4px 0 4px rgba(0, 0, 0, 0.1)

	&.right
		right 0

		&[data-shadow]
			box-shadow -4px 0 4px rgba(0, 0, 0, 0.1)

	> .body
		position fixed
		top 0
		z-index 1
		width $width
		height 100%
		background var(--desktopHeaderBg)

		> .post
			width $width
			height $width
			padding 12px

			> button
				display inline-block
				margin 0
				padding 0
				height 100%
				width 100%
				font-size 1.2em
				font-weight normal
				text-decoration none
				color var(--primaryForeground)
				background var(--primary) !important
				outline none
				border none
				border-radius 100%
				transition background 0.1s ease
				cursor pointer

				*
					pointer-events none

				&:hover
					background var(--primaryLighten10) !important

				&:active
					background var(--primaryDarken10) !important
					transition background 0s ease

		> .nav.bottom
			position absolute
			bottom 0
			left 0

			> .account
				width $width
				height $width
				padding 14px

				> *
					display block
					width 100%
					height 100%

					> .avatar
						pointer-events none
						width 100%
						height 100%

	> .notifications
		position fixed
		top 0
		width 350px
		height 100%
		overflow auto
		background var(--face)

		&.left
			left $width

			&[data-shadow]
				box-shadow 4px 0 4px rgba(0, 0, 0, 0.1)

		&.right
			right $width

			&[data-shadow]
				box-shadow -4px 0 4px rgba(0, 0, 0, 0.1)

	.nav
		> *
			> *
				display block
				width $width
				line-height 52px
				text-align center
				font-size 18px
				color var(--desktopHeaderFg)

				&:hover
					background rgba(0, 0, 0, 0.05)
					color var(--desktopHeaderHoverFg)
					text-decoration none

				&:active
					background rgba(0, 0, 0, 0.1)

	&.left
		.nav
			> *
				&.active
					box-shadow -4px 0 var(--primary) inset

	&.right
		.nav
			> *
				&.active
					box-shadow 4px 0 var(--primary) inset

.slide-left-enter-active,
.slide-left-leave-active {
	transition: all 0.2s ease;
}

.slide-left-enter, .slide-left-leave-to {
	transform: translateX(-16px);
	opacity: 0;
}

.slide-right-enter-active,
.slide-right-leave-active {
	transition: all 0.2s ease;
}

.slide-right-enter, .slide-right-leave-to {
	transform: translateX(16px);
	opacity: 0;
}
</style>