better displaying of favs and boosts states
This commit is contained in:
parent
afed572916
commit
a4c32b3464
|
@ -26,6 +26,9 @@ export class ActionBarComponent implements OnInit, OnDestroy {
|
|||
private isProviderSelected: boolean;
|
||||
private selectedAccounts: AccountInfo[];
|
||||
|
||||
private favoriteStatePerAccountId: { [id: string]: boolean; } = {};
|
||||
private bootedStatePerAccountId: { [id: string]: boolean; } = {};
|
||||
|
||||
private accounts$: Observable<AccountInfo[]>;
|
||||
private accountSub: Subscription;
|
||||
|
||||
|
@ -40,8 +43,12 @@ export class ActionBarComponent implements OnInit, OnDestroy {
|
|||
// const selectedAccounts = this.getSelectedAccounts();
|
||||
// this.checkStatus(selectedAccounts);
|
||||
|
||||
const status = this.statusWrapper.status;
|
||||
const account = this.statusWrapper.provider;
|
||||
this.favoriteStatePerAccountId[account.id] = status.favourited;
|
||||
this.bootedStatePerAccountId[account.id] = status.reblogged;
|
||||
|
||||
this.accountSub = this.accounts$.subscribe((accounts: AccountInfo[]) => {
|
||||
console.warn('selectedAccounts');
|
||||
this.checkStatus(accounts);
|
||||
});
|
||||
}
|
||||
|
@ -67,6 +74,9 @@ export class ActionBarComponent implements OnInit, OnDestroy {
|
|||
} else {
|
||||
this.isLocked = false;
|
||||
}
|
||||
|
||||
this.checkIfFavorited();
|
||||
this.checkIfBoosted();
|
||||
}
|
||||
|
||||
reply(): boolean {
|
||||
|
@ -93,14 +103,16 @@ export class ActionBarComponent implements OnInit, OnDestroy {
|
|||
|
||||
pipeline
|
||||
.then((status: Status) => {
|
||||
if(this.isBoosted) {
|
||||
if (this.isBoosted) {
|
||||
return this.mastodonService.unreblog(account, status);
|
||||
} else {
|
||||
return this.mastodonService.reblog(account, status);
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
this.isBoosted = !this.isBoosted;
|
||||
.then((boostedStatus: Status) => {
|
||||
this.bootedStatePerAccountId[account.id] = boostedStatus.reblogged;
|
||||
this.checkIfBoosted();
|
||||
// this.isBoosted = !this.isBoosted;
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
|
@ -129,14 +141,16 @@ export class ActionBarComponent implements OnInit, OnDestroy {
|
|||
|
||||
pipeline
|
||||
.then((status: Status) => {
|
||||
if(this.isFavorited) {
|
||||
if (this.isFavorited) {
|
||||
return this.mastodonService.unfavorite(account, status);
|
||||
} else {
|
||||
return this.mastodonService.favorite(account, status);
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
this.isFavorited = !this.isFavorited;
|
||||
.then((favoritedStatus: Status) => {
|
||||
this.favoriteStatePerAccountId[account.id] = favoritedStatus.favourited;
|
||||
this.checkIfFavorited();
|
||||
// this.isFavorited = !this.isFavorited;
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
|
@ -145,6 +159,25 @@ export class ActionBarComponent implements OnInit, OnDestroy {
|
|||
return false;
|
||||
}
|
||||
|
||||
private checkIfBoosted() {
|
||||
const selectedAccount = <AccountInfo>this.selectedAccounts[0];
|
||||
if (selectedAccount) {
|
||||
this.isBoosted = this.bootedStatePerAccountId[selectedAccount.id];
|
||||
} else {
|
||||
this.isBoosted = false;
|
||||
}
|
||||
}
|
||||
|
||||
private checkIfFavorited() {
|
||||
const selectedAccount = <AccountInfo>this.selectedAccounts[0];
|
||||
|
||||
if (selectedAccount) {
|
||||
this.isFavorited = this.favoriteStatePerAccountId[selectedAccount.id];
|
||||
} else {
|
||||
this.isFavorited = false;
|
||||
}
|
||||
}
|
||||
|
||||
more(): boolean {
|
||||
console.warn('more');
|
||||
return false;
|
||||
|
|
|
@ -116,15 +116,16 @@ export interface Status {
|
|||
created_at: string;
|
||||
reblogs_count: string;
|
||||
favourites_count: string;
|
||||
reblogged: string;
|
||||
favourited: string;
|
||||
sensitive: string;
|
||||
reblogged: boolean;
|
||||
favourited: boolean;
|
||||
sensitive: boolean;
|
||||
spoiler_text: string;
|
||||
visibility: string;
|
||||
media_attachments: Attachment[];
|
||||
mentions: string;
|
||||
tags: string;
|
||||
application: Application;
|
||||
emojis: any[];
|
||||
}
|
||||
export interface Tag {
|
||||
name: string;
|
||||
|
|
Loading…
Reference in New Issue