summaryrefslogtreecommitdiffstats
path: root/core/src/views/Profile.vue
blob: 9173e5bb820c2ab3d8b0efca283890684e165128 (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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
<!--
  - @copyright Copyright (c) 2021 Christopher Ng <chrng8@gmail.com>
  -
  - @author Christopher Ng <chrng8@gmail.com>
  - @author Julius Härtl <jus@bitgrid.net>
  -
  - @license GNU AGPL version 3 or any later version
  -
  - This program is free software: you can redistribute it and/or modify
  - it under the terms of the GNU Affero General Public License as
  - published by the Free Software Foundation, either version 3 of the
  - License, or (at your option) any later version.
  -
  - This program is distributed in the hope that it will be useful,
  - but WITHOUT ANY WARRANTY; without even the implied warranty of
  - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  - GNU Affero General Public License for more details.
  -
  - You should have received a copy of the GNU Affero General Public License
  - along with this program. If not, see <http://www.gnu.org/licenses/>.
  -
  -->

<template>
	<div class="profile">
		<div class="profile__header">
			<div class="profile__header__container">
				<div class="profile__header__container__placeholder" />
				<h2 class="profile__header__container__displayname">
					{{ displayname || userId }}
					<a v-if="isCurrentUser"
						class="primary profile__header__container__edit-button"
						:href="settingsUrl">
						<PencilIcon class="pencil-icon"
							decorative
							title=""
							:size="16" />
						{{ t('core', 'Edit Profile') }}
					</a>
				</h2>
				<div v-if="status.icon || status.message"
					class="profile__header__container__status-text"
					:class="{ interactive: isCurrentUser }"
					@click.prevent.stop="openStatusModal">
					{{ status.icon }} {{ status.message }}
				</div>
			</div>
		</div>

		<div class="profile__content">
			<div class="profile__sidebar">
				<Avatar class="avatar"
					:class="{ interactive: isCurrentUser }"
					:user="userId"
					:size="180"
					:show-user-status="true"
					:show-user-status-compact="false"
					:disable-menu="true"
					:disable-tooltip="true"
					:is-no-user="!isUserAvatarVisible"
					@click.native.prevent.stop="openStatusModal" />

				<div class="user-actions">
					<!-- When a tel: URL is opened with target="_blank", a blank new tab is opened which is inconsistent with the handling of other URLs so we set target="_self" for the phone action -->
					<PrimaryActionButton v-if="primaryAction"
						class="user-actions__primary"
						:href="primaryAction.target"
						:icon="primaryAction.icon"
						:target="primaryAction.id === 'phone' ? '_self' :'_blank'">
						{{ primaryAction.title }}
					</PrimaryActionButton>
					<div class="user-actions__other">
						<!-- FIXME Remove inline styles after https://github.com/nextcloud/nextcloud-vue/issues/2315 is fixed -->
						<Actions v-for="action in middleActions"
							:key="action.id"
							:default-icon="action.icon"
							style="
								background-position: 14px center;
								background-size: 16px;
								background-repeat: no-repeat;"
							:style="{
								backgroundImage: `url(${action.icon})`,
								...(colorMainBackground === '#181818' && { filter: 'invert(1)' })
							}">
							<ActionLink :close-after-click="true"
								:icon="action.icon"
								:href="action.target"
								:target="action.id === 'phone' ? '_self' :'_blank'">
								{{ action.title }}
							</ActionLink>
						</Actions>
						<template v-if="otherActions">
							<Actions :force-menu="true">
								<ActionLink v-for="action in otherActions"
									:key="action.id"
									:class="{ 'icon-invert': colorMainBackground === '#181818' }"
									:close-after-click="true"
									:icon="action.icon"
									:href="action.target"
									:target="action.id === 'phone' ? '_self' :'_blank'">
									{{ action.title }}
								</ActionLink>
							</Actions>
						</template>
					</div>
				</div>
			</div>

			<div class="profile__blocks">
				<div v-if="organisation || role || address" class="profile__blocks-details">
					<div v-if="organisation || role" class="detail">
						<p>{{ organisation }} <span v-if="organisation && role">•</span> {{ role }}</p>
					</div>
					<div v-if="address" class="detail">
						<p>
							<MapMarkerIcon class="map-icon"
								decorative
								title=""
								:size="16" />
							{{ address }}
						</p>
					</div>
				</div>
				<template v-if="headline || biography">
					<div v-if="headline" class="profile__blocks-headline">
						<h3>{{ headline }}</h3>
					</div>
					<div v-if="biography" class="profile__blocks-biography">
						<p>{{ biography }}</p>
					</div>
				</template>
				<template v-else>
					<div class="profile__blocks-empty-info">
						<AccountIcon decorative
							title=""
							fill-color="var(--color-text-maxcontrast)"
							:size="60" />
						<h3>{{ emptyProfileMessage }}</h3>
						<p>{{ t('core', 'The headline and about sections will show up here') }}</p>
					</div>
				</template>
			</div>
		</div>
	</div>
