clean up, renaming to be more name generic

This commit is contained in:
Nicolas Constant 2018-09-15 22:08:59 -04:00
parent 1137e7f69e
commit 97015ba0fe
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
9 changed files with 42 additions and 64 deletions

View File

@ -27,7 +27,7 @@ import { FloatingColumnComponent } from './components/floating-column/floating-c
import { ColumnsEditorComponent } from './components/floating-column/columns-editor/columns-editor.component';
import { MessageEditorComponent } from './components/floating-column/message-editor/message-editor.component';
import { StreamsState } from "./states/streams.state";
import { TootComponent } from "./components/stream/toot/toot.component";
import { StatusComponent } from "./components/stream/status/status.component";
const routes: Routes = [
{ path: "", redirectTo: "home", pathMatch: "full" },
@ -43,7 +43,7 @@ const routes: Routes = [
StreamsMainDisplayComponent,
StreamComponent,
StreamsSelectionFooterComponent,
TootComponent,
StatusComponent,
RegisterNewAccountComponent,
AccountIconComponent,
FloatingColumnComponent,

View File

@ -0,0 +1,5 @@
<div class="toot">
<img class="toot__avatar" src="{{ status.account.avatar }}" />
<a href class="toot__profile-link"><span class="toot__fullname" innerHTML="{{status.account.display_name}}"></span> @<span id="toot-username" innerHTML="{{status.account.username}}"></span></a>
<div class="toot__content" innerHTML="{{status.content}}"></div>
</div>

View File

@ -1,20 +1,20 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { TootComponent } from './toot.component';
import { StatusComponent } from './status.component';
describe('TootComponent', () => {
let component: TootComponent;
let fixture: ComponentFixture<TootComponent>;
describe('StatusComponent', () => {
let component: StatusComponent;
let fixture: ComponentFixture<StatusComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ TootComponent ]
declarations: [ StatusComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(TootComponent);
fixture = TestBed.createComponent(StatusComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

View File

@ -0,0 +1,18 @@
import { Component, OnInit, Input } from "@angular/core";
import { Status } from "../../../services/models/mastodon.interfaces";
@Component({
selector: "app-status",
templateUrl: "./status.component.html",
styleUrls: ["./status.component.scss"]
})
export class StatusComponent implements OnInit {
@Input() status: Status;
constructor() { }
ngOnInit() {
}
}

View File

@ -3,8 +3,8 @@
<a href title="return to top" (click)="goToTop()"><h1>{{ streamElement.name.toUpperCase() }}</h1></a>
</div>
<div class="stream-toots" data-simplebar>
<div *ngFor="let toot of statuses">
<app-toot [toot]="toot"></app-toot>
<div *ngFor="let status of statuses">
<app-status [status]="status"></app-status>
</div>
</div>
</div>

View File

@ -14,12 +14,12 @@ import { Status } from "../../services/models/mastodon.interfaces";
styleUrls: ["./stream.component.scss"]
})
export class StreamComponent implements OnInit {
private _streamElement: StreamElement;
private apiRoutes = new ApiRoutes();
private account: AccountInfo;
private websocketStreaming: StreamingWrapper;
private type: StreamTypeEnum;
statuses: TootWrapper[] = [];
private _streamElement: StreamElement;
statuses: Status[] = [];
@Input()
set streamElement(streamElement: StreamElement) {
@ -29,7 +29,7 @@ export class StreamComponent implements OnInit {
const user = splitedUserName[0];
const instance = splitedUserName[1];
this.account = this.getRegisteredAccounts().find(x => x.username == user && x.instance == instance);
this.type = streamElement.type;
// this.type = streamElement.type;
this.retrieveToots(); //TODO change this for WebSockets
this.launchWebsocket();
@ -39,15 +39,12 @@ export class StreamComponent implements OnInit {
return this._streamElement;
}
toots: TootWrapper[] = [];
constructor(
private readonly store: Store,
private readonly streamingService: StreamingService,
private readonly httpClient: HttpClient) {
}
ngOnInit() {
}
@ -56,7 +53,7 @@ export class StreamComponent implements OnInit {
}
private getTimelineRoute(): string {
switch (this.type) {
switch (this._streamElement.type) {
case StreamTypeEnum.personnal:
return this.apiRoutes.getHomeTimeline;
case StreamTypeEnum.local:
@ -78,11 +75,7 @@ export class StreamComponent implements OnInit {
const headers = new HttpHeaders({ 'Authorization': `Bearer ${this.account.token.access_token}` });
this.httpClient.get<Status[]>(route, { headers: headers }).toPromise()
.then((results: Status[]) => {
var statuses = results.map((status: Status) => {
return new TootWrapper(status);
});
for (const s of statuses) {
for (const s of results) {
this.statuses.push(s);
}
});
@ -91,7 +84,7 @@ export class StreamComponent implements OnInit {
private launchWebsocket(): void {
//Web socket
let streamRequest: string;
switch (this.type) {
switch (this._streamElement.type) {
case StreamTypeEnum.global:
streamRequest = 'public';
break;
@ -107,25 +100,9 @@ export class StreamComponent implements OnInit {
this.websocketStreaming.statusUpdateSubjet.subscribe((update: StatusUpdate) => {
if (update) {
if (update.type === EventEnum.update) {
this.statuses.unshift(new TootWrapper(update.status));
this.statuses.unshift(update.status);
}
}
});
}
}
export class TootWrapper {
constructor(status: Status) {
this.account = new AccountWrapper();
this.account.username = status.account.username;
this.account.display_name = status.account.display_name;
this.account.avatar = status.account.avatar;
this.content = status.content;
}
account: AccountWrapper; //TODO change to Account
content: string;
}
}

View File

@ -1,5 +0,0 @@
<div class="toot">
<img class="toot__avatar" src="{{ toot.account.avatar }}" />
<a href class="toot__profile-link"><span class="toot__fullname" innerHTML="{{toot.account.display_name}}"></span> @<span id="toot-username" innerHTML="{{toot.account.username}}"></span></a>
<div class="toot__content" innerHTML="{{toot.content}}"></div>
</div>

View File

@ -1,17 +0,0 @@
import { Component, OnInit, Input } from "@angular/core";
import { TootWrapper } from "../stream.component";
@Component({
selector: "app-toot",
templateUrl: "./toot.component.html",
styleUrls: ["./toot.component.scss"]
})
export class TootComponent implements OnInit {
@Input() toot: TootWrapper;
constructor() { }
ngOnInit() {
}
}