Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/NotAvailableMarker.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cn } from '../helpers/cn.helper';
import { cn } from '../helpers/className/cn.helper';

const NotAvailableMarker: React.FC<{
className?: string;
Expand Down
35 changes: 24 additions & 11 deletions src/components/SearchForm.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { FormEvent, useEffect, useRef, useState } from 'react';
import { useNavigate, useSearchParams } from 'react-router-dom';
import { useHistoryModal } from '../providers/HistoryProvider';
import { isDomainValid } from '../helpers/isDomainValid.helper';
import { isDomainValid } from '../helpers/domain/isDomainValid.helper';
import { domainPipe } from '../helpers/domain/domainPipe';
import { extractDomain } from '../helpers/domain/extractDomain';

const SearchForm = () => {
const [searchParams, setSearchParams] = useSearchParams();
const [searchQuery, setSearchQuery] = useState<string>('');
const navigate = useNavigate();
const inputRef = useRef<HTMLInputElement | null>(null);
const { historyPush } = useHistoryModal();
const [isValid, setIsValid] = useState<boolean>(false);
const [isValid, setIsValid] = useState<boolean>(true);

useEffect(() => {
window.addEventListener('keyup', handleKeyUp);
Expand All @@ -18,18 +20,27 @@ const SearchForm = () => {
}, []);

useEffect(() => {
setIsValid(false);
if (!searchQuery) {
setIsValid(true);
return;
}
const transformedDomain = domainPipe(extractDomain)(searchQuery);

if (isDomainValid(searchQuery)) setIsValid(true);
setIsValid(isDomainValid(transformedDomain));
}, [searchQuery]);

const handleSubmit = (event: FormEvent<HTMLFormElement>): void => {
event.preventDefault();
if (searchParams.get('domain') === searchQuery && !isValid) return;

historyPush(searchQuery);
setSearchParams({ domain: searchQuery });
navigate(`/results?domain=${encodeURIComponent(searchQuery)}`);
const transformedDomain = domainPipe(extractDomain)(searchQuery);
const isValid = isDomainValid(transformedDomain);
if (searchParams.get('domain') === transformedDomain || !isValid) {
return;
}

historyPush(transformedDomain);
setSearchParams({ domain: transformedDomain });
navigate(`/results?domain=${encodeURIComponent(transformedDomain)}`);
setTimeout(() => window.scroll(0, 0), 50);
};

Expand All @@ -42,13 +53,15 @@ const SearchForm = () => {
return (
<form className="flex gap-2 w-[30rem]" onSubmit={handleSubmit}>
<label
className="flex items-center input input-sm input-bordered w-full"
className={`flex items-center input input-sm input-bordered w-full ${
!isValid ? 'input-error' : ''
}`}
style={{ outline: 'none', boxShadow: 'none' }}
>
<input
type="text"
className="grow placeholder:text-xs "
placeholder="Type a domain..."
placeholder="Type a valid domain..."
autoFocus
value={searchQuery}
onChange={event => setSearchQuery(event.target.value.toLowerCase())}
Expand All @@ -59,7 +72,7 @@ const SearchForm = () => {
<button
className="btn btn-sm btn-primary"
type="submit"
disabled={searchQuery && isValid ? false : true}
disabled={searchQuery ? false : true}
>
Accio!
</button>
Expand Down
2 changes: 1 addition & 1 deletion src/components/ShortKeys.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { IoReturnDownBackSharp } from 'react-icons/io5';
import { Shortcut } from '../enums/Shortcut.enum';
import { cn } from '../helpers/cn.helper';
import { cn } from '../helpers/className/cn.helper';

const ShortKeys: React.FC<{ keys: Shortcut[]; className?: string }> = ({
keys,
Expand Down
2 changes: 1 addition & 1 deletion src/components/SslTable.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useMemo } from 'react';
import { getDays } from '../helpers/getDays';
import { getDays } from '../helpers/date/getDays';
import { SslStatus } from '../enums/SslStatus.enum';
import Loading from './Loading';

Expand Down
2 changes: 1 addition & 1 deletion src/components/WhoisTable.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useMemo } from 'react';
import { getDays } from '../helpers/getDays';
import { getDays } from '../helpers/date/getDays';
import Loading from './Loading';
const WhoisTable: React.FC<{
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions src/helpers/domain/domainPipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { PipeFunction } from '../../types/PipeFunction';

export const domainPipe =
<T>(...fns: PipeFunction<T>[]) =>
(x: T): T =>
fns.reduce((result, nextFn) => nextFn(result), x);
5 changes: 5 additions & 0 deletions src/helpers/domain/extractDomain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const extractDomain = (url: string): string => {
const domainRegex = /^(?:https?:\/\/)?(?:www\.)?([^/?#]+)/;
const match = url.match(domainRegex);
return match ? match[1] : '';
};
2 changes: 1 addition & 1 deletion src/hoc/H1.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { ReactNode } from 'react';
import { cn } from '../helpers/cn.helper';
import { cn } from '../helpers/className/cn.helper';

export const H1: React.FC<{ children: ReactNode; className?: string }> = ({
className,
Expand Down
2 changes: 1 addition & 1 deletion src/hoc/ViewContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { ReactNode } from 'react';
import { cn } from '../helpers/cn.helper';
import { cn } from '../helpers/className/cn.helper';

const ViewContainer: React.FC<{ children: ReactNode; className?: string }> = ({
children,
Expand Down
1 change: 1 addition & 0 deletions src/types/PipeFunction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type PipeFunction<T> = (input: T) => T;
16 changes: 15 additions & 1 deletion tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,21 @@ export default {
content: ['./index.html', './src/**/*.{js,ts,jsx,tsx}'],
plugins: [daisyui],
theme: {
extend: {},
extend: {
keyframes: {
// Define the keyframes for the animation
shake: {
'0%, 100%': { transform: 'translateX(0)' },
'25%': { transform: 'translateX(-4px)' },
'50%': { transform: 'translateX(4px)' },
'75%': { transform: 'translateX(-4px)' },
},
},
animation: {
// Create a class for the animation
shake: 'shake 0.5s ease-in-out',
},
},
},
daisyui: {
themes: [
Expand Down
Loading