Skip to content

Commit

Permalink
Removing alerts from state on disconnect (#25)
Browse files Browse the repository at this point in the history
* Removing alerts from state on disconnect
  • Loading branch information
srashee1 authored Jan 6, 2022
1 parent a87dee5 commit beccb0b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,11 @@
width: 100%;
height: 100%;
}

.mapboxgl-marker {
background: none;
border: none;
cursor: pointer;
width: 20px;
height: 20px;
}
15 changes: 13 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,30 @@ export default function App() {
if (stringMessage !== 'Connected') {
console.log(stringMessage);
const alert = JSON.parse(stringMessage) as Alert;
setAlerts((alerts) => [alert, ...alerts]);
if (!alerts.includes(alert)) {
setAlerts((alerts) => [alert, ...alerts]);
}
setViewport({
latitude: 39.98654998139231,
longitude: -83.00250910125781,
width: '100vw',
height: '100vh',
zoom: 10})
}
});
websocket.addEventListener('open', () => {
console.log('Connected to Alerting Engine');
});
websocket.addEventListener('close', () => {
console.log('Disconnected');
setAlerts((alerts) => [])
});
websocket.addEventListener('error', () => {
console.log('Error received from server');
});
websocketRef.current = websocket;
return () => websocket.close();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return (
Expand All @@ -89,6 +99,7 @@ export default function App() {
{...viewport}
mapboxApiAccessToken={MAPBOX_PUBLIC_KEY}
mapStyle="mapbox://styles/mapbox/light-v10"
minZoom={8}
onViewportChange={(viewport: React.SetStateAction<{ latitude: number; longitude: number; width: string; height: string; zoom: number; }>) => {
setViewport(viewport);
}}
Expand Down Expand Up @@ -128,4 +139,4 @@ export default function App() {
</ReactMapGL>
</div>
);
}
}

0 comments on commit beccb0b

Please sign in to comment.