This commit is contained in:
Nicolas Constant 2019-04-07 14:18:10 -04:00
parent caad3689f1
commit 8559d170f9
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
3 changed files with 133 additions and 55 deletions

View File

@ -4,7 +4,9 @@
</a>
<ion-icon *ngIf="isLocked" class="action-bar__lock" name="lock" title="Account can't access this post"></ion-icon>
<a *ngIf="!(isBoostLocked || isLocked)" href class="action-bar__link" title="Boost" [class.boosted]="isBoosted"
<a *ngIf="!(isBoostLocked || isLocked)" href class="action-bar__link" title="Boost"
[class.boosted]="isBoosted"
[class.boosting]="boostIsLoading"
(click)="boost()">
<ion-icon name="md-swap"></ion-icon>
</a>
@ -12,7 +14,9 @@
title="This post cannot be boosted"></ion-icon>
<ion-icon *ngIf="isLocked" class="action-bar__lock" name="lock" title="Account can't access this post"></ion-icon>
<a *ngIf="!isLocked" href class="action-bar__link" title="Favourite" [class.favorited]="isFavorited"
<a *ngIf="!isLocked" href class="action-bar__link" title="Favourite"
[class.favorited]="isFavorited"
[class.favoriting]="favoriteIsLoading"
(click)="favorite()">
<ion-icon name="md-star"></ion-icon>
</a>

View File

@ -1,4 +1,5 @@
@import "variables";
.action-bar {
// outline: 1px solid greenyellow; // height: 20px;
margin: 5px 10px 5px $avatar-column-space;
@ -9,9 +10,11 @@
&__link {
color: $status-secondary-color;
&:hover {
color: $status-links-color;
}
&:not(:last-child) {
margin-right: 15px;
}
@ -50,9 +53,9 @@
.boosted {
color: $boost-color;
&:hover {
color: darken($boost-color, 10);
color: darken($boost-color, 10);
}
}
@ -62,4 +65,70 @@
&:hover {
color: darken($favorite-color, 10);
}
}
@keyframes loadingAnimation {
0% {
opacity: 0;
}
50% {
opacity: 1;
}
100% {
opacity: 0;
}
}
@-o-keyframes loadingAnimation {
0% {
opacity: 0;
}
50% {
opacity: 1;
}
100% {
opacity: 0;
}
}
@-moz-keyframes loadingAnimation {
0% {
opacity: 0;
}
50% {
opacity: 1;
}
100% {
opacity: 0;
}
}
@-webkit-keyframes loadingAnimation {
0% {
opacity: 0;
}
50% {
opacity: 1;
}
100% {
opacity: 0;
}
}
.boosting,
.favoriting {
-webkit-animation: loadingAnimation 1s infinite;
-moz-animation: loadingAnimation 1s infinite;
-o-animation: loadingAnimation 1s infinite;
animation: loadingAnimation 1s infinite;
}

View File

@ -34,6 +34,9 @@ export class ActionBarComponent implements OnInit, OnDestroy {
isBoostLocked: boolean;
isLocked: boolean;
favoriteIsLoading: boolean;
boostIsLoading: boolean;
isContentWarningActive: boolean = false;
private isProviderSelected: boolean;
@ -48,7 +51,7 @@ export class ActionBarComponent implements OnInit, OnDestroy {
constructor(
private readonly store: Store,
private readonly toolsService: ToolsService,
private readonly mastodonService: MastodonService,
private readonly mastodonService: MastodonService,
private readonly notificationService: NotificationService) {
this.accounts$ = this.store.select(state => state.registeredaccounts.accounts);
@ -87,7 +90,7 @@ export class ActionBarComponent implements OnInit, OnDestroy {
this.isLocked = false;
}
if(status.sensitive || status.spoiler_text){
if (status.sensitive || status.spoiler_text) {
this.isContentWarningActive = true;
}
@ -113,56 +116,63 @@ export class ActionBarComponent implements OnInit, OnDestroy {
}
boost(): boolean {
//TODO get rid of that
this.selectedAccounts.forEach((account: AccountInfo) => {
if(this.boostIsLoading) return;
const usableStatus = this.toolsService.getStatusUsableByAccount(account, this.statusWrapper);
usableStatus
.then((status: Status) => {
if (this.isBoosted && status.reblogged) {
return this.mastodonService.unreblog(account, status);
} else if(!this.isBoosted && !status.reblogged){
return this.mastodonService.reblog(account, status);
} else {
return Promise.resolve(status);
}
})
.then((boostedStatus: Status) => {
this.bootedStatePerAccountId[account.id] = boostedStatus.reblogged;
this.checkIfBoosted();
// this.isBoosted = !this.isBoosted;
})
.catch((err: HttpErrorResponse) => {
this.notificationService.notifyHttpError(err);
});
});
this.boostIsLoading = true;
const account = this.toolsService.getSelectedAccounts()[0];
const usableStatus = this.toolsService.getStatusUsableByAccount(account, this.statusWrapper);
usableStatus
.then((status: Status) => {
if (this.isBoosted && status.reblogged) {
return this.mastodonService.unreblog(account, status);
} else if (!this.isBoosted && !status.reblogged) {
return this.mastodonService.reblog(account, status);
} else {
return Promise.resolve(status);
}
})
.then((boostedStatus: Status) => {
this.bootedStatePerAccountId[account.id] = boostedStatus.reblogged;
this.checkIfBoosted();
})
.catch((err: HttpErrorResponse) => {
this.notificationService.notifyHttpError(err);
})
.then(() => {
this.boostIsLoading = false;
});
return false;
}
favorite(): boolean {
this.selectedAccounts.forEach((account: AccountInfo) => {
const usableStatus = this.toolsService.getStatusUsableByAccount(account, this.statusWrapper);
usableStatus
.then((status: Status) => {
if (this.isFavorited && status.favourited) {
return this.mastodonService.unfavorite(account, status);
} else if(!this.isFavorited && !status.favourited) {
return this.mastodonService.favorite(account, status);
} else {
return Promise.resolve(status);
}
})
.then((favoritedStatus: Status) => {
this.favoriteStatePerAccountId[account.id] = favoritedStatus.favourited;
this.checkIfFavorited();
// this.isFavorited = !this.isFavorited;
})
.catch((err: HttpErrorResponse) => {
this.notificationService.notifyHttpError(err);
});
});
if(this.favoriteIsLoading) return;
this.favoriteIsLoading = true;
const account = this.toolsService.getSelectedAccounts()[0];
const usableStatus = this.toolsService.getStatusUsableByAccount(account, this.statusWrapper);
usableStatus
.then((status: Status) => {
if (this.isFavorited && status.favourited) {
return this.mastodonService.unfavorite(account, status);
} else if (!this.isFavorited && !status.favourited) {
return this.mastodonService.favorite(account, status);
} else {
return Promise.resolve(status);
}
})
.then((favoritedStatus: Status) => {
this.favoriteStatePerAccountId[account.id] = favoritedStatus.favourited;
this.checkIfFavorited();
// this.isFavorited = !this.isFavorited;
})
.catch((err: HttpErrorResponse) => {
this.notificationService.notifyHttpError(err);
})
.then(() => {
this.favoriteIsLoading = false;
});
return false;
}
@ -189,9 +199,4 @@ export class ActionBarComponent implements OnInit, OnDestroy {
console.warn('more'); //TODO
return false;
}
// private getSelectedAccounts(): AccountInfo[] {
// var regAccounts = <AccountInfo[]>this.store.snapshot().registeredaccounts.accounts;
// return regAccounts;
// }
}