Browse Source

feat(client): add watchlist components

pull/4604/head
KenTandrian 4 months ago
parent
commit
cc0dbff7e7
  1. 57
      apps/client/src/app/components/home-watchlist/home-watchlist.component.ts
  2. 24
      apps/client/src/app/components/home-watchlist/home-watchlist.html
  3. 16
      apps/client/src/app/components/home-watchlist/home-watchlist.module.ts
  4. 3
      apps/client/src/app/components/home-watchlist/home-watchlist.scss

57
apps/client/src/app/components/home-watchlist/home-watchlist.component.ts

@ -0,0 +1,57 @@
import { DataService } from '@ghostfolio/client/services/data.service';
import { UserService } from '@ghostfolio/client/services/user/user.service';
import { AssetProfileIdentifier, User } from '@ghostfolio/common/interfaces';
import { ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core';
import { DeviceDetectorService } from 'ngx-device-detector';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
@Component({
selector: 'gf-home-watchlist',
styleUrls: ['./home-watchlist.scss'],
templateUrl: './home-watchlist.html',
standalone: false
})
export class HomeWatchlistComponent implements OnDestroy, OnInit {
public watchlist: AssetProfileIdentifier[];
public deviceType: string;
public user: User;
private unsubscribeSubject = new Subject<void>();
public constructor(
private changeDetectorRef: ChangeDetectorRef,
private dataService: DataService,
private deviceService: DeviceDetectorService,
private userService: UserService
) {
this.deviceType = this.deviceService.getDeviceInfo().deviceType;
this.userService.stateChanged
.pipe(takeUntil(this.unsubscribeSubject))
.subscribe((state) => {
if (state?.user) {
this.user = state.user;
this.changeDetectorRef.markForCheck();
}
});
}
public ngOnInit() {
this.dataService
.fetchWatchlist()
.pipe(takeUntil(this.unsubscribeSubject))
.subscribe((watchlist) => {
this.watchlist = watchlist;
this.changeDetectorRef.markForCheck();
});
}
public ngOnDestroy() {
this.unsubscribeSubject.next();
this.unsubscribeSubject.complete();
}
}

24
apps/client/src/app/components/home-watchlist/home-watchlist.html

@ -0,0 +1,24 @@
<div class="container">
<h1 class="d-none d-sm-block h3 mb-4 text-center" i18n>Watchlist</h1>
<div class="mb-3 row">
<div class="col-xs-12 col-md-8 offset-md-2">
<gf-benchmark
[benchmarks]="watchlist"
[deviceType]="deviceType"
[locale]="user?.settings?.locale || undefined"
[user]="user"
/>
</div>
</div>
</div>
<div class="fab-container">
<a
class="align-items-center d-flex justify-content-center"
color="primary"
mat-fab
[queryParams]="{ createDialog: true }"
[routerLink]="[]"
>
<ion-icon name="add-outline" size="large" />
</a>
</div>

16
apps/client/src/app/components/home-watchlist/home-watchlist.module.ts

@ -0,0 +1,16 @@
import { GfBenchmarkComponent } from '@ghostfolio/ui/benchmark';
import { CommonModule } from '@angular/common';
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { RouterModule } from '@angular/router';
import { HomeWatchlistComponent } from './home-watchlist.component';
@NgModule({
declarations: [HomeWatchlistComponent],
exports: [HomeWatchlistComponent],
imports: [CommonModule, GfBenchmarkComponent, MatButtonModule, RouterModule],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class GfHomeWatchlistModule {}

3
apps/client/src/app/components/home-watchlist/home-watchlist.scss

@ -0,0 +1,3 @@
:host {
display: block;
}
Loading…
Cancel
Save