From 41fe7a3c6152b449a3a4f1ff1821aecb50fd5995 Mon Sep 17 00:00:00 2001 From: gabrielomndb1 Date: Tue, 24 Nov 2020 23:31:28 -0300 Subject: [PATCH] fit to new problem schema --- src/@types/problems.ts | 7 ++++--- src/pages/Dashboard/Map/Marker/index.tsx | 14 ++++++++------ src/pages/Dashboard/Map/Marker/styles.tsx | 19 +++++++++---------- src/pages/Dashboard/Map/index.tsx | 14 +++++--------- src/pages/Dashboard/SingleProblem/index.tsx | 15 +++++++-------- 5 files changed, 33 insertions(+), 36 deletions(-) diff --git a/src/@types/problems.ts b/src/@types/problems.ts index 5208be0..304cdfb 100644 --- a/src/@types/problems.ts +++ b/src/@types/problems.ts @@ -5,7 +5,8 @@ export interface IProblem { sector: string; author: string; status: string; - image: string; + userImages: string[]; + adminImages: string[]; description: string; comments: IComment[]; location: ILocation; @@ -23,6 +24,6 @@ interface ILocation { city?: string; state?: string; district?: string; - lat: number; - lg: number; + latitude: number; + longitude: number; } diff --git a/src/pages/Dashboard/Map/Marker/index.tsx b/src/pages/Dashboard/Map/Marker/index.tsx index f5c876e..9a9b76a 100644 --- a/src/pages/Dashboard/Map/Marker/index.tsx +++ b/src/pages/Dashboard/Map/Marker/index.tsx @@ -21,7 +21,7 @@ const defaultOptions = { iconSize: new L.Point(50, 55), iconAnchor: new L.Point(25, 55), shadowUrl: iconShadow -} +}; const SafetyIcon = new L.Icon({ iconUrl: safety, @@ -47,6 +47,7 @@ const InfraestrutureIcon = new L.Icon({ iconUrl: infraestruture, ...defaultOptions }); + const OtherIcon = new L.Icon({ iconUrl: other, ...defaultOptions @@ -56,6 +57,7 @@ const SewerIcon = new L.Icon({ iconUrl: sewer, ...defaultOptions }); + const EducationIcon = new L.Icon({ iconUrl: education, ...defaultOptions @@ -72,14 +74,14 @@ const markerIcons: Record = { energy: EnergyIcon }; -const CustomMarker: React.FC = ({ problem, children }) => { - if(!problem.location.lat || !problem.location.lg) problem.location = { lat: -7.21667, lg: -35.908813} - const { lat, lg } = problem.location; +const CustomMarker: React.FC = ({ problem }) => { + const { latitude, longitude } = problem.location; + return (

{problem.title}

diff --git a/src/pages/Dashboard/Map/Marker/styles.tsx b/src/pages/Dashboard/Map/Marker/styles.tsx index 0cd06e9..6cff30a 100644 --- a/src/pages/Dashboard/Map/Marker/styles.tsx +++ b/src/pages/Dashboard/Map/Marker/styles.tsx @@ -1,15 +1,14 @@ -import styled from 'styled-components' +import styled from 'styled-components'; import { Popup } from 'react-leaflet'; export const StyledPopup = styled(Popup)` - .leaflet-popup-content{ - height: 50px; - width: 200px; - padding: 10px; - text-align: center; - h3{ - margin-bottom: 10px; - } + .leaflet-popup-content { + height: 50px; + width: 200px; + padding: 10px; + text-align: center; + h3 { + margin-bottom: 10px; } - + } ` \ No newline at end of file diff --git a/src/pages/Dashboard/Map/index.tsx b/src/pages/Dashboard/Map/index.tsx index 8971e41..b3bc070 100644 --- a/src/pages/Dashboard/Map/index.tsx +++ b/src/pages/Dashboard/Map/index.tsx @@ -10,14 +10,12 @@ import { api } from '../../../service/api'; const DefaultCenter = L.latLng(-7.2171368, -35.911943); const Map = () => { - const [problems, setProblem] = useState([]) + const [problems, setProblem] = useState([]); useEffect(() => { - api - .listProblems() - .then((res) => { - setProblem(res) - }) - }, []) + api.listProblems().then((res) => { + setProblem(res); + }); + }, []); return ( @@ -30,9 +28,7 @@ const Map = () => { url='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png' attribution='© OpenStreetMap contributors' /> - {problems.map((problem) => { - return ( ); diff --git a/src/pages/Dashboard/SingleProblem/index.tsx b/src/pages/Dashboard/SingleProblem/index.tsx index 227e7e7..8a82208 100644 --- a/src/pages/Dashboard/SingleProblem/index.tsx +++ b/src/pages/Dashboard/SingleProblem/index.tsx @@ -28,15 +28,12 @@ const SingleProblem: React.FC = () => { author: '', status: '', comments: [], - image: '', + adminImages: [], + userImages: [], description: '', location: { - address: '', - city: '', - state: '', - district: '', - lat: 0, - lg: 0 + latitude: 0, + longitude: 0 } }) const [comment, setComment] = useState('') @@ -101,7 +98,9 @@ const SingleProblem: React.FC = () => {

Imagens adicionadas pelo cidadão

- imagem + {problem.userImages.map((image, index) => ( + problem + ))}