Skip to content

Commit

Permalink
feat(dojo): update realties refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
merranleo committed May 7, 2024
1 parent 88188c3 commit a8822ae
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 16 deletions.
2 changes: 1 addition & 1 deletion dojo-front/dojo-front/src/app/assets/assets.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ <h1 class="list-title">Vos appartements</h1>
</div>
<div class="assets__cards">
<div *ngFor="let apartment of apartments" class="assets__card">
<app-realty-card [realty]="apartment"></app-realty-card>
<app-realty-card [realty]="apartment" (realtyUpdated)="refreshRealties()"></app-realty-card>
</div>
</div>
</div>
Expand Down
15 changes: 10 additions & 5 deletions dojo-front/dojo-front/src/app/assets/assets.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Component, OnInit } from '@angular/core';
import { Observable, map, tap } from 'rxjs';
import { RealtiesService } from 'src/shared/services/realties.service';
import {map, take} from 'rxjs';
import { REALTY_TYPE, Realty } from '../../shared/interface/realty';
import { UserService } from '../home/services/user.service';

Expand All @@ -10,20 +9,22 @@ import { UserService } from '../home/services/user.service';
styleUrls: ['./assets.component.scss'],
})
export class AssetsComponent implements OnInit {
assets$!: Observable<Realty[]>;
apartments: Realty[] = [];
participatives: Realty[] = [];

constructor(
private realtiesService: RealtiesService,
private userService: UserService
) {}

ngOnInit() {
this.fetchRealties()
}

private fetchRealties(){
this.userService
.fetchUserRealties()
.pipe(map((assets) => assets.map((asset) => asset.realty)))
.pipe(tap(console.log))
.pipe(take(1))
.subscribe((realties) => {
this.apartments = this.filterRealtiesByType(
realties,
Expand All @@ -39,4 +40,8 @@ export class AssetsComponent implements OnInit {
private filterRealtiesByType(realties: Realty[], type: REALTY_TYPE) {
return realties.filter((realty) => realty.deedType === type);
}

refreshRealties() {
this.fetchRealties()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</p>
<div class="property-cards">
<div *ngFor="let realty of pagedRealties" class="property-cards__card">
<app-realty-card [realty]="realty"></app-realty-card>
<app-realty-card [realty]="realty" (realtyUpdated)="refreshRealties()"></app-realty-card>
</div>
</div>
<mat-paginator
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, Input} from '@angular/core';
import {Component, EventEmitter, Input, Output} from '@angular/core';
import {LegacyPageEvent as PageEvent} from '@angular/material/legacy-paginator';
import {Realty} from 'src/shared/interface/realty';

Expand All @@ -9,6 +9,7 @@ import {Realty} from 'src/shared/interface/realty';
})
export class RealtiesSectionComponent {
@Input() realties!: Realty[];
@Output() realtiesUpdated = new EventEmitter<boolean>()

pageSize!: number;
currentPageIndex!: number;
Expand All @@ -24,4 +25,8 @@ export class RealtiesSectionComponent {
this.currentPageIndex = event.pageIndex;
this.pagedRealties = this.realties.slice(0, this.pageSize);
}

refreshRealties() {
this.realtiesUpdated.emit(true)
}
}
3 changes: 2 additions & 1 deletion dojo-front/dojo-front/src/app/invest/invest.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<mat-form-field>
<mat-label>Type de biens :</mat-label>
<mat-select formControlName="type">
<mat-option value="" selected disabled
<mat-option
>Veuillez choisir un type de bien</mat-option
>
<mat-option [value]="REALTY_TYPE.APARTMENT"
Expand All @@ -24,5 +24,6 @@
<app-realties-section
*ngIf="availableRealties$ | async as availableRealties"
[realties]="availableRealties"
(realtiesUpdated)="refreshRealties()"
></app-realties-section>
</div>
4 changes: 4 additions & 0 deletions dojo-front/dojo-front/src/app/invest/invest.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ export class InvestComponent implements OnInit {
get type() {
return this.filtersForm.get('type');
}

refreshRealties() {
this.availableRealties$ = this.realtiesService.fetchRealties();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Input } from '@angular/core';
import {Component, EventEmitter, Input, Output} from '@angular/core';
import { Router } from '@angular/router';
import { AssetsService } from 'src/shared/services/assets.service';
import { RealtiesService } from 'src/shared/services/realties.service';
Expand All @@ -13,6 +13,9 @@ export class RealtyCardComponent {
@Input()
realty!: Realty;

@Output()
realtyUpdated = new EventEmitter<boolean>()

constructor(
public router: Router,
private realtiesService: RealtiesService,
Expand All @@ -21,17 +24,13 @@ export class RealtyCardComponent {

buyProperty() {
this.realtiesService.buyRealty(this.realty.id).subscribe((_) => {
this.refreshPage();
this.realtyUpdated.emit(true)
});
}

sellProperty() {
this.assetsService.sellRealty(this.realty.id).subscribe((_) => {
this.refreshPage();
this.realtyUpdated.emit(true)
});
}

private refreshPage() {
window.location.reload();
}
}

0 comments on commit a8822ae

Please sign in to comment.