reintegrating streams from colums state

This commit is contained in:
Nicolas Constant 2018-09-09 23:13:00 -04:00
parent dee15d9070
commit 24b3ff961e
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
6 changed files with 49 additions and 77 deletions

View File

@ -19,7 +19,6 @@ import { TootComponent } from "./components/toot/toot.component";
import { RegisterNewAccountComponent } from "./pages/register-new-account/register-new-account.component";
import { AuthService } from "./services/auth.service";
import { AccountsService } from "./services/accounts.service";
import { StreamsService } from "./services/streams.service";
import { StreamingService } from "./services/streaming.service";
import { RegisteredAppsState } from "./states/registered-apps.state";
import { AccountsState } from "./states/accounts.state";
@ -66,7 +65,7 @@ const routes: Routes = [
]),
NgxsStoragePluginModule.forRoot()
],
providers: [AuthService, NavigationService, AccountsService, StreamsService, StreamingService, { provide: APP_INITIALIZER, useFactory: settingsServiceFactory, deps: [AccountsService], multi: true }],
providers: [AuthService, NavigationService, AccountsService, StreamingService, { provide: APP_INITIALIZER, useFactory: settingsServiceFactory, deps: [AccountsService], multi: true }],
bootstrap: [AppComponent]
})
export class AppModule { }

View File

