Skip to content

Commit

Permalink
feat: only allow multiple vineyards for premium users
Browse files Browse the repository at this point in the history
  • Loading branch information
JanssenBrm committed Jan 28, 2024
1 parent bc4f7f9 commit 0d4d610
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/app/premium/config/features.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { ProductInfo } from '../premium.model';
import { environment } from '../../../environments/environment';

const BASIC_FEATURES = [
'Create multiple vineyards',
'Create a single vineyard',
'Register the actions on your vineyard',
'Access basic statistics',
'Create notes',
];

const PREMIUM_FEATURES = [
'Add multiple vineyards',
'Features of the basic user',
'Get weather statistics and frost warnings',
'Compare growing seasons',
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/components/toolbar/toolbar.component.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="toolbar">
<ion-button (click)="showLayersMenu($event)"><ion-icon slot="start" name="map-outline"></ion-icon>Layers</ion-button>
<ion-button *ngIf="mapMode === undefined" (click)="setMapMode(mapModes.Edit)"><ion-icon name="pencil-outline"></ion-icon></ion-button>
<ion-button *ngIf="mapMode === undefined" (click)="setMapMode(mapModes.Add)"><ion-icon name="add-outline"></ion-icon></ion-button>
<ion-button *ngIf="allowAdd() | async" (click)="setMapMode(mapModes.Add)"><ion-icon name="add-outline"></ion-icon></ion-button>
<ion-button *ngIf="mapMode === undefined" (click)="setMapMode(mapModes.Remove)"><ion-icon name="trash-outline"></ion-icon></ion-button>
<ion-button color="primary" *ngIf="dirty && mapMode !== undefined" (click)="save()"><ion-icon slot="start" name="save-outline"></ion-icon> Save</ion-button>
<ion-button color="light" *ngIf="mapMode !== undefined" (click)="discard()">Cancel</ion-button>
Expand Down
21 changes: 19 additions & 2 deletions src/app/shared/components/toolbar/toolbar.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { MapMode } from './../../../models/mapmode.model';
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { PopoverController } from '@ionic/angular';
import { LayersComponent } from './layers/layers.component';
import { BACKGROUND_LAYERS } from '../../../conf/layers.config';
import { Layer } from '../../../models/layer.model';
import { OverlayEventDetail } from '@ionic/core';
import { FeaturesService } from '../../../services/features.service';
import { map } from 'rxjs/operators';
import { VineyardService } from '../../../services/vineyard.service';
import { combineLatest } from 'rxjs';
import { Vineyard } from '../../../models/vineyard.model';

@Component({
selector: 'app-toolbar',
Expand All @@ -31,7 +36,11 @@ export class ToolbarComponent {

public layers: Layer[] = [...BACKGROUND_LAYERS];

constructor(private popoverController: PopoverController) {}
constructor(
private popoverController: PopoverController,
private featureService: FeaturesService,
private vineyardService: VineyardService
) {}

save(): void {
this.updateState.emit(true);
Expand Down Expand Up @@ -63,4 +72,12 @@ export class ToolbarComponent {
});
return popover.present();
}

allowAdd() {
return combineLatest(this.vineyardService.getVineyardsListener(), this.featureService.isUserPremium()).pipe(
map(([vineyards, isPremium]: [Vineyard[], boolean]) => {
return this.mapMode === undefined && (isPremium || (!isPremium && vineyards.length === 0));
})
);
}
}

0 comments on commit 0d4d610

Please sign in to comment.