</template>

<script>
import { getCurrentUser } from '@nextcloud/auth'
import { subscribe, unsubscribe } from '@nextcloud/event-bus'
import { loadState } from '@nextcloud/initial-state'
import { generateUrl } from '@nextcloud/router'
import { showError } from '@nextcloud/dialogs'

import Avatar from '@nextcloud/vue/dist/Components/Avatar'
import Actions from '@nextcloud/vue/dist/Components/Actions'
import ActionLink from '@nextcloud/vue/dist/Components/ActionLink'
import MapMarkerIcon from 'vue-material-design-icons/MapMarker'
import PencilIcon from 'vue-material-design-icons/Pencil'
import AccountIcon from 'vue-material-design-icons/Account'

import PrimaryActionButton from '../components/Profile/PrimaryActionButton'

const status = loadState('core', 'status', {})
const {
	userId,
	displayname,
	address,
	organisation,
	role,
	headline,
	biography,
	actions,
	isUserAvatarVisible,
} = loadState('core', 'profileParameters', {
	userId: null,
	displayname: null,
	address: null,
	organisation: null,
	role: null,
	headline: null,
	biography: null,
	actions: [],
	isUserAvatarVisible: false,
})

export default {
	name: 'Profile',

	components: {
		AccountIcon,
		ActionLink,
		Actions,
		Avatar,
		MapMarkerIcon,
		PencilIcon,
		PrimaryActionButton,
	},

	data() {
		return {
			status,
			userId,
			displayname,
			address,
			organisation,
			role,
			headline,
			biography,
			actions,
			isUserAvatarVisible,
		}
	},

	computed: {
		isCurrentUser() {
			return getCurrentUser()?.uid === this.userId
		},

		allActions() {
			return this.actions
		},

		primaryAction() {
			if (this.allActions.length) {
				return this.allActions[0]
			}
			return null
		},

		middleActions() {
			if (this.allActions.slice(1, 4).length) {
				return this.allActions.slice(1, 4)
			}
			return null
		},

		otherActions() {
			if (this.allActions.slice(4).length) {
				return this.allActions.slice(4)
			}
			return null
		},

		settingsUrl() {
			return generateUrl('/settings/user')
		},

		colorMainBackground() {
			// For some reason the returned string has prepended whitespace
			return getComputedStyle(document.body).getPropertyValue('--color-main-background').trim()
		},

		emptyProfileMessage() {
			return this.isCurrentUser
				? t('core', 'You have not added any info yet')
				: t('core', '{user} has not added any info yet', { user: (this.displayname || this.userId) })
		},
	},

	mounted() {
		// Set the user's displayname or userId in the page title and preserve the default title of "Nextcloud" at the end
		document.title = `${this.displayname || this.userId} - ${document.title}`
		subscribe('user_status:status.updated', this.handleStatusUpdate)
	},

	beforeDestroy() {
		unsubscribe('user_status:status.updated', this.handleStatusUpdate)
	},

	methods: {
		handleStatusUpdate(status) {
			if (this.isCurrentUser && status.userId === this.userId) {
				this.status = status
			}
		},

		openStatusModal() {
			const statusMenuItem = document.querySelector('.user-status-menu-item__toggle')
			// Changing the user status is only enabled if you are the current user
			if (this.isCurrentUser) {
				if (statusMenuItem) {
					statusMenuItem.click()
				} else {
					showError(t('core', 'Error opening the user status modal, try hard refreshing the page'))
				}
			}
		},
	},
}
</script>

<style lang="scss">
// Override header styles
#header {
	background-color: transparent !important;
	background-image: none !important;
}

#content {
	padding-top: 0px;
}
</style>

<style lang="scss" scoped>
$profile-max-width: 1024px;
$content-max-width: 640px;

