import { Alert, AspectRatio, Divider, Group, Skeleton, Space, Stack, em, } from "@mantine/core"; import { useMediaQuery } from "@mantine/hooks"; import { IconInfoCircle } from "@tabler/icons-react"; import { usePubSub } from "create-pubsub/react"; import { Suspense, lazy, useMemo } from "react"; import { Pattern, match } from "ts-pattern"; import { searchResultsPubSub, searchStatePubSub, settingsPubSub, } from "../../../modules/pubSub"; import type { SearchResults } from "../../../modules/search"; import type { Settings } from "../../../modules/settings"; const ImageResultsList = lazy(() => import("./Graphical/ImageResultsList")); const SearchResultsList = lazy(() => import("./Textual/SearchResultsList")); export default function SearchResultsSection() { const [searchResults] = usePubSub(searchResultsPubSub); const [searchState] = usePubSub(searchStatePubSub); const [settings] = usePubSub(settingsPubSub); return useMemo( () => match(searchState) .with("running", () => ) .with("failed", () => ) .with("completed", () => ( )) .otherwise(() => null), [searchState, searchResults, settings], ); } function RunningSearchContent() { const hasSmallScreen = useMediaQuery(`(max-width: ${em(530)})`); const numberOfSquareSkeletons = hasSmallScreen ? 4 : 6; const skeletonIds = Array.from( { length: numberOfSquareSkeletons }, (_, i) => `skeleton-${i}`, ); return ( <> {skeletonIds.map((id) => ( ))} ); } function FailedSearchContent() { return ( <> } > It looks like your current search did not return any results. Try refining your search by adding more keywords or rephrasing your query. ); } function CompletedSearchContent({ searchResults, settings, }: { searchResults: SearchResults; settings: Settings; }) { return ( <> {match([settings.enableImageSearch, searchResults.imageResults.length]) .with([true, Pattern.number.positive()], () => ( )) .otherwise(() => null)} ); }