Skip to content

Commit

Permalink
Makes loader more responsive
Browse files Browse the repository at this point in the history
  • Loading branch information
Aryan51203 committed Oct 10, 2024
1 parent d08a1db commit 95bbed7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
"use client";

import DomainSearchResults from "@/components/DomainSearchResults";
import { SearchInput } from "@/components/SearchInput";
import Link from "next/link";
import { useState } from "react";

export default function Home({ searchParams }: { searchParams: { [key: string]: string | string[] | undefined } }) {
const domainQuery = searchParams?.domain?.toString();
const [isLoading, setIsLoading] = useState(true);
return (
<div style={{ display: "flex", minHeight: "100vh", flexDirection: "column", alignItems: "center" }}>
<h2 style={{ padding: "2rem" }}>
<Link href="/" className="defaultcolor">
DKIM Archive
</Link>
</h2>
<SearchInput domainQuery={domainQuery} />
<DomainSearchResults domainQuery={domainQuery} />
<SearchInput domainQuery={domainQuery} setIsLoading={setIsLoading} />
<DomainSearchResults domainQuery={domainQuery} isLoading={isLoading} setIsLoading={setIsLoading} />
<div style={{ textAlign: "center", marginTop: "5rem", fontSize: "0.8rem" }}>
<hr style={{ width: "50%", margin: "1rem auto", borderTop: "1px solid black" }} />
<div>
Expand Down
10 changes: 8 additions & 2 deletions src/components/DomainSearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import { parseDkimTagList } from "@/lib/utils";
import { useEffect, useState } from "react";
import { DomainSearchResultsDisplay } from "./DomainSearchResultsDisplay";

interface DomainSearchResultsProps {
domainQuery: string | undefined;
isLoading: boolean;
setIsLoading: (isLoading: boolean) => void;
}

function dkimValueHasPrivateKey(dkimValue: string): boolean {
return !!parseDkimTagList(dkimValue).p;
}
Expand All @@ -18,8 +24,8 @@ async function DomainResultsLoader(domainQuery: string | undefined) {
return records;
}

function DomainSearchResults({ domainQuery }: { domainQuery: string | undefined }) {
const [isLoading, setIsLoading] = useState(true);
function DomainSearchResults({ domainQuery, isLoading, setIsLoading }: DomainSearchResultsProps) {
// const [isLoading, setIsLoading] = useState(true);
const [records, setRecords] = useState<RecordWithSelector[]>([]);
const [cursor, setCursor] = useState<number | null>(null);

Expand Down
4 changes: 3 additions & 1 deletion src/components/SearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import debounce from "lodash/debounce"; // Importing lodash's debounce

interface SearchFormProps {
domainQuery: string | undefined;
setIsLoading: (isLoading: boolean) => void;
}

export const SearchInput: React.FC<SearchFormProps> = ({ domainQuery }) => {
export const SearchInput: React.FC<SearchFormProps> = ({ domainQuery, setIsLoading }) => {
const router = useRouter();
const [searchResults, setSearchResults] = useState<AutocompleteResults>([]);
const [inputValue, setInputValue] = useState<string>(domainQuery || "");
Expand Down Expand Up @@ -37,6 +38,7 @@ export const SearchInput: React.FC<SearchFormProps> = ({ domainQuery }) => {

const onChange = (_event: React.SyntheticEvent, value: string | null) => {
if (value) {
setIsLoading(true);
router.push(`/?domain=${value}`);
}
};
Expand Down

0 comments on commit 95bbed7

Please sign in to comment.