Full Toolkit for Next-Level Domain Analysis
Show OSM Map in IP Details Modal 🗺
Felix Wotschofskye0808ab8403e
diff --git a/components/IpDetailsModal.tsx b/components/IpDetailsModal.tsxindex ba7c4a2..c2f0fb2 100644--- a/components/IpDetailsModal.tsx+++ b/components/IpDetailsModal.tsx@@ -1,4 +1,6 @@+import dynamic from 'next/dynamic';import {+ chakra,Flex,Modal,ModalBody,@@ -12,8 +14,10 @@ import {Tr,} from '@chakra-ui/react';import useSWR from 'swr';+import type { LatLngExpression } from 'leaflet';import type { IpLookupResponse } from '@/api/lookupIp';+import styles from '@/styles/IpDetailsModal.module.css'type IpDetailsModalProps = {ip: string;@@ -27,6 +31,8 @@ const IpDetailsModal = (props: IpDetailsModalProps) => {);let mappedEntries: { label: string; value: string }[] = [];+ let location: LatLngExpression = [0, 0];+if (data) {mappedEntries = [{@@ -58,8 +64,14 @@ const IpDetailsModal = (props: IpDetailsModalProps) => {value: data.timezone,},];++ location = [data.lat, data.lon];}+ const LocationMap = dynamic(() => import('@/components/LocationMap'), {+ ssr: false,+ });+return (<Modal size="xl" isOpen={props.isOpen} onClose={props.onClose}><ModalOverlay />@@ -83,6 +95,10 @@ const IpDetailsModal = (props: IpDetailsModalProps) => {</Tr>))}</Table>++ <chakra.div className={styles.mapWrapper} my={4}>+ <LocationMap location={location} />+ </chakra.div></>)}</ModalBody>diff --git a/components/LocationMap.tsx b/components/LocationMap.tsxnew file mode 100644index 0000000..9fcc89e--- /dev/null+++ b/components/LocationMap.tsx@@ -0,0 +1,17 @@+import { MapContainer, TileLayer, Marker } from 'react-leaflet';+import type { LatLngExpression } from 'leaflet';+import 'leaflet-defaulticon-compatibility';+import 'leaflet-defaulticon-compatibility/dist/leaflet-defaulticon-compatibility.css';+import 'leaflet/dist/leaflet.css';++const LocationMap = ({ location }: { location: LatLngExpression }) => (+ <MapContainer center={location} zoom={4}>+ <TileLayer+ attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'+ url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"+ />+ <Marker position={location} />+ </MapContainer>+);++export default LocationMap;diff --git a/package.json b/package.jsonindex a8b7847..6312cd9 100644--- a/package.json+++ b/package.json@@ -13,15 +13,19 @@"@chakra-ui/react": "^1.6.4","@emotion/react": "^11","@emotion/styled": "^11",+ "@types/leaflet": "^1.7.4","@types/punycode": "^2.1.0","@types/validator": "^13.6.3","axios": "^0.21.1","framer-motion": "^4",+ "leaflet": "^1.7.1",+ "leaflet-defaulticon-compatibility": "^0.1.1","next": "11.0.0","punycode": "^2.1.1","react": "17.0.2","react-dom": "17.0.2","react-icons": "^4.2.0",+ "react-leaflet": "^3.2.0","swr": "^0.5.6","validator": "^13.6.0"},diff --git a/pages/api/lookupIp.ts b/pages/api/lookupIp.tsindex d8107da..11fb1a4 100644--- a/pages/api/lookupIp.ts+++ b/pages/api/lookupIp.ts@@ -5,15 +5,15 @@ import dns from 'dns';import isIP from 'validator/lib/isIP';export type IpLookupResponse = {- reverse: string[];+ city: string;+ country: string;isp: string;+ lat: number;+ lon: number;org: string;- country: string;region: string;- city: string;+ reverse: string[];timezone: string;- lat: string;- lon: string;};export type IpLookupErrorResponse = { error: true; message: string };diff --git a/styles/IpDetailsModal.module.css b/styles/IpDetailsModal.module.cssnew file mode 100644index 0000000..619a9c4--- /dev/null+++ b/styles/IpDetailsModal.module.css@@ -0,0 +1,4 @@+.mapWrapper :global(.leaflet-container) {+ width: 100%;+ height: 20rem;+}diff --git a/tsconfig.json b/tsconfig.jsonindex bef9bf2..58c7319 100644--- a/tsconfig.json+++ b/tsconfig.json@@ -17,6 +17,7 @@"paths": {"@/api/*": ["pages/api/*"],"@/components/*": ["components/*"],+ "@/styles/*": ["styles/*"],"@/utils/*": ["utils/*"]}},diff --git a/yarn.lock b/yarn.lockindex 5f0e557..03fb051 100644--- a/yarn.lock+++ b/yarn.lock@@ -878,16 +878,33 @@prop-types "^15.7.2"tslib "^2.1.0"+"@react-leaflet/core@^1.1.0":+ version "1.1.0"+ resolved "https://registry.yarnpkg.com/@react-leaflet/core/-/core-1.1.0.tgz#389b2b373f1da4caeb3c4cf6f33d84561c58d504"+ integrity sha512-zFxMHgfjCi7khRVB7o7H8NoJl36NaezvfcaeEurVXx22lAGHFlTHiSuLOGA4tOiHj+Ep+Lo3uwUGJ3YM9BGkHg==+"@rushstack/eslint-patch@^1.0.6":version "1.0.6"resolved "https://registry.yarnpkg.com/@rushstack/eslint-patch/-/eslint-patch-1.0.6.tgz#023d72a5c4531b4ce204528971700a78a85a0c50"integrity sha512-Myxw//kzromB9yWgS8qYGuGVf91oBUUJpNvy5eM50sqvmKLbKjwLxohJnkWGTeeI9v9IBMtPLxz5Gc60FIfvCA==+"@types/geojson@*":+ version "7946.0.8"+ resolved "https://registry.yarnpkg.com/@types/geojson/-/geojson-7946.0.8.tgz#30744afdb385e2945e22f3b033f897f76b1f12ca"+ integrity sha512-1rkryxURpr6aWP7R786/UQOkJ3PcpQiWkAXBmdWc7ryFWqN6a4xfK7BtjXvFBKO9LjQ+MWQSWxYeZX1OApnArA==+"@types/json5@^0.0.29":version "0.0.29"resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"integrity sha1-7ihweulOEdK4J7y+UnC86n8+ce4=+"@types/leaflet@^1.7.4":+ version "1.7.4"+ resolved "https://registry.yarnpkg.com/@types/leaflet/-/leaflet-1.7.4.tgz#bb9430f69d588ca5829c1ba82657e179454f93a1"+ integrity sha512-a3qYlMwJ62+WRoiDmYODUD4KywA14jP2XohAkAWtELGuMAD3MohZa/MmIvQDqF52xNI9OYaY8BMsL+9z7yf2HQ==+ dependencies:+ "@types/geojson" "*"+"@types/[email protected]":version "4.6.6"resolved "https://registry.yarnpkg.com/@types/lodash.mergewith/-/lodash.mergewith-4.6.6.tgz#c4698f5b214a433ff35cb2c75ee6ec7f99d79f10"@@ -2650,6 +2667,16 @@ language-tags@^1.0.5:dependencies:language-subtag-registry "~0.3.2"+leaflet-defaulticon-compatibility@^0.1.1:+ version "0.1.1"+ resolved "https://registry.yarnpkg.com/leaflet-defaulticon-compatibility/-/leaflet-defaulticon-compatibility-0.1.1.tgz#ab72257b3da66fb48dab69a10c3824012a15a20a"+ integrity sha512-vDBFdlUAwjSEGep9ih8kfJilf6yN8V9zTbF5NC/1ZwLeGko3RUQepspPnGCRMFV51dY3Lb3hziboicrFz+rxQA==++leaflet@^1.7.1:+ version "1.7.1"+ resolved "https://registry.yarnpkg.com/leaflet/-/leaflet-1.7.1.tgz#10d684916edfe1bf41d688a3b97127c0322a2a19"+ integrity sha512-/xwPEBidtg69Q3HlqPdU3DnrXQOvQU/CCHA1tcDQVzOwm91YMYaILjNp7L4Eaw5Z4sOYdbBz6koWyibppd8Zqw==+levn@^0.4.1:version "0.4.1"resolved "https://registry.yarnpkg.com/levn/-/levn-0.4.1.tgz#ae4562c007473b932a6200d403268dd2fffc6ade"@@ -3401,6 +3428,13 @@ react-is@^16.7.0, react-is@^16.8.1:resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==+react-leaflet@^3.2.0:+ version "3.2.0"+ resolved "https://registry.yarnpkg.com/react-leaflet/-/react-leaflet-3.2.0.tgz#8d5d05beab3f9e52665738ad737bb7b1da99f30b"+ integrity sha512-eHVqoRGjW8T9GxLt7jyTKP3BDQ7XQ5AD+tc/zkbaABn1dbmREDy8GojNcYjZQa3QFLQoOLQMcUC1PTtzytZpUA==+ dependencies:+ "@react-leaflet/core" "^1.1.0"+version "0.8.3"resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.8.3.tgz#721d4657672d400c5e3c75d063c4a85fb2d5d68f"