Skip to content

Full Toolkit for Next-Level Domain Analysis

Use bottom drawer for IP details on small screens 📲

Felix Wotschofsky0032042ea35e
diff --git a/components/IpDetailsModal.tsx b/components/IpDetailsModal.tsx
index f4eba31..37e1862 100644
--- a/components/IpDetailsModal.tsx
+++ b/components/IpDetailsModal.tsx
@@ -1,4 +1,5 @@
import type { DialogProps } from '@radix-ui/react-dialog';
+import { useWindowSize } from '@uidotdev/usehooks';
import type { LatLngExpression } from 'leaflet';
import naturalCompare from 'natural-compare-lite';
import dynamic from 'next/dynamic';
@@ -12,6 +13,16 @@ import {
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog';
+import {
+ Drawer,
+ DrawerClose,
+ DrawerContent,
+ DrawerDescription,
+ DrawerFooter,
+ DrawerHeader,
+ DrawerTitle,
+ DrawerTrigger,
+} from '@/components/ui/drawer';
import { Spinner } from '@/components/ui/spinner';
import { Table, TableBody, TableCell, TableRow } from '@/components/ui/table';
@@ -19,6 +30,8 @@ import type { IpLookupResponse } from '@/app/api/lookupIp/route';
import CopyButton from '@/components/CopyButton';
import DomainLink from '@/components/DomainLink';
+import { Button } from './ui/button';
+
const LocationMap = dynamic(() => import('@/components/LocationMap'), {
ssr: false,
});
@@ -44,6 +57,8 @@ const IpDetailsModal: FC<IpDetailsModalProps> = ({
open,
onOpenChange,
}) => {
+ const { width: windowWidth } = useWindowSize();
+
const { data, error } = useSWRImmutable<IpLookupResponse>(
open ? `/api/lookupIp?ip=${encodeURIComponent(ip)}` : null
);
@@ -96,51 +111,65 @@ const IpDetailsModal: FC<IpDetailsModalProps> = ({
location = [data.lat, data.lon];
}
+ const title = `IP Details for ${ip}`;
+ const content = !data ? (
+ <div className="flex items-center justify-center">
+ <Spinner />
+ </div>
+ ) : error ? (
+ <p>An error occurred!</p>
+ ) : (
+ <>
+ <Table>
+ <TableBody>
+ {mappedEntries.map((el) => (
+ <TableRow
+ key={el.label + el.value}
+ className="hover:bg-transparent"
+ >
+ <TableCell className="pl-0">{el.label}</TableCell>
+ <TableCell className="pr-0">
+ {el.type === EntryTypes.Reverse ? (
+ <DomainLink domain={el.value} />
+ ) : (
+ <>
+ <span>{el.value}</span>
+ {el.type === EntryTypes.IP && (
+ <CopyButton value={el.value} />
+ )}
+ </>
+ )}
+ </TableCell>
+ </TableRow>
+ ))}
+ </TableBody>
+ </Table>
+
+ <div className="my-4 [&_.leaflet-container]:h-80 [&_.leaflet-container]:w-full">
+ <LocationMap location={location} />
+ </div>
+ </>
+ );
+
+ if (windowWidth && windowWidth < 640) {
+ return (
+ <Drawer open={open} onOpenChange={onOpenChange}>
+ <DrawerContent>
+ <DrawerHeader>
+ <DrawerTitle>{title}</DrawerTitle>
+ <DrawerDescription>{content}</DrawerDescription>
+ </DrawerHeader>
+ </DrawerContent>
+ </Drawer>
+ );
+ }
+
return (
<Dialog modal open={open} onOpenChange={onOpenChange}>
<DialogContent>
<DialogHeader>
- <DialogTitle>IP Details for {ip}</DialogTitle>
- <DialogDescription>
- {!data ? (
- <div className="flex items-center justify-center">
- <Spinner />
- </div>
- ) : error ? (
- <p>An error occurred!</p>
- ) : (
- <>
- <Table>
- <TableBody>
- {mappedEntries.map((el) => (
- <TableRow
- key={el.label + el.value}
- className="hover:bg-transparent"
- >
- <TableCell className="pl-0">{el.label}</TableCell>
- <TableCell className="pr-0">
- {el.type === EntryTypes.Reverse ? (
- <DomainLink domain={el.value} />
- ) : (
- <>
- <span>{el.value}</span>
- {el.type === EntryTypes.IP && (
- <CopyButton value={el.value} />
- )}
- </>
- )}
- </TableCell>
- </TableRow>
- ))}
- </TableBody>
- </Table>
-
- <div className="my-4 [&_.leaflet-container]:h-80 [&_.leaflet-container]:w-full">
- <LocationMap location={location} />
- </div>
- </>
- )}
- </DialogDescription>
+ <DialogTitle>{title}</DialogTitle>
+ <DialogDescription>{content}</DialogDescription>
</DialogHeader>
</DialogContent>
</Dialog>
diff --git a/components/ui/drawer.tsx b/components/ui/drawer.tsx
new file mode 100644
index 0000000..f78fb47
--- /dev/null
+++ b/components/ui/drawer.tsx
@@ -0,0 +1,118 @@
+'use client';
+
+import * as React from 'react';
+import { Drawer as DrawerPrimitive } from 'vaul';
+
+import { cn } from '@/lib/utils';
+
+const Drawer = ({
+ shouldScaleBackground = true,
+ ...props
+}: React.ComponentProps<typeof DrawerPrimitive.Root>) => (
+ <DrawerPrimitive.Root
+ shouldScaleBackground={shouldScaleBackground}
+ {...props}
+ />
+);
+Drawer.displayName = 'Drawer';
+
+const DrawerTrigger = DrawerPrimitive.Trigger;
+
+const DrawerPortal = DrawerPrimitive.Portal;
+
+const DrawerClose = DrawerPrimitive.Close;
+
+const DrawerOverlay = React.forwardRef<
+ React.ElementRef<typeof DrawerPrimitive.Overlay>,
+ React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Overlay>
+>(({ className, ...props }, ref) => (
+ <DrawerPrimitive.Overlay
+ ref={ref}
+ className={cn('fixed inset-0 z-50 bg-black/80', className)}
+ {...props}
+ />
+));
+DrawerOverlay.displayName = DrawerPrimitive.Overlay.displayName;
+
+const DrawerContent = React.forwardRef<
+ React.ElementRef<typeof DrawerPrimitive.Content>,
+ React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Content>
+>(({ className, children, ...props }, ref) => (
+ <DrawerPortal>
+ <DrawerOverlay />
+ <DrawerPrimitive.Content
+ ref={ref}
+ className={cn(
+ 'fixed inset-x-0 bottom-0 z-50 mt-24 flex h-auto flex-col rounded-t-[10px] border bg-background',
+ className
+ )}
+ {...props}
+ >
+ <div className="mx-auto mt-4 h-2 w-[100px] rounded-full bg-muted" />
+ {children}
+ </DrawerPrimitive.Content>
+ </DrawerPortal>
+));
+DrawerContent.displayName = 'DrawerContent';
+
+const DrawerHeader = ({
+ className,
+ ...props
+}: React.HTMLAttributes<HTMLDivElement>) => (
+ <div
+ className={cn('grid gap-1.5 p-4 text-center sm:text-left', className)}
+ {...props}
+ />
+);
+DrawerHeader.displayName = 'DrawerHeader';
+
+const DrawerFooter = ({
+ className,
+ ...props
+}: React.HTMLAttributes<HTMLDivElement>) => (
+ <div
+ className={cn('mt-auto flex flex-col gap-2 p-4', className)}
+ {...props}
+ />
+);
+DrawerFooter.displayName = 'DrawerFooter';
+
+const DrawerTitle = React.forwardRef<
+ React.ElementRef<typeof DrawerPrimitive.Title>,
+ React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Title>
+>(({ className, ...props }, ref) => (
+ <DrawerPrimitive.Title
+ ref={ref}
+ className={cn(
+ 'text-lg font-semibold leading-none tracking-tight',
+ className
+ )}
+ {...props}
+ />
+));
+DrawerTitle.displayName = DrawerPrimitive.Title.displayName;
+
+const DrawerDescription = React.forwardRef<
+ React.ElementRef<typeof DrawerPrimitive.Description>,
+ React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Description>
+>(({ className, ...props }, ref) => (
+ <DrawerPrimitive.Description
+ ref={ref}
+ className={cn('text-sm text-muted-foreground', className)}
+ {...props}
+ />
+));
+DrawerDescription.displayName = DrawerPrimitive.Description.displayName;
+
+export {
+ Drawer,
+ DrawerPortal,
+ DrawerOverlay,
+ DrawerTrigger,
+ DrawerClose,
+ DrawerContent,
+ DrawerHeader,
+ DrawerFooter,
+ DrawerTitle,
+ DrawerDescription,
+};
diff --git a/package.json b/package.json
index 3ab5cd6..13c7dc7 100644
--- a/package.json
+++ b/package.json
@@ -23,6 +23,7 @@
"@radix-ui/react-tooltip": "^1.0.7",
"@types/punycode": "^2.1.3",
"@types/validator": "^13.11.7",
+ "@uidotdev/usehooks": "^2.4.1",
"@vercel/speed-insights": "^1.0.1",
"autoprefixer": "^10.4.16",
"bottleneck": "^2.19.5",
@@ -53,6 +54,7 @@
"tailwindcss": "^3.3.6",
"tailwindcss-animate": "^1.0.7",
"validator": "^13.11.0",
+ "vaul": "^0.8.0",
"whoiser": "^1.17.1"
},
"devDependencies": {
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 2256a77..f75c87f 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -32,6 +32,9 @@ dependencies:
'@types/validator':
specifier: ^13.11.7
version: 13.11.7
+ '@uidotdev/usehooks':
+ specifier: ^2.4.1
'@vercel/speed-insights':
specifier: ^1.0.1
version: 1.0.1
@@ -122,6 +125,9 @@ dependencies:
validator:
specifier: ^13.11.0
version: 13.11.0
+ vaul:
+ specifier: ^0.8.0
whoiser:
specifier: ^1.17.1
version: 1.17.1
@@ -2724,6 +2730,17 @@ packages:
eslint-visitor-keys: 3.4.3
dev: true
+ resolution: {integrity: sha512-1I+RwWyS+kdv3Mv0Vmc+p0dPYH0DTRAo04HLyXReYBL9AeseDWUJyi4THuksBJcu9F0Pih69Ak150VDnqbVnXg==}
+ engines: {node: '>=16'}
+ peerDependencies:
+ react: '>=18.0.0'
+ react-dom: '>=18.0.0'
+ dependencies:
+ react: 18.2.0
+ react-dom: 18.2.0([email protected])
+ dev: false
+
resolution: {integrity: sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==}
dev: true
@@ -5885,6 +5902,20 @@ packages:
engines: {node: '>= 0.10'}
dev: false
+ resolution: {integrity: sha512-9nUU2jIObJvJZxeQU1oVr/syKo5XqbRoOMoTEt0hHlWify4QZFlqTh6QSN/yxoKzNrMeEQzxbc3XC/vkPLOIqw==}
+ peerDependencies:
+ react: ^16.8 || ^17.0 || ^18.0
+ react-dom: ^16.8 || ^17.0 || ^18.0
+ dependencies:
+ '@radix-ui/react-dialog': 1.0.5(@types/[email protected])(@types/[email protected])([email protected])([email protected])
+ react: 18.2.0
+ react-dom: 18.2.0([email protected])
+ transitivePeerDependencies:
+ - '@types/react'
+ - '@types/react-dom'
+ dev: false
+
resolution: {integrity: sha512-Lcvm7MGST/4fup+ifyKi2hjyIAwcdI4HRgtvTpIUxBRhB+RFtUh8XtDOxUfctVCnhVi+QQj49i91OyvzkJl6cg==}
engines: {node: '>=10.13.0'}