Skip to content

Full Toolkit for Next-Level Domain Analysis

Rework star reminder 🌟

Felix Wotschofsky5f38682b19dd
diff --git a/app/_components/star-reminder.tsx b/app/_components/star-reminder.tsx
deleted file mode 100644
index 576a6f4..0000000
--- a/app/_components/star-reminder.tsx
+++ /dev/null
@@ -1,89 +0,0 @@
-'use client';
-
-import { useLocalStorage } from '@uidotdev/usehooks';
-import { XIcon } from 'lucide-react';
-import ms from 'ms';
-import { type FC, useCallback, useEffect, useState } from 'react';
-import { FaGithub } from 'react-icons/fa';
-
-import { Button } from '@/components/ui/button';
-import { Card } from '@/components/ui/card';
-
-import { useAnalytics } from '@/lib/analytics';
-
-const INITIAL_DELAY = ms('2m');
-const TIMEOUT_PERIOD = ms('7d');
-
-export const StarReminder: FC = () => {
- const { reportEvent } = useAnalytics();
- const [_, setForceUpdate] = useState(0);
-
- const [isStarred, setIsStarred] = useLocalStorage(
- 'star-reminder.starred',
- false,
- );
- const [lastDismissed, setLastDismissed] = useLocalStorage(
- 'star-reminder.last-dismissed',
- Date.now() - TIMEOUT_PERIOD + INITIAL_DELAY,
- );
-
- const timeUntilVisible = TIMEOUT_PERIOD - (Date.now() - lastDismissed);
- const visible = timeUntilVisible <= 0 && !isStarred;
-
- useEffect(() => {
- if (timeUntilVisible > 0) {
- const timeout = setTimeout(() => {
- setForceUpdate((prev) => prev + 1);
- }, timeUntilVisible + 100);
- return () => clearTimeout(timeout);
- }
- }, [timeUntilVisible]);
-
- const handleDismiss = useCallback(() => {
- setLastDismissed(Date.now());
- reportEvent('Star Reminder: Suppress', {});
- }, [setLastDismissed, reportEvent]);
-
- const handleClick = useCallback(() => {
- setIsStarred(true);
- reportEvent('Star Reminder: Click', {});
- }, [setIsStarred, reportEvent]);
-
- if (!visible) {
- return null;
- }
-
- return (
- <aside className="fixed bottom-6 left-6 max-w-[calc(100vw-3rem)]">
- <Card className="relative p-6 shadow-lg">
- <p className="!pl-0 font-semibold">
- Enjoying Domain Digger?{' '}
- <XIcon
- role="button"
- onClick={handleDismiss}
- className="ml-3 inline-block h-5 w-5 text-zinc-500 dark:text-zinc-400"
- />
- </p>
- <div className="mt-4 flex select-none justify-evenly !pl-0">
- <Button
- variant="ghost"
- asChild
- className="px-2"
- onClick={handleClick}
- >
- <a
- href="https://github.com/wotschofsky/domain-digger"
- target="_blank"
- rel="noopener"
- >
- <FaGithub className="mr-1 h-6 w-4" />
- <span className="hidden md:inline">
- Star <span className="sr-only">on GitHub</span>
- </span>
- </a>
- </Button>
- </div>
- </Card>
- </aside>
- );
-};
diff --git a/app/api/stargazers-summary/route.ts b/app/api/stargazers-summary/route.ts
new file mode 100644
index 0000000..c081d10
--- /dev/null
+++ b/app/api/stargazers-summary/route.ts
@@ -0,0 +1,28 @@
+import { NextResponse } from 'next/server';
+
+import { getStargazersSummary } from '@/lib/github';
+
+export const runtime = 'edge';
+export const preferredRegion = 'home';
+
+export const GET = async () => {
+ try {
+ const stargazers = await getStargazersSummary(
+ 'wotschofsky',
+ 'domain-digger',
+ );
+
+ return NextResponse.json(stargazers, {
+ headers: {
+ 'Cache-Control': 'public, s-maxage=3600',
+ },
+ });
+ } catch (error) {
+ console.error('Failed to fetch recent stargazers:', error);
+
+ return NextResponse.json(
+ { error: 'Failed to fetch recent stargazers' },
+ { status: 500 },
+ );
+ }
+};
diff --git a/app/layout.tsx b/app/layout.tsx
index b948c2c..c2092a7 100644
--- a/app/layout.tsx
+++ b/app/layout.tsx
@@ -1,22 +1,14 @@
import { SpeedInsights } from '@vercel/speed-insights/next';
import type { Viewport } from 'next';
-import dynamic from 'next/dynamic';
import type { FC, ReactNode } from 'react';
import { Toaster } from '@/components/ui/sonner';
-import { ClientOnly } from '@/components/client-only';
import { env } from '@/env';
import './globals.css';
import { Providers } from './providers';
-const StarReminder = dynamic(() =>
- import('./_components/star-reminder').then((m) => ({
- default: m.StarReminder,
- })),
-);
-
export const viewport: Viewport = {
width: 'device-width',
initialScale: 1,
@@ -58,9 +50,6 @@ const RootLayout: FC<RootLayoutProps> = ({ children }) => {
</div>
</Providers>
- <ClientOnly>
- <StarReminder />
- </ClientOnly>
<Toaster />
<SpeedInsights />
</body>
diff --git a/app/lookup/[domain]/_components/star-reminder.tsx b/app/lookup/[domain]/_components/star-reminder.tsx
new file mode 100644
index 0000000..53badd5
--- /dev/null
+++ b/app/lookup/[domain]/_components/star-reminder.tsx
@@ -0,0 +1,185 @@
+'use client';
+
+import { useLocalStorage } from '@uidotdev/usehooks';
+import ms from 'ms';
+import { type FC, useCallback, useEffect, useState } from 'react';
+import { FaGithub } from 'react-icons/fa';
+import useSWRImmutable from 'swr/immutable';
+
+import {
+ AlertDialog,
+ AlertDialogAction,
+ AlertDialogCancel,
+ AlertDialogContent,
+ AlertDialogDescription,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogTitle,
+} from '@/components/ui/alert-dialog';
+
+import { useAnalytics } from '@/lib/analytics';
+import { cn } from '@/lib/utils';
+
+const INITIAL_DELAY = ms('2m');
+const TIMEOUT_PERIOD = ms('7d');
+const SKIP_BUTTON_DELAY = ms('5s');
+
+export const StarReminder: FC = () => {
+ const { reportEvent } = useAnalytics();
+ const [_, setForceUpdate] = useState(0);
+ const forceUpdate = useCallback(
+ () => setForceUpdate((prev) => prev + 1),
+ [setForceUpdate],
+ );
+ const [secondsRemaining, setSecondsRemaining] = useState(
+ Math.ceil(SKIP_BUTTON_DELAY / 1000),
+ );
+
+ const { data } = useSWRImmutable<{
+ recentStargazers: Array<{
+ name: string;
+ avatarUrl: string;
+ }>;
+ totalStars: number;
+ }>('/api/stargazers-summary');
+
+ const [isStarred, setIsStarred] = useLocalStorage(
+ 'star-reminder.starred',
+ false,
+ );
+ const [lastDismissed, setLastDismissed] = useLocalStorage(
+ 'star-reminder.last-dismissed',
+ Date.now() - TIMEOUT_PERIOD + INITIAL_DELAY,
+ );
+
+ const timeUntilVisible = TIMEOUT_PERIOD - (Date.now() - lastDismissed);
+ const visible = Boolean(data) && timeUntilVisible <= 0 && !isStarred;
+
+ useEffect(() => {
+ if (timeUntilVisible > 0) {
+ const timeout = setTimeout(() => {
+ forceUpdate();
+ }, timeUntilVisible + 100);
+ return () => clearTimeout(timeout);
+ }
+ }, [timeUntilVisible]);
+
+ useEffect(() => {
+ if (visible) {
+ reportEvent('Star Reminder: Show', {});
+ }
+ }, [visible]);
+
+ useEffect(() => {
+ if (!visible) return;
+
+ const interval = setInterval(() => {
+ setSecondsRemaining((prev) => Math.max(0, prev - 1));
+ }, 1000);
+
+ return () => clearInterval(interval);
+ }, [visible]);
+
+ const handleOpenChange = useCallback(
+ (state: boolean) => {
+ if (!state) {
+ setLastDismissed(Date.now());
+ reportEvent('Star Reminder: Suppress', {});
+ }
+ },
+ [setLastDismissed, reportEvent],
+ );
+
+ const handleClick = useCallback(() => {
+ setIsStarred(true);
+ reportEvent('Star Reminder: Click', {});
+ }, [setIsStarred, reportEvent]);
+
+ useEffect(() => {
+ const style = document.createElement('style');
+ style.innerHTML = `
+ @keyframes avatar-bounce {
+ 0%, 100% { transform: translateY(0) scale(1.25); }
+ 50% { transform: translateY(-10px) scale(1.25); }
+ }
+ `;
+ document.head.appendChild(style);
+
+ return () => {
+ document.head.removeChild(style);
+ };
+ }, []);
+
+ if (!visible) {
+ return null;
+ }
+
+ if (!data) {
+ return null;
+ }
+
+ return (
+ <AlertDialog open={visible} onOpenChange={handleOpenChange}>
+ <AlertDialogContent>
+ <AlertDialogHeader>
+ <AlertDialogTitle className="text-center text-lg font-bold">
+ Enjoying Domain Digger?
+ </AlertDialogTitle>
+ <AlertDialogDescription>
+ <div className="space-y-4">
+ <div className="flex justify-center">
+ {data.recentStargazers.map((user, index) => (
+ <img
+ key={index}
+ className="aspect-square w-8 scale-125 rounded-full border-2 border-white dark:border-zinc-900"
+ style={{
+ animationDelay: `${1 + index * 0.15}s`,
+ animationDuration: '0.5s',
+ animationName: 'avatar-bounce',
+ animationIterationCount: 1,
+ animationTimingFunction: 'ease-in-out',
+ }}
+ src={user.avatarUrl}
+ alt={`${user.name}'s avatar`}
+ />
+ ))}
+ </div>
+ <p className="text-center">
+ {data.recentStargazers[0].name} and {data.totalStars - 1} others
+ <br />
+ have recently starred Domain Digger
+ </p>
+ </div>
+ </AlertDialogDescription>
+ </AlertDialogHeader>
+
+ <AlertDialogAction asChild onClick={handleClick}>
+ <a
+ href="https://github.com/wotschofsky/domain-digger"
+ target="_blank"
+ rel="noopener"
+ className="mx-auto my-3 flex w-fit items-center justify-center px-4"
+ >
+ <FaGithub className="mr-1 h-6 w-4" />
+ Star on GitHub
+ </a>
+ </AlertDialogAction>
+
+ <AlertDialogDescription className="text-center text-sm">
+ Starring the project is 100% free and helps spread the word
+ </AlertDialogDescription>
+
+ <AlertDialogFooter>
+ <AlertDialogCancel
+ disabled={secondsRemaining > 0}
+ className={cn(
+ secondsRemaining > 0 && 'cursor-not-allowed opacity-50',
+ )}
+ >
+ {secondsRemaining > 0 ? `Skip (${secondsRemaining}s)` : 'Skip'}
+ </AlertDialogCancel>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
+ );
+};
diff --git a/app/lookup/[domain]/layout.tsx b/app/lookup/[domain]/layout.tsx
index 90e0fe1..7a0cf05 100644
--- a/app/lookup/[domain]/layout.tsx
+++ b/app/lookup/[domain]/layout.tsx
@@ -1,12 +1,14 @@
import { waitUntil } from '@vercel/functions';
import { ExternalLinkIcon } from 'lucide-react';
import type { Metadata } from 'next';
+import dynamic from 'next/dynamic';
import { headers } from 'next/headers';
import { notFound } from 'next/navigation';
import { type FC, type ReactNode } from 'react';
import { Card } from '@/components/ui/card';
+import { ClientOnly } from '@/components/client-only';
import { getVisitorIp, isUserBot } from '@/lib/api';
import { recordLookup } from '@/lib/search';
import { isValidDomain, isWildcardDomain } from '@/lib/utils';
@@ -18,6 +20,12 @@ import { ResultsTabs } from './_components/results-tabs';
import { ShareButton } from './_components/share-button';
import { WhoisQuickInfo } from './_components/whois-quick-info';
+const StarReminder = dynamic(() =>
+ import('./_components/star-reminder').then((m) => ({
+ default: m.StarReminder,
+ })),
+);
+
type LookupLayoutProps = {
children: ReactNode;
params: Promise<{
@@ -100,6 +108,10 @@ const LookupLayout: FC<LookupLayoutProps> = async (props) => {
</div>
</main>
<Footer />
+
+ <ClientOnly>
+ <StarReminder />
+ </ClientOnly>
</>
);
};
diff --git a/components/ui/alert-dialog.tsx b/components/ui/alert-dialog.tsx
index f1189ae..ccd5189 100644
--- a/components/ui/alert-dialog.tsx
+++ b/components/ui/alert-dialog.tsx
@@ -43,7 +43,7 @@ const AlertDialogContent = React.forwardRef<
<AlertDialogPrimitive.Content
ref={ref}
className={cn(
- 'relative z-50 grid w-full max-w-lg gap-4 rounded-t-3xl bg-white p-8 shadow-lg ring-1 ring-zinc-950/10 transition duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 dark:bg-zinc-900 dark:ring-white/10 sm:rounded-2xl',
+ 'relative z-50 grid w-full max-w-lg gap-4 rounded-3xl bg-white p-8 shadow-lg ring-1 ring-zinc-950/10 transition duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 dark:bg-zinc-900 dark:ring-white/10 sm:rounded-2xl',
className,
)}
{...props}
diff --git a/lib/analytics.ts b/lib/analytics.ts
index 08b752e..fd4a465 100644
--- a/lib/analytics.ts
+++ b/lib/analytics.ts
@@ -14,6 +14,7 @@ type Events = {
'Search Form: Submit': { domain: string };
'Share: Click': { url: string };
'Star Reminder: Click': EmptyEvent;
+ 'Star Reminder: Show': EmptyEvent;
'Star Reminder: Suppress': EmptyEvent;
'Trace: Click': { type: string; domain: string };
};
diff --git a/lib/github.ts b/lib/github.ts
index 9a736e3..314f90f 100644
--- a/lib/github.ts
+++ b/lib/github.ts
@@ -103,3 +103,82 @@ export const getGitHubSponsors = async (username: string) => {
return filteredSponsors;
};
+
+type StargazerSummary = {
+ recentStargazers: Array<{
+ name: string;
+ avatarUrl: string;
+ }>;
+ totalStars: number;
+};
+
+export const getStargazersSummary = async (
+ owner: string,
+ repo: string,
+ limit = 5,
+): Promise<StargazerSummary> => {
+ if (!env.GITHUB_TOKEN) {
+ console.warn('GITHUB_TOKEN not set; skipping GitHub stargazers');
+ return {
+ recentStargazers: Array.from({ length: limit }).map(() => ({
+ name: 'GitHub User',
+ avatarUrl: 'https://avatars.githubusercontent.com/u/33993147?v=4',
+ })),
+ totalStars: 0,
+ };
+ }
+
+ // Use GraphQL to get the most recent stargazers and total count
+ const graphqlResponse = await fetch('https://api.github.com/graphql', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ Authorization: `Bearer ${env.GITHUB_TOKEN}`,
+ },
+ body: JSON.stringify({
+ query: `
+ query StargazersSummary($owner: String!, $repo: String!, $limit: Int!) {
+ repository(owner: $owner, name: $repo) {
+ stargazerCount
+ stargazers(first: $limit, orderBy: {field: STARRED_AT, direction: DESC}) {
+ nodes {
+ login
+ name
+ avatarUrl
+ }
+ }
+ }
+ }
+ `,
+ variables: {
+ owner,
+ repo,
+ limit,
+ },
+ }),
+ });
+
+ if (!graphqlResponse.ok) {
+ const body = await graphqlResponse.text();
+ throw new Error(
+ `Failed to fetch GitHub stargazers: ${graphqlResponse.status} ${graphqlResponse.statusText}\n${body}`,
+ );
+ }
+
+ const result = await graphqlResponse.json();
+
+ if (result.errors) {
+ console.error('GraphQL errors:', result.errors);
+ throw new Error(`GraphQL errors: ${JSON.stringify(result.errors)}`);
+ }
+
+ return {
+ recentStargazers: result.data.repository.stargazers.nodes.map(
+ (user: any) => ({
+ name: user.name || user.login,
+ avatarUrl: user.avatarUrl,
+ }),
+ ),
+ totalStars: result.data.repository.stargazerCount,
+ };
+};