refactor subscribe button and comment-add for visitor-interact UX (#1100)

* refactor subscribe button for visitor-subscribe UX
* refactor comment-add for visitor-interact UX
pull/1119/head
Rigel Kent 2018-09-25 15:42:58 +02:00 committed by GitHub
parent ba6a98b8fa
commit 660d11e91e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 295 additions and 79 deletions

View File

@ -9,7 +9,7 @@
<div class="actor-display-name">{{ videoChannel.displayName }}</div>
<div class="actor-name">{{ videoChannel.nameWithHost }}</div>
<my-subscribe-button #subscribeButton *ngIf="isUserLoggedIn()" [videoChannel]="videoChannel"></my-subscribe-button>
<my-subscribe-button #subscribeButton [videoChannel]="videoChannel"></my-subscribe-button>
</div>
<div i18n class="actor-followers">{{ videoChannel.followersCount }} subscribers</div>

View File

@ -41,7 +41,7 @@
<div i18n class="video-channel-followers">{{ result.followersCount }} subscribers</div>
</div>
<my-subscribe-button *ngIf="isUserLoggedIn()" [videoChannel]="result"></my-subscribe-button>
<my-subscribe-button [videoChannel]="result"></my-subscribe-button>
</div>
<div *ngIf="isVideo(result)" class="entry video">

View File

@ -53,7 +53,7 @@ import { PeertubeCheckboxComponent } from '@app/shared/forms/peertube-checkbox.c
import { VideoImportService } from '@app/shared/video-import/video-import.service'
import { ActionDropdownComponent } from '@app/shared/buttons/action-dropdown.component'
import { NgbDropdownModule, NgbModalModule, NgbPopoverModule, NgbTabsetModule, NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap'
import { SubscribeButtonComponent, UserSubscriptionService } from '@app/shared/user-subscription'
import { SubscribeButtonComponent, RemoteSubscribeComponent, UserSubscriptionService } from '@app/shared/user-subscription'
import { InstanceFeaturesTableComponent } from '@app/shared/instance/instance-features-table.component'
import { OverviewService } from '@app/shared/overview'
@ -93,6 +93,7 @@ import { OverviewService } from '@app/shared/overview'
ReactiveFileComponent,
PeertubeCheckboxComponent,
SubscribeButtonComponent,
RemoteSubscribeComponent,
InstanceFeaturesTableComponent
],
@ -127,6 +128,7 @@ import { OverviewService } from '@app/shared/overview'
ReactiveFileComponent,
PeertubeCheckboxComponent,
SubscribeButtonComponent,
RemoteSubscribeComponent,
InstanceFeaturesTableComponent,
NumberFormatterPipe,

View File

@ -1,2 +1,3 @@
export * from './user-subscription.service'
export * from './subscribe-button.component'
export * from './remote-subscribe.component'

View File

@ -0,0 +1,25 @@
<form novalidate [formGroup]="form"
(ngSubmit)="formValidated()">
<div class="form-group">
<input type="email"
formControlName="text"
class="form-control"
(keyup.control.enter)="onValidKey()" (keyup.meta.enter)="onValidKey()"
placeholder="jane_doe@example.com">
</div>
<button type="submit"
[disabled]="!form.valid"
class="btn btn-sm btn-remote-follow"
i18n>
<span *ngIf="!interact">Remote subscribe</span>
<span *ngIf="interact">Remote interact</span>
</button>
<my-help *ngIf="!interact && showHelp"
helpType="custom"
i18n-customHtml customHtml="You can subscribe to the channel via any ActivityPub-capable fediverse instance. For instance with Mastodon or Pleroma you can type the channel URL in the search box and subscribe there.">
</my-help>
<my-help *ngIf="showHelp && interact"
helpType="custom"
i18n-customHtml customHtml="You can interact with this via any ActivityPub-capable fediverse instance. For instance with Mastodon or Pleroma you can type the current URL in the search box and interact with it there.">
</my-help>
</form>

View File

@ -0,0 +1,5 @@
@import '_mixins';
.btn-remote-follow {
@include orange-button;
}

View File

@ -0,0 +1,43 @@
import { Component, Input, OnInit } from '@angular/core'
import { FormReactive } from '@app/shared/forms/form-reactive'
import {
FormValidatorService,
UserValidatorsService
} from '@app/shared/forms/form-validators'
@Component({
selector: 'my-remote-subscribe',
templateUrl: './remote-subscribe.component.html',
styleUrls: ['./remote-subscribe.component.scss']
})
export class RemoteSubscribeComponent extends FormReactive implements OnInit {
@Input() account: string
@Input() interact = false
@Input() showHelp = false
constructor (
protected formValidatorService: FormValidatorService,
private userValidatorsService: UserValidatorsService
) {
super()
}
ngOnInit () {
this.buildForm({
text: this.userValidatorsService.USER_EMAIL
})
}
onValidKey () {
this.onValueChanged()
if (!this.form.valid) return
this.formValidated()
}
formValidated () {
const address = this.form.value['text']
const [ , hostname ] = address.split('@')
window.open(`https://${hostname}/authorize_interaction?acct=${this.account}`)
}
}

View File

@ -1,15 +1,45 @@
<span i18n *ngIf="subscribed === false" class="subscribe-button" [ngClass]="size" role="button" (click)="subscribe()">
<span>Subscribe</span>
<span *ngIf="displayFollowers && videoChannel.followersCount !== 0" class="followers-count">
{{ videoChannel.followersCount | myNumberFormatter }}
</span>
</span>
<div class="btn-group-subscribe btn-group"
[ngClass]="{'subscribe-button': subscribed !== true, 'unsubscribe-button': subscribed === true}">
<button *ngIf="subscribed === false && isUserLoggedIn()" type="button"
class="btn btn-sm" role="button"
(click)="subscribe()" i18n>
<span>
Subscribe
</span>
<span *ngIf="displayFollowers && videoChannel.followersCount !== 0" class="followers-count">
{{ videoChannel.followersCount | myNumberFormatter }}
</span>
</button>
<button *ngIf="subscribed === true" type="button"
class="btn btn-sm" role="button"
(click)="unsubscribe()" i18n>Unsubscribe</button>
<span *ngIf="subscribed === true" class="unsubscribe-button" [ngClass]="size" role="button" (click)="unsubscribe()">
<span class="subscribed" i18n>Subscribed</span>
<span class="unsubscribe" i18n>Unsubscribe</span>
<div class="btn-group" ngbDropdown autoClose="outside"
placement="bottom-right" role="group"
aria-label="Multiple ways to subscribe to the current channel">
<button class="btn btn-sm dropdown-toggle-split" ngbDropdownToggle>
<span *ngIf="!isUserLoggedIn()">
Subscribe
</span>
<span *ngIf="displayFollowers && videoChannel.followersCount !== 0" class="followers-count">
{{ videoChannel.followersCount | myNumberFormatter }}
</span>
</button>
<div class="dropdown-menu" ngbDropdownMenu>
<span *ngIf="displayFollowers && videoChannel.followersCount !== 0" class="followers-count">
{{ videoChannel.followersCount | myNumberFormatter }}
</span>
</span>
<h6 class="dropdown-header" i18n>Using an ActivityPub-compatible account</h6>
<button class="dropdown-item" (click)="subscribe()"
*ngIf="subscribed === false">
<span *ngIf="!isUserLoggedIn()" i18n>Subscribe with an account on {{ videoChannel.host }}</span>
<span *ngIf="isUserLoggedIn()" i18n>Subscribe with your local account</span>
</button>
<button class="dropdown-item" i18n>Subscribe with a remote account:</button>
<my-remote-subscribe showHelp="true" account="{{ uriAccount }}"></my-remote-subscribe>
<div class="dropdown-divider"></div>
<h6 class="dropdown-header" i18n>Using a syndication feed</h6>
<button (click)="rssOpen()" class="dropdown-item" i18n>Subscribe via RSS</button>
</div>
</div>
</div>

View File

@ -1,51 +1,46 @@
@import '_variables';
@import '_mixins';
.subscribe-button {
.btn-group-subscribe {
@include peertube-button;
@include orange-button;
}
@include disable-default-a-behaviour;
float: right;
padding: 0;
.unsubscribe-button {
@include peertube-button;
@include grey-button
}
.subscribe-button,
.unsubscribe-button {
display: inline-block;
&.small {
min-width: 75px;
height: 20px;
line-height: 20px;
font-size: 13px;
&.btn-group > .btn:not(.dropdown-toggle) {
padding-right: 5px;
font-size: 15px;
}
&.btn-group > .btn-group:not(:first-child) > .btn {
padding-left: 2px;
}
&.normal {
min-width: 120px;
height: 30px;
line-height: 30px;
font-size: 16px;
}
}
.unsubscribe-button {
.subscribed {
display: inline;
}
.unsubscribe {
display: none;
}
&:hover {
.subscribed {
display: none;
&.subscribe-button {
.btn {
@include orange-button;
font-weight: 600;
}
.unsubscribe {
display: inline;
span.followers-count {
padding-left:5px;
}
}
}
&.unsubscribe-button {
.btn {
@include grey-button;
font-weight: 600;
}
}
.dropdown-header {
padding-left: 1rem;
}
/deep/ form {
padding: 0.25rem 1rem;
}
input {
@include peertube-input-text(100%);
}
}

View File

@ -1,4 +1,6 @@
import { Component, Input, OnInit } from '@angular/core'
import { Router } from '@angular/router'
import { AuthService } from '@app/core'
import { UserSubscriptionService } from '@app/shared/user-subscription/user-subscription.service'
import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
import { NotificationsService } from 'angular2-notifications'
@ -17,6 +19,8 @@ export class SubscribeButtonComponent implements OnInit {
subscribed: boolean
constructor (
private authService: AuthService,
private router: Router,
private notificationsService: NotificationsService,
private userSubscriptionService: UserSubscriptionService,
private i18n: I18n
@ -26,16 +30,30 @@ export class SubscribeButtonComponent implements OnInit {
return this.videoChannel.name + '@' + this.videoChannel.host
}
ngOnInit () {
this.userSubscriptionService.isSubscriptionExists(this.uri)
.subscribe(
res => this.subscribed = res[this.uri],
get uriAccount () {
return this.videoChannel.ownerAccount.name + '@' + this.videoChannel.host
}
err => this.notificationsService.error(this.i18n('Error'), err.message)
)
ngOnInit () {
if (this.isUserLoggedIn()) {
this.userSubscriptionService.isSubscriptionExists(this.uri)
.subscribe(
res => this.subscribed = res[this.uri],
err => this.notificationsService.error(this.i18n('Error'), err.message)
)
}
}
subscribe () {
if (this.isUserLoggedIn()) {
this.localSubscribe()
} else {
this.gotoLogin()
}
}
localSubscribe () {
this.userSubscriptionService.addSubscription(this.uri)
.subscribe(
() => {
@ -52,6 +70,12 @@ export class SubscribeButtonComponent implements OnInit {
}
unsubscribe () {
if (this.isUserLoggedIn()) {
this.localUnsubscribe()
}
}
localUnsubscribe () {
this.userSubscriptionService.deleteSubscription(this.uri)
.subscribe(
() => {
@ -66,4 +90,16 @@ export class SubscribeButtonComponent implements OnInit {
err => this.notificationsService.error(this.i18n('Error'), err.message)
)
}
isUserLoggedIn () {
return this.authService.isLoggedIn()
}
gotoLogin () {
this.router.navigate([ '/login' ])
}
rssOpen () {
window.open('')
}
}

View File

@ -1,9 +1,11 @@
<form novalidate [formGroup]="form" (ngSubmit)="formValidated()">
<div class="avatar-and-textarea">
<img [src]="user.accountAvatarUrl" alt="Avatar" />
<img [src]="getAvatarUrl()" alt="Avatar" />
<div class="form-group">
<textarea i18n-placeholder placeholder="Add comment..." autosize
[readonly]="(user === null) ? true : false"
(click)="openVisitorModal($event)"
formControlName="text" [ngClass]="{ 'input-error': formErrors['text'] }"
(keyup.control.enter)="onValidKey()" (keyup.meta.enter)="onValidKey()" #textarea>
@ -20,3 +22,25 @@
</button>
</div>
</form>
<ng-template #visitorModal let-modal>
<div class="modal-header">
<h4 class="modal-title" id="modal-basic-title" i18n>You are one step away from commenting</h4>
<button type="button" class="close" aria-label="Close" (click)="hideVisitorModal()"></button>
</div>
<div class="modal-body" i18n>
<span i18n>
If you have an account on this instance, you can login:
</span>
<span class="btn btn-sm mx-3" role="button" (click)="gotoLogin()" i18n>login to comment</span>
<span i18n>
Otherwise you can comment using an account on an ActivityPub-compatible instance:
</span>
<my-remote-subscribe [interact]="true" account="{{ uri }}"></my-remote-subscribe>
</div>
<div class="modal-footer inputs">
<span i18n class="action-button action-button-cancel" role="button" (click)="hideVisitorModal()">
Cancel
</span>
</div>
</ng-template>

View File

@ -36,7 +36,7 @@ form {
button {
@include peertube-button;
@include orange-button
@include orange-button;
}
}
@ -44,4 +44,16 @@ form {
textarea, .submit-comment button {
font-size: 14px !important;
}
}
.modal-body {
.btn {
@include peertube-button;
@include orange-button;
}
span {
float: left;
margin-bottom: 20px;
}
}

View File

@ -1,4 +1,5 @@
import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'
import { Router } from '@angular/router'
import { NotificationsService } from 'angular2-notifications'
import { Observable } from 'rxjs'
import { VideoCommentCreate } from '../../../../../../shared/models/videos/video-comment.model'
@ -10,6 +11,8 @@ import { VideoCommentService } from './video-comment.service'
import { I18n } from '@ngx-translate/i18n-polyfill'
import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
import { VideoCommentValidatorsService } from '@app/shared/forms/form-validators/video-comment-validators.service'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { AuthService } from '@app/core/auth'
@Component({
selector: 'my-video-comment-add',
@ -25,15 +28,20 @@ export class VideoCommentAddComponent extends FormReactive implements OnInit {
@Output() commentCreated = new EventEmitter<VideoCommentCreate>()
@ViewChild('visitorModal') visitorModal: NgbModal
@ViewChild('textarea') private textareaElement: ElementRef
private addingComment = false
private uri: string
constructor (
protected formValidatorService: FormValidatorService,
private videoCommentValidatorsService: VideoCommentValidatorsService,
private notificationsService: NotificationsService,
private videoCommentService: VideoCommentService,
private authService: AuthService,
private modalService: NgbModal,
private router: Router,
private i18n: I18n
) {
super()
@ -44,19 +52,23 @@ export class VideoCommentAddComponent extends FormReactive implements OnInit {
text: this.videoCommentValidatorsService.VIDEO_COMMENT_TEXT
})
if (this.focusOnInit === true) {
this.textareaElement.nativeElement.focus()
}
this.uri = this.router.url
if (this.parentComment) {
const mentions = this.parentComments
.filter(c => c.account.id !== this.user.account.id) // Don't add mention of ourselves
.map(c => '@' + c.by)
if (this.user) {
if (this.focusOnInit === true) {
this.textareaElement.nativeElement.focus()
}
const mentionsSet = new Set(mentions)
const mentionsText = Array.from(mentionsSet).join(' ') + ' '
if (this.parentComment) {
const mentions = this.parentComments
.filter(c => c.account.id !== this.user.account.id) // Don't add mention of ourselves
.map(c => '@' + c.by)
this.form.patchValue({ text: mentionsText })
const mentionsSet = new Set(mentions)
const mentionsText = Array.from(mentionsSet).join(' ') + ' '
this.form.patchValue({ text: mentionsText })
}
}
}
@ -67,6 +79,20 @@ export class VideoCommentAddComponent extends FormReactive implements OnInit {
this.formValidated()
}
openVisitorModal (event) {
if (this.user === null) { // we only open it for visitors
// fixing ng-bootstrap ModalService and the "Expression Changed After It Has Been Checked" Error
event.srcElement.blur()
event.preventDefault()
this.modalService.open(this.visitorModal)
}
}
hideVisitorModal () {
this.modalService.dismissAll()
}
formValidated () {
// If we validate very quickly the comment form, we might comment twice
if (this.addingComment) return
@ -101,6 +127,17 @@ export class VideoCommentAddComponent extends FormReactive implements OnInit {
return this.form.value['text']
}
getAvatarUrl () {
if (this.user) return this.user.accountAvatarUrl
return window.location.origin + '/client/assets/images/default-avatar.png'
}
gotoLogin () {
this.hideVisitorModal()
this.authService.redirectUrl = this.router.url
this.router.navigate([ '/login' ])
}
private addCommentReply (commentCreate: VideoCommentCreate) {
return this.videoCommentService
.addCommentReply(this.video.id, this.parentComment.id, commentCreate)

View File

@ -10,7 +10,6 @@
<ng-template [ngIf]="video.commentsEnabled === true">
<my-video-comment-add
*ngIf="isUserLoggedIn()"
[video]="video"
[user]="user"
(commentCreated)="onCommentThreadCreated($event)"

View File

@ -126,7 +126,7 @@
<img [src]="video.videoChannelAvatarUrl" alt="Video channel avatar" />
</a>
<my-subscribe-button #subscribeButton *ngIf="isUserLoggedIn()" [videoChannel]="video.channel" size="small"></my-subscribe-button>
<my-subscribe-button #subscribeButton [videoChannel]="video.channel" size="small"></my-subscribe-button>
</div>
<div class="video-info-by">
@ -134,8 +134,6 @@
<span i18n>By {{ video.byAccount }}</span>
<img [src]="video.accountAvatarUrl" alt="Account avatar" />
</a>
<my-help helpType="custom" i18n-customHtml customHtml="You can subscribe to this account via any ActivityPub-capable fediverse instance. For instance with Mastodon or Pleroma you can type in the search box <strong>@{{video.account.name}}@{{video.account.host}}</strong> and subscribe there."></my-help>
</div>
</div>

View File

@ -199,9 +199,18 @@ label {
.dropdown-item {
padding: 3px 15px;
&:active {
color: #000 !important;
}
}
button {
@include disable-default-a-behaviour;
}
a {
@include disable-default-a-behaviour;
color: #000 !important;
}
}

View File

@ -46,7 +46,7 @@ $nav-pills-link-active-color: #000;
@import '~bootstrap/scss/buttons';
//@import '~bootstrap/scss/transitions';
@import '~bootstrap/scss/dropdown';
//@import '~bootstrap/scss/button-group';
@import '~bootstrap/scss/button-group';
@import '~bootstrap/scss/input-group';
//@import '~bootstrap/scss/custom-forms';
@import '~bootstrap/scss/nav';