first iteration of favorites section

This commit is contained in:
Nicolas Constant 2019-03-23 16:34:46 -04:00
parent c481c05a0c
commit 76955704e7
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
5 changed files with 60 additions and 14 deletions

View File

@ -1,15 +1,57 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, Output, EventEmitter, Input } from '@angular/core';
import { StatusWrapper } from '../../../../models/common.model';
import { OpenThreadEvent } from '../../../../services/tools.service';
import { AccountWrapper } from '../../../../models/account.models';
import { MastodonService } from '../../../../services/mastodon.service';
import { Status } from '../../../../services/models/mastodon.interfaces';
import { NotificationService } from '../../../../services/notification.service';
@Component({
selector: 'app-favorites',
templateUrl: './favorites.component.html',
styleUrls: ['./favorites.component.scss']
templateUrl: '../../../stream/stream-statuses/stream-statuses.component.html',
styleUrls: ['../../../stream/stream-statuses/stream-statuses.component.scss', './favorites.component.scss']
})
export class FavoritesComponent implements OnInit {
statuses: StatusWrapper[] = [];
displayError: string;
isLoading = true;
isThread = false;
hasContentWarnings = false;
constructor() { }
@Output() browseAccountEvent = new EventEmitter<string>();
@Output() browseHashtagEvent = new EventEmitter<string>();
@Output() browseThreadEvent = new EventEmitter<OpenThreadEvent>();
@Input() account: AccountWrapper;
constructor(
private readonly notificationService: NotificationService,
private readonly mastodonService: MastodonService) { }
ngOnInit() {
this.getFavorites();
}
private getFavorites(){
this.isLoading = true;
this.statuses.length = 0;
this.mastodonService.getFavorites(this.account.info)
.then((statuses: Status[]) => {
for (const s of statuses) {
const wrapper = new StatusWrapper(s, this.account.info);
this.statuses.push(wrapper);
}
})
.catch(err => {
this.notificationService.notifyHttpError(err);
})
.then(() => {
this.isLoading = false;
});
}
}

View File

@ -29,7 +29,7 @@
</div>
<app-direct-messages class="account__body" *ngIf="subPanel === 'dm'"></app-direct-messages>
<app-favorites class="account__body" *ngIf="subPanel === 'favorites'"></app-favorites>
<app-favorites class="account__body" *ngIf="subPanel === 'favorites'" [account]="account"></app-favorites>
<app-mentions class="account__body" *ngIf="subPanel === 'mentions'"></app-mentions>
<app-my-account class="account__body" *ngIf="subPanel === 'account'" [account]="account">
</app-my-account>

View File

@ -55,6 +55,6 @@ $account-header-height: 60px;
overflow: auto;
height: calc(100% - #{$account-header-height} - 31px);
display: block;
// border: 1px red solid;
font-size: $default-font-size;
}
}

View File

@ -134,6 +134,12 @@ export class MastodonService {
return this.httpClient.get<Context>(route, { headers: headers }).toPromise();
}
getFavorites(account: AccountInfo): Promise<Status[]> {
const route = `https://${account.instance}${this.apiRoutes.getFavourites}`;
const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` });
return this.httpClient.get<Status[]>(route, { headers: headers }).toPromise();
}
searchAccount(account: AccountInfo, query: string, limit: number = 40, following: boolean = false): Promise<Account[]> {
const route = `https://${account.instance}${this.apiRoutes.searchForAccounts}?q=${query}&limit=${limit}&following=${following}`;
const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` });
@ -164,8 +170,6 @@ export class MastodonService {
return this.httpClient.post<Status>(route, null, { headers: headers }).toPromise()
}
getRelationships(account: AccountInfo, accountsToRetrieve: Account[]): Promise<Relationship[]> {
let params = `?${this.formatArray(accountsToRetrieve.map(x => x.id.toString()), 'id')}`;