From 76955704e74453c62050d11b0081c28a3e68290d Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Sat, 23 Mar 2019 16:34:46 -0400 Subject: [PATCH] first iteration of favorites section --- .../favorites/favorites.component.ts | 56 ++++++++++++++++--- .../manage-account.component.html | 2 +- .../manage-account.component.scss | 2 +- .../manage-account.component.ts | 2 +- src/app/services/mastodon.service.ts | 12 ++-- 5 files changed, 60 insertions(+), 14 deletions(-) diff --git a/src/app/components/floating-column/manage-account/favorites/favorites.component.ts b/src/app/components/floating-column/manage-account/favorites/favorites.component.ts index d3a373e1..9ff75dbe 100644 --- a/src/app/components/floating-column/manage-account/favorites/favorites.component.ts +++ b/src/app/components/floating-column/manage-account/favorites/favorites.component.ts @@ -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'] + selector: 'app-favorites', + 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(); + @Output() browseHashtagEvent = new EventEmitter(); + @Output() browseThreadEvent = new EventEmitter(); - ngOnInit() { - } + @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; + }); + + } } diff --git a/src/app/components/floating-column/manage-account/manage-account.component.html b/src/app/components/floating-column/manage-account/manage-account.component.html index a345f919..9398a871 100644 --- a/src/app/components/floating-column/manage-account/manage-account.component.html +++ b/src/app/components/floating-column/manage-account/manage-account.component.html @@ -29,7 +29,7 @@ - + diff --git a/src/app/components/floating-column/manage-account/manage-account.component.scss b/src/app/components/floating-column/manage-account/manage-account.component.scss index c52cd5c8..d0bea638 100644 --- a/src/app/components/floating-column/manage-account/manage-account.component.scss +++ b/src/app/components/floating-column/manage-account/manage-account.component.scss @@ -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; } } \ No newline at end of file diff --git a/src/app/components/floating-column/manage-account/manage-account.component.ts b/src/app/components/floating-column/manage-account/manage-account.component.ts index 19ac752a..feee4a35 100644 --- a/src/app/components/floating-column/manage-account/manage-account.component.ts +++ b/src/app/components/floating-column/manage-account/manage-account.component.ts @@ -25,7 +25,7 @@ export class ManageAccountComponent implements OnInit { constructor() { } - ngOnInit() { + ngOnInit() { } loadSubPanel(subpanel: string): boolean { diff --git a/src/app/services/mastodon.service.ts b/src/app/services/mastodon.service.ts index 195b1c38..bdb5526d 100644 --- a/src/app/services/mastodon.service.ts +++ b/src/app/services/mastodon.service.ts @@ -7,7 +7,7 @@ import { AccountInfo } from '../states/accounts.state'; import { StreamTypeEnum } from '../states/streams.state'; @Injectable() -export class MastodonService { +export class MastodonService { private apiRoutes = new ApiRoutes(); constructor(private readonly httpClient: HttpClient) { } @@ -133,6 +133,12 @@ export class MastodonService { const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` }); return this.httpClient.get(route, { headers: headers }).toPromise(); } + + getFavorites(account: AccountInfo): Promise { + const route = `https://${account.instance}${this.apiRoutes.getFavourites}`; + const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` }); + return this.httpClient.get(route, { headers: headers }).toPromise(); + } searchAccount(account: AccountInfo, query: string, limit: number = 40, following: boolean = false): Promise { const route = `https://${account.instance}${this.apiRoutes.searchForAccounts}?q=${query}&limit=${limit}&following=${following}`; @@ -162,9 +168,7 @@ export class MastodonService { const route = `https://${account.instance}${this.apiRoutes.unfavouritingStatus}`.replace('{0}', status.id); const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` }); return this.httpClient.post(route, null, { headers: headers }).toPromise() - } - - + } getRelationships(account: AccountInfo, accountsToRetrieve: Account[]): Promise { let params = `?${this.formatArray(accountsToRetrieve.map(x => x.id.toString()), 'id')}`;