Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove @Select selector from ngxs due to deperaction #2010

Merged
merged 30 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
07f19a8
Main commit to remove all select decorators from the code.
HarelM Jun 12, 2024
9b48b01
Use more async, add pipe for destroy.
HarelM Jun 13, 2024
bb27199
Use more async in layers properties dialog
HarelM Jun 13, 2024
eb7944b
More fixes with async in html
HarelM Jun 13, 2024
d58171b
add takeuntildestroied to traces
HarelM Jun 13, 2024
372f1af
Move drawing to use async pipe
HarelM Jun 13, 2024
7aa0284
Remove unneded field, add takeuntildestroied.
HarelM Jun 13, 2024
ed3967c
Improve takeuntildestory logic.
HarelM Jun 13, 2024
9ed6904
Add takeuntildestroied
HarelM Jun 13, 2024
257b98a
add takeuntildestory for layers view
HarelM Jun 13, 2024
bee7c26
reduce changes
HarelM Jun 13, 2024
00d74bf
Add more takeuntildestried
HarelM Jun 13, 2024
cc90adc
Move initialization to constructor.
HarelM Jun 13, 2024
a362e34
Use async more
HarelM Jun 13, 2024
89c8e4d
Add takeuntildestoyed
HarelM Jun 13, 2024
25196ea
Add takeuntildestroyed
HarelM Jun 13, 2024
c216bd6
make distance async
HarelM Jun 13, 2024
d391030
Less changes
HarelM Jun 13, 2024
5b2ce08
Add takeuntildestroyed
HarelM Jun 13, 2024
8a0480e
Move import up
HarelM Jun 13, 2024
b22658a
Add pipe
HarelM Jun 13, 2024
55dd818
add missing space
HarelM Jun 13, 2024
492ceb8
add takeuntildestryed
HarelM Jun 13, 2024
0e612dc
move back to async
HarelM Jun 13, 2024
043422d
Fix html
HarelM Jun 13, 2024
48d9a8b
Add async
HarelM Jun 13, 2024
f45dde8
Fix lint
HarelM Jun 13, 2024
82496fc
Add missing destory ref
HarelM Jun 13, 2024
4565818
Merge branch 'main' into remove-ngx-select-decorator
HarelM Jun 13, 2024
c5d91cb
Fix automatic layer presentation unsubscribe issue.
HarelM Jun 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
import { Component, OnInit, OnDestroy } from "@angular/core";

import { Component, DestroyRef, OnInit } from "@angular/core";
import { Router, ActivatedRoute } from "@angular/router";
import { Subscription } from "rxjs";
import { Store } from "@ngxs/store";

import { RouteStrings } from "../services/hash.service";
import { SidebarService } from "../services/sidebar.service";
import { DataContainerService } from "../services/data-container.service";
import { FitBoundsService } from "../services/fit-bounds.service";
import { SetFileUrlAndBaseLayerAction, SetShareUrlAction } from "../reducers/in-memory.reducer";
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";

