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 isProviderSelected: boolean;
|
||||||
private selectedAccounts: AccountInfo[];
|
private selectedAccounts: AccountInfo[];
|
||||||
|
|
||||||
|
private favoriteStatePerAccountId: { [id: string]: boolean; } = {};
|
||||||
|
private bootedStatePerAccountId: { [id: string]: boolean; } = {};
|
||||||
|
|
||||||
private accounts$: Observable<AccountInfo[]>;
|
private accounts$: Observable<AccountInfo[]>;
|
||||||
private accountSub: Subscription;
|
private accountSub: Subscription;
|
||||||
|
|
||||||
|
@ -40,8 +43,12 @@ export class ActionBarComponent implements OnInit, OnDestroy {
|
||||||
// const selectedAccounts = this.getSelectedAccounts();
|
// const selectedAccounts = this.getSelectedAccounts();
|
||||||
// this.checkStatus(selectedAccounts);
|
// 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[]) => {
|
this.accountSub = this.accounts$.subscribe((accounts: AccountInfo[]) => {
|
||||||
console.warn('selectedAccounts');
|
|
||||||
this.checkStatus(accounts);
|
this.checkStatus(accounts);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -67,6 +74,9 @@ export class ActionBarComponent implements OnInit, OnDestroy {
|
||||||
} else {
|
} else {
|
||||||
this.isLocked = false;
|
this.isLocked = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.checkIfFavorited();
|
||||||
|
this.checkIfBoosted();
|
||||||
}
|
}
|
||||||
|
|
||||||
reply(): boolean {
|
reply(): boolean {
|
||||||
|
@ -93,20 +103,22 @@ export class ActionBarComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
pipeline
|
pipeline
|
||||||
.then((status: Status) => {
|
.then((status: Status) => {
|
||||||
if(this.isBoosted) {
|
if (this.isBoosted) {
|
||||||
return this.mastodonService.unreblog(account, status);
|
return this.mastodonService.unreblog(account, status);
|
||||||
} else {
|
} else {
|
||||||
return this.mastodonService.reblog(account, status);
|
return this.mastodonService.reblog(account, status);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then((boostedStatus: Status) => {
|
||||||
this.isBoosted = !this.isBoosted;
|
this.bootedStatePerAccountId[account.id] = boostedStatus.reblogged;
|
||||||
|
this.checkIfBoosted();
|
||||||
|
// this.isBoosted = !this.isBoosted;
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,22 +141,43 @@ export class ActionBarComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
pipeline
|
pipeline
|
||||||
.then((status: Status) => {
|
.then((status: Status) => {
|
||||||
if(this.isFavorited) {
|
if (this.isFavorited) {
|
||||||
return this.mastodonService.unfavorite(account, status);
|
return this.mastodonService.unfavorite(account, status);
|
||||||
} else {
|
} else {
|
||||||
return this.mastodonService.favorite(account, status);
|
return this.mastodonService.favorite(account, status);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then((favoritedStatus: Status) => {
|
||||||
this.isFavorited = !this.isFavorited;
|
this.favoriteStatePerAccountId[account.id] = favoritedStatus.favourited;
|
||||||
|
this.checkIfFavorited();
|
||||||
|
// this.isFavorited = !this.isFavorited;
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return false;
|
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 {
|
more(): boolean {
|
||||||
console.warn('more');
|
console.warn('more');
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -116,15 +116,16 @@ export interface Status {
|
||||||
created_at: string;
|
created_at: string;
|
||||||
reblogs_count: string;
|
reblogs_count: string;
|
||||||
favourites_count: string;
|
favourites_count: string;
|
||||||
reblogged: string;
|
reblogged: boolean;
|
||||||
favourited: string;
|
favourited: boolean;
|
||||||
sensitive: string;
|
sensitive: boolean;
|
||||||
spoiler_text: string;
|
spoiler_text: string;
|
||||||
visibility: string;
|
visibility: string;
|
||||||
media_attachments: Attachment[];
|
media_attachments: Attachment[];
|
||||||
mentions: string;
|
mentions: string;
|
||||||
tags: string;
|
tags: string;
|
||||||
application: Application;
|
application: Application;
|
||||||
|
emojis: any[];
|
||||||
}
|
}
|
||||||
export interface Tag {
|
export interface Tag {
|
||||||
name: string;
|
name: string;
|
||||||
|
|
Loading…
Reference in New Issue