@ -1,5 +1,5 @@
import { Component, OnInit, Input } from '@angular/core';
import { ColumnElement, ColumnTypeEnum, AddColumn } from '../../../states/panels.state';
import { ColumnElement, StreamTypeEnum, AddColumn } from '../../../states/panels.state';
import { Store } from '@ngxs/store';
@Component({
@ -17,9 +17,9 @@ export class ColumnsEditorComponent implements OnInit {
ngOnInit() {
this.availableColumns.length = 0;
this.availableColumns.push(new ColumnElement(ColumnTypeEnum.global, 'Global Timeline', this.username));
this.availableColumns.push(new ColumnElement(ColumnTypeEnum.local, 'Local Timeline', this.username));
this.availableColumns.push(new ColumnElement(ColumnTypeEnum.personnal, 'Personnal Timeline', this.username));
this.availableColumns.push(new ColumnElement(StreamTypeEnum.global, 'Global Timeline', this.username));
this.availableColumns.push(new ColumnElement(StreamTypeEnum.local, 'Local Timeline', this.username));
this.availableColumns.push(new ColumnElement(StreamTypeEnum.personnal, 'Personnal Timeline', this.username));
}
addColumn(column: ColumnElement): boolean {

View File

@ -6,6 +6,7 @@ import { AccountWrapper } from "./account.models";
import { ApiRoutes } from "../services/models/api.settings";
import { Account, Status } from "../services/models/mastodon.interfaces";
import { StreamingService, StreamingWrapper } from "../services/streaming.service";
import { StreamTypeEnum } from "../states/panels.state";
export class Stream {
private apiRoutes = new ApiRoutes();
@ -36,7 +37,7 @@ export class Stream {
// .then((res: Response) => {
// const statuses = (res.json() as Status[])
// .map((status: Status) => {
// return new TootWrapper(status);
// return new TootWrapper(status);
// });
// this.statuses.next(statuses);
@ -46,22 +47,22 @@ export class Stream {
private getTimelineRoute(): string {
switch (this.type) {
case StreamTypeEnum.Home:
case StreamTypeEnum.personnal:
return this.apiRoutes.getHomeTimeline;
case StreamTypeEnum.Local:
case StreamTypeEnum.local:
return this.apiRoutes.getPublicTimeline + `?Local=true`;
case StreamTypeEnum.Public:
case StreamTypeEnum.global:
return this.apiRoutes.getPublicTimeline + `?Local=false`;
}
}
}
export enum StreamTypeEnum {
Home,
Public,
Local
}
// export enum StreamTypeEnum {
// Home,
// Public,
// Local
// }
export class TootWrapper {

View File

@ -1,7 +1,10 @@
import { Component, OnInit } from "@angular/core";
import { Component, OnInit, OnDestroy } from "@angular/core";
import { Stream } from "../../models/stream.models";
import { StreamsService } from "../../services/streams.service";
import { Observable, Subscription } from "rxjs";
import { ColumnElement } from "../../states/panels.state";
import { Store } from "@ngxs/store";
import { Http } from "@angular/http";
@Component({
@ -9,24 +12,44 @@ import { StreamsService } from "../../services/streams.service";
templateUrl: "./streams-main-display.component.html",
styleUrls: ["./streams-main-display.component.scss"]
})
export class StreamsMainDisplayComponent implements OnInit {
export class StreamsMainDisplayComponent implements OnInit, OnDestroy {
streams: Stream[] = [];
constructor(private readonly streamService: StreamsService) {
private columns$: Observable<ColumnElement[]>;
private columnsStateSub: Subscription;
constructor(
private readonly http: Http,
private readonly store: Store) {
this.columns$ = this.store.select(state => state.columnsstatemodel.columns);
}
ngOnInit() {
this.streamService.streamsSubject.subscribe((streams: Stream[]) => {
for (let s of streams) {
this.streams.push(s);
this.columnsStateSub = this.columns$.subscribe((columns: ColumnElement[]) => {
this.streams.length = 0;
for (const column of columns) {
const newStream = new Stream(this.http, column.name, column.type);
this.streams.push(newStream);
}
});
// this.streamService.streamsSubject.subscribe((streams: Stream[]) => {
// for (let s of streams) {
// this.streams.push(s);
// }
// });
//for (let i = 0; i < 3; i++) {
// this.streams.push(new Stream());
//}
}
ngOnDestroy(): void {
this.columnsStateSub.unsubscribe();
}
}

View File

@ -1,51 +0,0 @@
import { Injectable } from "@angular/core";
import { Http } from "@angular/http";
import { BehaviorSubject } from "rxjs";
import { Stream, StreamTypeEnum } from "../models/stream.models";
import { AccountsService } from "./accounts.service";
@Injectable()
export class StreamsService {
streamsSubject = new BehaviorSubject<Stream[]>([]);
constructor(
private readonly httpService: Http,
// private readonly accountsService: AccountsService
) {
// Return home/local/public of all accounts
// this.accountsService.accountsSubject
// .subscribe((accounts: LocalAccount[]) => {
// const streams: Stream[] = [];
// for (let acc of accounts) {
// const homeStream = new Stream(this.httpService, "Home", StreamTypeEnum.Home, acc);
// const localStream = new Stream(this.httpService, "Local", StreamTypeEnum.Local, acc);
// const publicStream = new Stream(this.httpService, "Public", StreamTypeEnum.Public, acc);
// streams.push(homeStream);
// streams.push(localStream);
// streams.push(publicStream);
// }
// this.streamsSubject.next(streams);
// });
}
//getStreams(): void {
// // Return home/local/public of all accounts
// this.accountsService.accountsSubject
// .map((accounts: LocalAccount[]) => {
// const streams: Stream[] = [];
// for (let acc of accounts) {
// const homeStream = new Stream(this.httpService, "Home", StreamTypeEnum.Home, acc);
// const localStream = new Stream(this.httpService, "Local", StreamTypeEnum.Local, acc);
// const publicStream = new Stream(this.httpService, "Public", StreamTypeEnum.Public, acc);
// streams.push(homeStream);
// streams.push(localStream);
// streams.push(publicStream);
// }
// this.streamsSubject.next(streams);
// });
}

View File

@ -26,12 +26,12 @@ export class ColumnsState {
}
export class ColumnElement {
constructor(public type: ColumnTypeEnum, public name: string, public username: string) {
constructor(public type: StreamTypeEnum, public name: string, public username: string) {
}
}
export enum ColumnTypeEnum {
export enum StreamTypeEnum {
unknown = 0,
global = 1,
local = 2,