Skip to content

Full Toolkit for Next-Level Domain Analysis

Add "Share" button 👥

Felix Wotschofsky3fa3ec084b46
diff --git a/app/layout.tsx b/app/layout.tsx
index 963b2ad..ad5625a 100644
--- a/app/layout.tsx
+++ b/app/layout.tsx
@@ -1,6 +1,8 @@
import { SpeedInsights } from '@vercel/speed-insights/next';
import type { FC, ReactNode } from 'react';
+import { Toaster } from '@/components/ui/sonner';
+
import Footer from '@/components/Footer';
import Header from '@/components/Header';
@@ -43,6 +45,7 @@ const RootLayout: FC<RootLayoutProps> = ({ children }) => {
</div>
</Providers>
+ <Toaster />
<SpeedInsights />
</body>
</html>
diff --git a/app/lookup/[domain]/layout.tsx b/app/lookup/[domain]/layout.tsx
index 444e512..25d61df 100644
--- a/app/lookup/[domain]/layout.tsx
+++ b/app/lookup/[domain]/layout.tsx
@@ -6,6 +6,7 @@ import { type FC, type ReactNode } from 'react';
import RelatedDomains from '@/components/RelatedDomains';
import ResultsTabs from '@/components/ResultsTabs';
import SearchForm from '@/components/SearchForm';
+import ShareButton from '@/components/ShareButton';
import WhoisQuickInfo from '@/components/WhoisQuickInfo';
import { isValidDomain } from '@/lib/utils';
@@ -47,17 +48,21 @@ const LookupLayout: FC<LookupLayoutProps> = ({
</div>
<div className="container">
- <h1 className="mb-2">
- <span className="block text-muted-foreground">Results for</span>
- <a
- className="block text-4xl font-bold"
- href={`https://${domain}`}
- target="_blank"
- rel="noreferrer nofollow"
- >
- {domain} <ExternalLinkIcon className="inline-block" />
- </a>
- </h1>
+ <div className="flex items-center gap-4">
+ <h1 className="mb-2 flex-1">
+ <span className="block text-muted-foreground">Results for</span>
+ <a
+ className="block text-4xl font-bold"
+ href={`https://${domain}`}
+ target="_blank"
+ rel="noreferrer nofollow"
+ >
+ {domain} <ExternalLinkIcon className="inline-block" />
+ </a>
+ </h1>
+
+ <ShareButton />
+ </div>
<RelatedDomains domain={domain} />
<WhoisQuickInfo domain={domain} />
diff --git a/components/CopyButton.tsx b/components/CopyButton.tsx
index 677540d..bb75919 100644
--- a/components/CopyButton.tsx
+++ b/components/CopyButton.tsx
@@ -3,6 +3,7 @@
import { CheckIcon, ClipboardIcon } from 'lucide-react';
import { usePlausible } from 'next-plausible';
import { type FC, useCallback, useState } from 'react';
+import { toast } from 'sonner';
import {
Tooltip,
@@ -24,6 +25,8 @@ const CopyButton: FC<CopyButton> = ({ value }) => {
navigator.clipboard.writeText(value);
setTimeout(() => setWasCopied(false), 2000);
+ toast('Copied to clipboard');
+
plausible('Copy Button: Click', { props: { value } });
}, [value, setWasCopied, plausible]);
diff --git a/components/ShareButton.tsx b/components/ShareButton.tsx
new file mode 100644
index 0000000..56c6b0e
--- /dev/null
+++ b/components/ShareButton.tsx
@@ -0,0 +1,37 @@
+'use client';
+
+import { ShareIcon } from 'lucide-react';
+import { usePlausible } from 'next-plausible';
+import { type FC, useCallback } from 'react';
+import { toast } from 'sonner';
+
+import { Button } from '@/components/ui/button';
+
+const ShareButton: FC = () => {
+ const plausible = usePlausible();
+
+ const onClick = useCallback(() => {
+ if ('share' in navigator) {
+ navigator.share({
+ title: document.title,
+ url: window.location.href,
+ });
+ return;
+ } else {
+ (navigator as Navigator).clipboard.writeText(window.location.href);
+ toast('Copied to clipboard');
+ }
+
+ plausible('Share: Click', {
+ props: { url: window.location.pathname + window.location.search },
+ });
+ }, [plausible]);
+
+ return (
+ <Button className="px-3" variant="outline" size="lg" onClick={onClick}>
+ <ShareIcon />
+ </Button>
+ );
+};
+
+export default ShareButton;
diff --git a/components/ui/sonner.tsx b/components/ui/sonner.tsx
new file mode 100644
index 0000000..b38ad1e
--- /dev/null
+++ b/components/ui/sonner.tsx
@@ -0,0 +1,31 @@
+'use client';
+
+import { useTheme } from 'next-themes';
+import { Toaster as Sonner } from 'sonner';
+
+type ToasterProps = React.ComponentProps<typeof Sonner>;
+
+const Toaster = ({ ...props }: ToasterProps) => {
+ const { theme = 'system' } = useTheme();
+
+ return (
+ <Sonner
+ theme={theme as ToasterProps['theme']}
+ className="toaster group"
+ toastOptions={{
+ classNames: {
+ toast:
+ 'group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg',
+ description: 'group-[.toast]:text-muted-foreground',
+ actionButton:
+ 'group-[.toast]:bg-primary group-[.toast]:text-primary-foreground',
+ cancelButton:
+ 'group-[.toast]:bg-muted group-[.toast]:text-muted-foreground',
+ },
+ }}
+ {...props}
+ />
+ );
+};
+
+export { Toaster };
diff --git a/package.json b/package.json
index bdcc235..9800c6f 100644
--- a/package.json
+++ b/package.json
@@ -50,6 +50,7 @@
"react-leaflet": "^4.2.1",
"react-string-replace": "^1.1.1",
"react-wrap-balancer": "^1.1.0",
+ "sonner": "^1.3.1",
"swr": "^2.2.4",
"tailwind-merge": "^2.1.0",
"tailwindcss": "^3.3.6",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 186cf95..2e3994e 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -113,6 +113,9 @@ dependencies:
react-wrap-balancer:
specifier: ^1.1.0
version: 1.1.0([email protected])
+ sonner:
+ specifier: ^1.3.1
swr:
specifier: ^2.2.4
version: 2.2.4([email protected])
@@ -5420,6 +5423,16 @@ packages:
tslib: 2.6.2
dev: true
+ resolution: {integrity: sha512-+rOAO56b2eI3q5BtgljERSn2umRk63KFIvgb2ohbZ5X+Eb5u+a/7/0ZgswYqgBMg8dyl7n6OXd9KasA8QF9ToA==}
+ 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-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==}
engines: {node: '>=0.10.0'}