.profile {
	width: 100%;

	&__header {
		position: sticky;
		height: 190px;
		top: -40px;
		background-color: var(--color-primary);
		background-image: var(--gradient-primary-background);

		&__container {
			align-self: flex-end;
			width: 100%;
			max-width: $profile-max-width;
			margin: 0 auto;
			display: grid;
			grid-template-rows: max-content max-content;
			grid-template-columns: 240px 1fr;
			justify-content: center;

			&__placeholder {
				grid-row: 1 / 3;
			}

			&__displayname, &__status-text {
				color: var(--color-primary-text);
			}

			&__displayname {
				width: $content-max-width;
				height: 45px;
				margin-top: 128px;
				// Override the global style declaration
				margin-bottom: 0;
				font-size: 30px;
				display: flex;
				align-items: center;
				cursor: text;

				&:not(:last-child) {
					margin-top: 100px;
					margin-bottom: 4px;
				}
			}

			&__edit-button {
				border: none;
				margin-left: 18px;
				margin-top: 2px;
				color: var(--color-primary-element);
				background-color: var(--color-primary-text);
				box-shadow: 0 0 0 2px var(--color-primary-text);
				border-radius: var(--border-radius-pill);
				padding: 0 18px;
				font-size: var(--default-font-size);
				height: 44px;
				line-height: 44px;
				font-weight: bold;

				&:hover,
				&:focus,
				&:active {
					color: var(--color-primary-text);
					background-color: var(--color-primary-element-light);
				}

				.pencil-icon {
					display: inline-block;
					vertical-align: middle;
					margin-top: 2px;
				}
			}

			&__status-text {
				width: max-content;
				max-width: $content-max-width;
				padding: 5px 10px;
				margin-left: -12px;
				margin-top: 2px;

				&.interactive {
					cursor: pointer;

					&:hover,
					&:focus,
					&:active {
						background-color: var(--color-main-background);
						color: var(--color-main-text);
						border-radius: var(--border-radius-pill);
						font-weight: bold;
						box-shadow: 0 3px 6px var(--color-box-shadow);
					}
				}
			}
		}
	}

	&__sidebar {
		position: sticky;
		top: var(--header-height);
		align-self: flex-start;
		padding-top: 20px;
		min-width: 220px;
		margin: -150px 20px 0 0;

		// Specificity hack is needed to override Avatar component styles
		&::v-deep .avatar.avatardiv, h2 {
			text-align: center;
			margin: auto;
			display: block;
			padding: 8px;
		}

		&::v-deep .avatar.avatardiv:not(.avatardiv--unknown) {
			background-color: var(--color-main-background) !important;
			box-shadow: none;
		}

		&::v-deep .avatar.avatardiv {
			.avatardiv__user-status {
				right: 14px;
				bottom: 14px;
				width: 34px;
				height: 34px;
				background-size: 28px;
				border: none;
				// Styles when custom status icon and status text are set
				background-color: var(--color-main-background);
				line-height: 34px;
				font-size: 20px;
			}
		}

		&::v-deep .avatar.interactive.avatardiv {
			.avatardiv__user-status {
				cursor: pointer;

				&:hover,
				&:focus,
				&:active {
					box-shadow: 0 3px 6px var(--color-box-shadow);
				}
			}
		}
	}

	&__content {
		max-width: $profile-max-width;
		margin: 0 auto;
		display: flex;
		width: 100%;
	}

	&__blocks {
		margin: 18px 0 80px 0;
		display: grid;
		gap: 16px 0;
		width: $content-max-width;

		p, h3 {
			overflow-wrap: anywhere;
		}

		&-details {
			display: flex;
			flex-direction: column;
			gap: 2px 0;

			.detail {
				display: inline-block;
				color: var(--color-text-maxcontrast);

				p .map-icon {
					display: inline-block;
					vertical-align: middle;
				}
			}
		}

		&-headline {
			margin-top: 10px;

			h3 {
				font-weight: bold;
				font-size: 20px;
				margin: 0;
			}
		}

		&-biography {
			white-space: pre-line;
		}

		h3, p {
			cursor: text;
		}

		&-empty-info {
			margin-top: 80px;
			margin-right: 100px;
			display: flex;
			flex-direction: column;
			text-align: center;

			h3 {
				font-weight: bold;
				font-size: 18px;
				margin: 8px 0;
			}
		}
	}
}

@media only screen and (max-width: 1024px) {
	.profile {
		&__header {
			height: 250px;
			position: unset;

			&__container {
				grid-template-columns: unset;

				&__displayname {
					margin: 100px 20px 0px;
					width: unset;
					display: unset;
					text-align: center;
				}

				&__edit-button {
					width: fit-content;
					display: block;
					margin: 30px auto;
				}
			}
		}

		&__content {
			display: block;
		}

		&__blocks {
			width: unset;
			max-width: 600px;
			margin: 0 auto;
			padding: 20px 50px 50px 50px;

			&-empty-info {
				margin: 0;
			}
		}

		&__sidebar {
			margin: unset;
			position: unset;
		}
	}
}

.user-actions {
	display: flex;
	flex-direction: column;
	gap: 8px 0;
	margin-top: 20px;

	&__primary {
		margin: 0 auto;
	}

	&__other {
		display: flex;
		justify-content: center;
		gap: 0 4px;
		a {
			filter: var(--background-invert-if-dark);
		}
	}
}

.icon-invert {
	&::v-deep .action-link__icon {
		filter: invert(1);
	}
}
</style>