mirror of https://github.com/ghostfolio/ghostfolio
11 changed files with 131 additions and 222 deletions
@ -1,80 +0,0 @@ |
|||
import { GfFearAndGreedIndexComponent } from '@ghostfolio/client/components/fear-and-greed-index/fear-and-greed-index.component'; |
|||
import { UserService } from '@ghostfolio/client/services/user/user.service'; |
|||
import { Benchmark, InfoItem, User } from '@ghostfolio/common/interfaces'; |
|||
import { hasPermission, permissions } from '@ghostfolio/common/permissions'; |
|||
import { GfBenchmarkComponent } from '@ghostfolio/ui/benchmark'; |
|||
import { DataService } from '@ghostfolio/ui/services'; |
|||
|
|||
import { |
|||
ChangeDetectionStrategy, |
|||
ChangeDetectorRef, |
|||
Component, |
|||
computed, |
|||
CUSTOM_ELEMENTS_SCHEMA, |
|||
DestroyRef, |
|||
inject, |
|||
OnInit, |
|||
signal |
|||
} from '@angular/core'; |
|||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; |
|||
import { DeviceDetectorService } from 'ngx-device-detector'; |
|||
|
|||
@Component({ |
|||
changeDetection: ChangeDetectionStrategy.OnPush, |
|||
imports: [GfBenchmarkComponent, GfFearAndGreedIndexComponent], |
|||
schemas: [CUSTOM_ELEMENTS_SCHEMA], |
|||
selector: 'gf-home-market', |
|||
styleUrls: ['./home-market.scss'], |
|||
templateUrl: './home-market.html' |
|||
}) |
|||
export class GfHomeMarketComponent implements OnInit { |
|||
protected readonly benchmarks = signal<Benchmark[]>([]); |
|||
|
|||
protected readonly deviceType = computed( |
|||
() => this.deviceDetectorService.deviceInfo().deviceType |
|||
); |
|||
|
|||
protected fearAndGreedIndex: number | undefined; |
|||
protected hasPermissionToAccessFearAndGreedIndex: boolean; |
|||
protected user: User; |
|||
|
|||
private readonly info: InfoItem; |
|||
|
|||
private readonly changeDetectorRef = inject(ChangeDetectorRef); |
|||
private readonly dataService = inject(DataService); |
|||
private readonly destroyRef = inject(DestroyRef); |
|||
private readonly deviceDetectorService = inject(DeviceDetectorService); |
|||
private readonly userService = inject(UserService); |
|||
|
|||
public constructor() { |
|||
this.info = this.dataService.fetchInfo(); |
|||
|
|||
this.userService.stateChanged |
|||
.pipe(takeUntilDestroyed(this.destroyRef)) |
|||
.subscribe((state) => { |
|||
if (state?.user) { |
|||
this.user = state.user; |
|||
|
|||
this.changeDetectorRef.markForCheck(); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
public ngOnInit() { |
|||
this.hasPermissionToAccessFearAndGreedIndex = hasPermission( |
|||
this.info?.globalPermissions, |
|||
permissions.enableFearAndGreedIndex |
|||
); |
|||
|
|||
if (this.hasPermissionToAccessFearAndGreedIndex) { |
|||
this.fearAndGreedIndex = this.info.fearAndGreedStocksMarketPrice; |
|||
} |
|||
|
|||
this.dataService |
|||
.fetchBenchmarks() |
|||
.pipe(takeUntilDestroyed(this.destroyRef)) |
|||
.subscribe(({ benchmarks }) => { |
|||
this.benchmarks.set(benchmarks); |
|||
}); |
|||
} |
|||
} |
|||
@ -1,35 +0,0 @@ |
|||
<div class="container"> |
|||
<h1 class="d-none d-sm-block h3 mb-4 text-center" i18n>Markets</h1> |
|||
@if (hasPermissionToAccessFearAndGreedIndex) { |
|||
<div class="mb-4 row"> |
|||
<div class="col-xs-12 col-md-10 offset-md-1"> |
|||
<gf-fear-and-greed-index |
|||
class="d-flex justify-content-center" |
|||
[fearAndGreedIndex]="fearAndGreedIndex" |
|||
/> |
|||
</div> |
|||
</div> |
|||
} |
|||
|
|||
<div class="mb-3 row"> |
|||
<div class="col-xs-12 col-md-10 offset-md-1"> |
|||
<gf-benchmark |
|||
[benchmarks]="benchmarks()" |
|||
[deviceType]="deviceType()" |
|||
[locale]="user?.settings?.locale || undefined" |
|||
[showSymbol]="false" |
|||
[user]="user" |
|||
/> |
|||
@if (benchmarks()?.length > 0) { |
|||
<div |
|||
class="gf-text-wrap-balance line-height-1 mt-3 text-center text-muted" |
|||
> |
|||
<small i18n> |
|||
Calculations are based on delayed market data and may not be |
|||
displayed in real-time.</small |
|||
> |
|||
</div> |
|||
} |
|||
</div> |
|||
</div> |
|||
</div> |
|||
@ -1,3 +0,0 @@ |
|||
:host { |
|||
display: block; |
|||
} |
|||
@ -1,7 +1,7 @@ |
|||
<div class="container"> |
|||
<div class="row"> |
|||
<div class="col"> |
|||
<gf-home-market /> |
|||
<gf-markets /> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
|
|||
Loading…
Reference in new issue