Full Toolkit for Next-Level Domain Analysis
Add keyboard shortcut for search input ⌨
Felix Wotschofskyb61a0bfd247e
diff --git a/components/ResultsTabs.tsx b/components/ResultsTabs.tsxindex d1bd0f7..d8ab49e 100644--- a/components/ResultsTabs.tsx+++ b/components/ResultsTabs.tsx@@ -6,11 +6,7 @@ import { useRouter, useSelectedLayoutSegment } from 'next/navigation';import type { FC } from 'react';import { useHotkeys } from 'react-hotkeys-hook';-const isAppleDevice = () => {- if (typeof window === 'undefined') return false;- const userAgent = window.navigator.userAgent;- return /Mac|iPad|iPhone|iPod/.test(userAgent);-};+import { isAppleDevice } from '@/lib/utils';const SingleTab: FC<{label: string;diff --git a/components/SearchForm.tsx b/components/SearchForm.tsxindex 74852d5..192a109 100644--- a/components/SearchForm.tsx+++ b/components/SearchForm.tsx@@ -4,12 +4,13 @@ import { Loader2 } from 'lucide-react';import { usePlausible } from 'next-plausible';import { usePathname, useRouter } from 'next/navigation';import { toASCII } from 'punycode';-import { ChangeEvent, FormEvent, useEffect, useState } from 'react';+import { ChangeEvent, FormEvent, useEffect, useRef, useState } from 'react';+import { useHotkeys } from 'react-hotkeys-hook';import { Button } from '@/components/ui/button';import { Input } from '@/components/ui/input';-import { cn, isValidDomain } from '@/lib/utils';+import { cn, isAppleDevice, isValidDomain } from '@/lib/utils';enum FormStates {Initial,@@ -33,6 +34,14 @@ const SearchForm = (props: SearchFormProps) => {const [state, setState] = useState<FormStates>(FormStates.Initial);const [error, setError] = useState(false);+ const inputRef = useRef<HTMLInputElement>(null);+ useHotkeys(+ isAppleDevice() ? 'alt+k' : 'ctrl+k',+ () => inputRef.current?.focus(),+ { preventDefault: true },+ [inputRef.current]+ );+useEffect(() => {if (props.initialValue) {setDomain(props.initialValue);@@ -79,19 +88,32 @@ const SearchForm = (props: SearchFormProps) => {return (<><form className="flex gap-3" onSubmit={handleSubmit}>- <Input- className="flex-[3]"- type="text"- required- placeholder="example.com"- aria-label="Domain"- value={domain}- onInput={(event: ChangeEvent<HTMLInputElement>) =>- setDomain(event.target.value)- }- disabled={state !== FormStates.Initial}- autoFocus={props.autofocus}- />+ <div className="relative flex-[3]">+ <Input+ ref={inputRef}+ className="w-full"+ type="text"+ required+ placeholder="example.com"+ aria-label="Domain"+ value={domain}+ onInput={(event: ChangeEvent<HTMLInputElement>) =>+ setDomain(event.target.value)+ }+ disabled={state !== FormStates.Initial}+ autoFocus={props.autofocus}+ />++ <kbd className="pointer-events-none absolute right-3 top-1/2 hidden h-5 -translate-y-1/2 select-none items-center gap-1 rounded border bg-muted px-1.5 font-mono text-[10px] font-medium opacity-100 sm:flex">+ {isAppleDevice() ? (+ <>+ <span className="text-xs">⌘</span>K+ </>+ ) : (+ 'ctrl+k'+ )}+ </kbd>+ </div><ButtonclassName="flex-[1]"type="submit"diff --git a/lib/utils.ts b/lib/utils.tsindex 4f49246..6a8f137 100644--- a/lib/utils.ts+++ b/lib/utils.ts@@ -9,3 +9,9 @@ export const isValidDomain = (domain: string) =>/^(\*\.)?(((?!-))(xn--|_)?[a-z0-9-]{0,61}[a-z0-9]{1,1}\.)*(xn--)?([a-z0-9][a-z0-9\-]{0,60}|[a-z0-9-]{1,30}\.[a-z]{2,})$/.test(domain);++export const isAppleDevice = () => {+ if (typeof window === 'undefined') return false;+ const userAgent = window.navigator.userAgent;+ return /Mac|iPad|iPhone|iPod/.test(userAgent);+};