From a8822aeffd258a2640115aece89a0a66234d7c92 Mon Sep 17 00:00:00 2001
From: merranleo
Date: Tue, 7 May 2024 22:37:00 +0200
Subject: [PATCH] feat(dojo): update realties refresh
---
.../src/app/assets/assets.component.html | 2 +-
.../dojo-front/src/app/assets/assets.component.ts | 15 ++++++++++-----
.../realties-section.component.html | 2 +-
.../realties-section.component.ts | 7 ++++++-
.../src/app/invest/invest.component.html | 3 ++-
.../dojo-front/src/app/invest/invest.component.ts | 4 ++++
.../realty-card/realty-card.component.ts | 13 ++++++-------
7 files changed, 30 insertions(+), 16 deletions(-)
diff --git a/dojo-front/dojo-front/src/app/assets/assets.component.html b/dojo-front/dojo-front/src/app/assets/assets.component.html
index 86a881e..644f14c 100644
--- a/dojo-front/dojo-front/src/app/assets/assets.component.html
+++ b/dojo-front/dojo-front/src/app/assets/assets.component.html
@@ -5,7 +5,7 @@ Vos appartements
diff --git a/dojo-front/dojo-front/src/app/assets/assets.component.ts b/dojo-front/dojo-front/src/app/assets/assets.component.ts
index bf810e6..d23e6b2 100644
--- a/dojo-front/dojo-front/src/app/assets/assets.component.ts
+++ b/dojo-front/dojo-front/src/app/assets/assets.component.ts
@@ -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';
@@ -10,20 +9,22 @@ import { UserService } from '../home/services/user.service';
styleUrls: ['./assets.component.scss'],
})
export class AssetsComponent implements OnInit {
- assets$!: Observable;
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,
@@ -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()
+ }
}
diff --git a/dojo-front/dojo-front/src/app/invest/components/realties-section/realties-section.component.html b/dojo-front/dojo-front/src/app/invest/components/realties-section/realties-section.component.html
index ddc069f..5c17b63 100644
--- a/dojo-front/dojo-front/src/app/invest/components/realties-section/realties-section.component.html
+++ b/dojo-front/dojo-front/src/app/invest/components/realties-section/realties-section.component.html
@@ -11,7 +11,7 @@
()
pageSize!: number;
currentPageIndex!: number;
@@ -24,4 +25,8 @@ export class RealtiesSectionComponent {
this.currentPageIndex = event.pageIndex;
this.pagedRealties = this.realties.slice(0, this.pageSize);
}
+
+ refreshRealties() {
+ this.realtiesUpdated.emit(true)
+ }
}
diff --git a/dojo-front/dojo-front/src/app/invest/invest.component.html b/dojo-front/dojo-front/src/app/invest/invest.component.html
index 04d3a36..0532bf4 100644
--- a/dojo-front/dojo-front/src/app/invest/invest.component.html
+++ b/dojo-front/dojo-front/src/app/invest/invest.component.html
@@ -6,7 +6,7 @@
Type de biens :
- Veuillez choisir un type de bien
diff --git a/dojo-front/dojo-front/src/app/invest/invest.component.ts b/dojo-front/dojo-front/src/app/invest/invest.component.ts
index fa0db15..1f40785 100644
--- a/dojo-front/dojo-front/src/app/invest/invest.component.ts
+++ b/dojo-front/dojo-front/src/app/invest/invest.component.ts
@@ -39,4 +39,8 @@ export class InvestComponent implements OnInit {
get type() {
return this.filtersForm.get('type');
}
+
+ refreshRealties() {
+ this.availableRealties$ = this.realtiesService.fetchRealties();
+ }
}
diff --git a/dojo-front/dojo-front/src/shared/component/realty-card/realty-card.component.ts b/dojo-front/dojo-front/src/shared/component/realty-card/realty-card.component.ts
index 26a258b..834ca93 100644
--- a/dojo-front/dojo-front/src/shared/component/realty-card/realty-card.component.ts
+++ b/dojo-front/dojo-front/src/shared/component/realty-card/realty-card.component.ts
@@ -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';
@@ -13,6 +13,9 @@ export class RealtyCardComponent {
@Input()
realty!: Realty;
+ @Output()
+ realtyUpdated = new EventEmitter()
+
constructor(
public router: Router,
private realtiesService: RealtiesService,
@@ -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();
- }
}