@Component({
selector: "application-state",
template: "<div></div>"
})
export class ApplicationStateComponent implements OnInit, OnDestroy {

private subscription: Subscription;

export class ApplicationStateComponent implements OnInit {
constructor(private readonly router: Router,
private readonly route: ActivatedRoute,
private readonly sidebarService: SidebarService,
private readonly dataContainerService: DataContainerService,
private readonly fitBoundsService: FitBoundsService,
private readonly store: Store) {
this.subscription = null;
private readonly store: Store,
private readonly destroyRef: DestroyRef) {
}

public ngOnInit() {
this.subscription = this.route.params.subscribe(params => {
this.route.params.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(params => {
if (this.router.url.startsWith(RouteStrings.ROUTE_MAP)) {
this.fitBoundsService.flyTo({
lng: +params[RouteStrings.LON],
Expand All @@ -46,10 +42,4 @@ export class ApplicationStateComponent implements OnInit, OnDestroy {
}
});
}

public ngOnDestroy() {
if (this.subscription) {
this.subscription.unsubscribe();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Component } from "@angular/core";
import { Observable } from "rxjs";
import { Store, Select } from "@ngxs/store";
import type { Immutable } from "immer";
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
import { Store } from "@ngxs/store";

import { BaseMapComponent } from "./base-map.component";
import { ResourcesService } from "../services/resources.service";
import type { ApplicationState, Language } from "../models/models";
import type { ApplicationState } from "../models/models";

@Component({
selector: "background-text",
Expand All @@ -14,25 +13,16 @@ import type { ApplicationState, Language } from "../models/models";
})
export class BackgroundTextComponent extends BaseMapComponent {

@Select((state: ApplicationState) => state.offlineState.isOfflineAvailable)
public isOfflineAvailable$: Observable<boolean>;

@Select((state: ApplicationState) => state.offlineState.lastModifiedDate)
public lastModifiedDate$: Observable<boolean>;

@Select((state: ApplicationState) => state.configuration.language)
public language$: Observable<Immutable<Language>>;

public text: string;

constructor(resources: ResourcesService,
private readonly store: Store) {
super(resources);

this.text = "";
this.isOfflineAvailable$.subscribe(() => this.updateText());
this.lastModifiedDate$.subscribe(() => this.updateText());
this.language$.subscribe(() => this.updateText());
this.store.select((state: ApplicationState) => state.offlineState.isOfflineAvailable).pipe(takeUntilDestroyed()).subscribe(() => this.updateText());
this.store.select((state: ApplicationState) => state.offlineState.lastModifiedDate).pipe(takeUntilDestroyed()).subscribe(() => this.updateText());
this.store.select((state: ApplicationState) => state.configuration.language).pipe(takeUntilDestroyed()).subscribe(() => this.updateText());
}

private updateText() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="flex flex-row" *ngIf="isApp()">
<div class="flex-1">
<label id="example-radio-group-label">{{resources.batteryOptimization}}</label>
<mat-radio-group (change)=setBatteryOptimizationType($event.value) [value]="batteryOptimizationType | async">
<mat-radio-group (change)=setBatteryOptimizationType($event.value) [value]="batteryOptimizationType$ | async">
<div>
<mat-radio-button value="screen-on" color="primary" angulartics2On="click" angularticsCategory="Intro" angularticsAction="Set battery optimization on">{{resources.screenOn}}</mat-radio-button>
</div>
Expand All @@ -24,14 +24,14 @@
</div>
<div class="flex flex-row" *ngIf="isApp()">
<div class="flex-1">
<mat-checkbox [checked]="isAutomaticRecordingUpload | async" (change)="toggleAutomaticRecordingUpload()" color="primary" angulartics2On="click" angularticsCategory="Configuration" angularticsAction="Toggle automatic upload">{{resources.automaticRecordingUpload}}</mat-checkbox>
<mat-checkbox [checked]="isAutomaticRecordingUpload$ | async" (change)="toggleAutomaticRecordingUpload()" color="primary" angulartics2On="click" angularticsCategory="Configuration" angularticsAction="Toggle automatic upload">{{resources.automaticRecordingUpload}}</mat-checkbox>
<br />
<span class="text-sm">{{resources.automaticRecordingUploadHint}}</span>
</div>
</div>
<div class="flex flex-row" *ngIf="isApp()">
<div class="flex-1">
<mat-checkbox [checked]="isGotLostWarnings | async" (change)="toggleGotLostWarnings()" color="primary" angulartics2On="click" angularticsCategory="Configuration" angularticsAction="Toggle got lost warnings">{{resources.gotLostWarnings}}</mat-checkbox>
<mat-checkbox [checked]="isGotLostWarnings$ | async" (change)="toggleGotLostWarnings()" color="primary" angulartics2On="click" angularticsCategory="Configuration" angularticsAction="Toggle got lost warnings">{{resources.gotLostWarnings}}</mat-checkbox>
<br />
<span class="text-sm">{{resources.gotLostWarningsHint}}</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component } from "@angular/core";
import { MatDialogRef } from "@angular/material/dialog";
import { Observable } from "rxjs";
import { Store, Select } from "@ngxs/store";
import { Store } from "@ngxs/store";

import { BaseMapComponent } from "../base-map.component";
import { ResourcesService } from "../../services/resources.service";
Expand All @@ -22,14 +22,9 @@ import type { ApplicationState, BatteryOptimizationType } from "../../models/mod
})
export class ConfigurationDialogComponent extends BaseMapComponent {

@Select((state: ApplicationState) => state.configuration.batteryOptimizationType)
public batteryOptimizationType: Observable<BatteryOptimizationType>;

@Select((state: ApplicationState) => state.configuration.isAutomaticRecordingUpload)
public isAutomaticRecordingUpload: Observable<boolean>;

@Select((state: ApplicationState) => state.configuration.isGotLostWarnings)
public isGotLostWarnings: Observable<boolean>;
public batteryOptimizationType$: Observable<BatteryOptimizationType>;
public isAutomaticRecordingUpload$: Observable<boolean>;
public isGotLostWarnings$: Observable<boolean>;

constructor(resources: ResourcesService,
private readonly dialogRef: MatDialogRef<ConfigurationDialogComponent>,
Expand All @@ -38,6 +33,9 @@ export class ConfigurationDialogComponent extends BaseMapComponent {
private readonly logginService: LoggingService,
private readonly store: Store) {
super(resources);
this.batteryOptimizationType$ = this.store.select((state: ApplicationState) => state.configuration.batteryOptimizationType);
this.isAutomaticRecordingUpload$ = this.store.select((state: ApplicationState) => state.configuration.isAutomaticRecordingUpload);
this.isGotLostWarnings$ = this.store.select((state: ApplicationState) => state.configuration.isGotLostWarnings);
}

public isApp() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component } from "@angular/core";
import { HttpClient } from "@angular/common/http";
import { Store } from "@ngxs/store";

import { LayerBaseDialogComponent } from "./layer-base-dialog.component";
import { ResourcesService } from "../../../services/resources.service";
Expand All @@ -17,9 +18,9 @@ export class BaseLayerAddDialogComponent extends LayerBaseDialogComponent {
layersService: LayersService,
mapService: MapService,
toastService: ToastService,
http: HttpClient
) {
super(resources, mapService, layersService, toastService, http);
http: HttpClient,
store: Store) {
super(resources, mapService, layersService, toastService, http, store);
this.title = this.resources.addBaseLayer;
this.isNew = true;
this.isOverlay = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component } from "@angular/core";
import { HttpClient } from "@angular/common/http";
import { Store } from "@ngxs/store";

import { ResourcesService } from "../../../services/resources.service";
import { MapService } from "../../../services/map.service";
Expand All @@ -19,8 +20,9 @@ export class BaseLayerEditDialogComponent extends LayerBaseDialogComponent {
mapService: MapService,
layersService: LayersService,
toastService: ToastService,
http: HttpClient) {
super(resources, mapService, layersService, toastService, http);
http: HttpClient,
store: Store) {
super(resources, mapService, layersService, toastService, http, store);
this.title = this.resources.baseLayerProperties;
this.isNew = false;
this.isOverlay = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HttpClient } from "@angular/common/http";
import { firstValueFrom, Observable } from "rxjs";
import { Select } from "@ngxs/store";
import { Observable, firstValueFrom } from "rxjs";
import { Store } from "@ngxs/store";

import { BaseMapComponent } from "../../base-map.component";
import { ResourcesService } from "../../../services/resources.service";
Expand All @@ -14,18 +14,15 @@ export abstract class LayerBaseDialogComponent extends BaseMapComponent {
public title: string;
public isNew: boolean;
public isOverlay: boolean;

public layerData: EditableLayer;

@Select((state: ApplicationState) => state.locationState)
public location: Observable<Immutable<LocationState>>;
public location$: Observable<Immutable<LocationState>>;

protected constructor(resources: ResourcesService,
protected readonly mapService: MapService,
protected readonly layersService: LayersService,
protected readonly toastService: ToastService,
private readonly http: HttpClient
) {
private readonly http: HttpClient,
private readonly store: Store) {
super(resources);
this.layerData = {
minZoom: LayersService.MIN_ZOOM,
Expand All @@ -37,6 +34,8 @@ export abstract class LayerBaseDialogComponent extends BaseMapComponent {
isOfflineAvailable: false,
isOfflineOn: true
} as EditableLayer;

this.location$ = this.store.select((state: ApplicationState) => state.locationState);
}

public onAddressChanged(address: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<div class="flex flex-row">
<div class="w-full" style="height: 138px">
<mgl-map [zoom]="[(layerData.minZoom + layerData.maxZoom) / 2]"
[center]="[(location | async)?.longitude, (location | async)?.latitude]"
[center]="[(location$ | async)?.longitude, (location$ | async)?.latitude]"
[style]='{"version": 8, "sources": {}, "layers": [] }'
[attributionControl]="false">
<auto-layer [layerData]="layerData"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component } from "@angular/core";
import { HttpClient } from "@angular/common/http";
import { Store } from "@ngxs/store";

import { ResourcesService } from "../../../services/resources.service";
import { MapService } from "../../../services/map.service";
Expand All @@ -18,8 +19,9 @@ export class OverlayAddDialogComponent extends LayerBaseDialogComponent {
mapService: MapService,
layersService: LayersService,
toastService: ToastService,
http: HttpClient) {
super(resources, mapService, layersService, toastService, http);
http: HttpClient,
store: Store) {
super(resources, mapService, layersService, toastService, http, store);
this.title = this.resources.addOverlay;
this.isNew = true;
this.isOverlay = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component } from "@angular/core";
import { HttpClient } from "@angular/common/http";
import { Store } from "@ngxs/store";
import type { Immutable } from "immer";

import { ResourcesService } from "../../../services/resources.service";
Expand All @@ -21,8 +22,9 @@ export class OverlayEditDialogComponent extends LayerBaseDialogComponent {
mapService: MapService,
layersService: LayersService,
toastService: ToastService,
http: HttpClient) {
super(resources, mapService, layersService, toastService, http);
http: HttpClient,
store: Store) {
super(resources, mapService, layersService, toastService, http, store);
this.title = this.resources.overlayProperties;
this.isNew = false;
this.isOverlay = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Component, OnInit, ViewEncapsulation, OnDestroy } from "@angular/core";
import { Component, OnInit, ViewEncapsulation } from "@angular/core";
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
import { MatDialog } from "@angular/material/dialog";
import { FormControl } from "@angular/forms";
import { SocialSharing } from "@awesome-cordova-plugins/social-sharing/ngx";
import { take, orderBy } from "lodash-es";
import { Observable, Subscription } from "rxjs";
import { Store, Select } from "@ngxs/store";
import { Observable } from "rxjs";
import { Store } from "@ngxs/store";
import type { Immutable } from "immer";

import { BaseMapComponent } from "../base-map.component";
Expand All @@ -23,23 +24,17 @@ import type { ApplicationState, ShareUrl } from "../../models/models";
styleUrls: ["shares-dialog.component.scss"],
encapsulation: ViewEncapsulation.None
})
export class SharesDialogComponent extends BaseMapComponent implements OnInit, OnDestroy {
export class SharesDialogComponent extends BaseMapComponent implements OnInit {

public filteredShareUrls: Immutable<ShareUrl[]>;
public shareUrlInEditMode: ShareUrl;
public selectedShareUrlId: string;
public loadingShareUrls: boolean;
public searchTerm: FormControl<string>;

@Select((state: ApplicationState) => state.shareUrlsState.shareUrls)
public shareUrls$: Observable<Immutable<ShareUrl[]>>;

@Select((state: ApplicationState) => state.inMemoryState.shareUrl)
public shownShareUrl$: Observable<Immutable<ShareUrl>>;

private sessionSearchTerm = "";
private page: number;
private subscriptions: Subscription[];

constructor(resources: ResourcesService,
private readonly dialog: MatDialog,
Expand All @@ -56,17 +51,17 @@ export class SharesDialogComponent extends BaseMapComponent implements OnInit, O
this.shareUrlInEditMode = null;
this.selectedShareUrlId = null;
this.page = 1;
this.subscriptions = [];
this.searchTerm = new FormControl<string>("");
this.subscriptions.push(this.searchTerm.valueChanges.subscribe((searchTerm: string) => {
this.searchTerm.valueChanges.pipe(takeUntilDestroyed()).subscribe((searchTerm: string) => {
this.updateFilteredLists(searchTerm);
}));
});
this.searchTerm.setValue(this.sessionSearchTerm);
this.subscriptions.push(this.shareUrls$.subscribe(() => {
this.store.select((state: ApplicationState) => state.shareUrlsState.shareUrls).pipe(takeUntilDestroyed()).subscribe(() => {
if (!this.loadingShareUrls) {
this.updateFilteredLists(this.searchTerm.value);
}
}));
});
this.shownShareUrl$ = this.store.select((state: ApplicationState) => state.inMemoryState.shareUrl).pipe(takeUntilDestroyed());
}

public async ngOnInit() {
Expand All @@ -76,12 +71,6 @@ export class SharesDialogComponent extends BaseMapComponent implements OnInit, O
this.updateFilteredLists(this.searchTerm.value);
}

public ngOnDestroy() {
for (const subscription of this.subscriptions) {
subscription.unsubscribe();
}
}

public isApp(): boolean {
return this.runningContextService.isCapacitor;
}
Expand Down
Loading