From 7ac92b283d8a87fbbd55813c56359257c4035133 Mon Sep 17 00:00:00 2001 From: Weronika Olejniczak Date: Sun, 26 May 2024 21:44:51 +0200 Subject: [PATCH] refactor(mobile): update PointOfInterest model to factory function --- .../domains/map/containers/MapContainer.tsx | 18 +++++------ apps/mobile/src/models/PointOfInterest.ts | 30 +++++++++++++------ 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/apps/mobile/src/domains/map/containers/MapContainer.tsx b/apps/mobile/src/domains/map/containers/MapContainer.tsx index 802485be..35bd477f 100644 --- a/apps/mobile/src/domains/map/containers/MapContainer.tsx +++ b/apps/mobile/src/domains/map/containers/MapContainer.tsx @@ -6,7 +6,7 @@ import { View } from 'react-native'; import { useDispatch, useSelector } from 'react-redux'; import { patchMapRequest } from 'actions/mapActions'; -import PointOfInterest from 'models/PointOfInterest'; +import PointOfInterestModel from 'models/PointOfInterest'; import fetchMapSearch from 'services/fetchMapSearch'; import { Toolbar } from '../components'; import { styles } from './MapContainerStyle'; @@ -151,22 +151,22 @@ const MapContainer = ({ route, navigation }) => { markers ? [ ...markers, - new PointOfInterest( - new Date().getTime().toString(), - new Date().toString(), + PointOfInterestModel({ + id: new Date().getTime().toString(), + key: new Date().toString(), latitude, longitude, title, - ), + }), ] : [ - new PointOfInterest( - new Date().getTime().toString(), - new Date().toString(), + PointOfInterestModel({ + id: new Date().getTime().toString(), + key: new Date().toString(), latitude, longitude, title, - ), + }), ], ); }; diff --git a/apps/mobile/src/models/PointOfInterest.ts b/apps/mobile/src/models/PointOfInterest.ts index cfeb00eb..6634e6ea 100644 --- a/apps/mobile/src/models/PointOfInterest.ts +++ b/apps/mobile/src/models/PointOfInterest.ts @@ -1,11 +1,23 @@ -class PointOfInterest { - constructor(key, id, lat, lon, title) { - this.key = key; - this.id = id; - this.lat = lat; - this.lon = lon; - this.title = title; - } +interface PointOfInterestModelParams { + id: string; + key: string; + latitude: number; + longitude: number; + title: string; } -export default PointOfInterest; +const PointOfInterestModel = ({ + id, + key, + latitude, + longitude, + title, +}: PointOfInterestModelParams) => ({ + id, + key, + latitude, + longitude, + title, +}); + +export default PointOfInterestModel;