{ "version": 3, "sources": ["../../assets/scripts/store/features/search/SearchForm/SearchResults.tsx", "../../assets/scripts/store/hooks/useDebounce.ts", "../../assets/scripts/store/features/search/SearchForm/index.tsx"], "sourcesContent": ["import fetcher from '@app/utils/fetcher';\r\nimport Loader from '@store/components/Loader';\r\nimport type { FC} from 'react';\r\nimport React, { createRef, useEffect, useState } from 'react';\r\nimport { useTranslation } from 'react-i18next';\r\nimport useSWR from 'swr';\r\n\r\nimport type { ISearchResult, ISearchResultItem } from './types';\r\n\r\ninterface IProps {\r\n apiUrl: string;\r\n searchTerm: string;\r\n searchLink: string;\r\n}\r\n\r\nconst ItemsGroup: FC<{ items: ISearchResultItem[]; title: string }> = ({ items, title }) => {\r\n if (!items || items.length === 0) return <>;\r\n\r\n return (\r\n
\r\n \r\n {title}\r\n \r\n
\r\n {items.map(item => (\r\n \r\n ))}\r\n
\r\n
\r\n );\r\n};\r\n\r\nconst SearchListItem: FC = props => {\r\n const [hasImage, setValidPicture] = useState(!!props.imageUrl);\r\n\r\n return (\r\n \r\n
\r\n {hasImage && props.imageUrl && (\r\n setValidPicture(false)}\r\n />\r\n )}\r\n
\r\n \r\n {props.name}\r\n \r\n \r\n );\r\n};\r\n\r\nexport default function SearchResults({ apiUrl, searchTerm, searchLink }: IProps) {\r\n const { t } = useTranslation();\r\n\r\n const ref = createRef();\r\n const [isFocused, setFocused] = useState(true);\r\n\r\n const { data, error } = useSWR({ apiUrl, searchTerm }, ({ apiUrl, searchTerm }) =>\r\n fetcher(apiUrl, { searchParams: { searchTerm } })\r\n );\r\n\r\n useEffect(() => {\r\n const handler = (event: MouseEvent) => {\r\n if (ref.current?.contains(event.target as Node)) {\r\n event.stopPropagation();\r\n return;\r\n }\r\n\r\n if (isFocused) {\r\n setFocused(false);\r\n }\r\n };\r\n\r\n document.addEventListener('click', handler, false);\r\n return () => document.removeEventListener('click', handler);\r\n });\r\n\r\n if (error) {\r\n console.error(error);\r\n return <>;\r\n }\r\n\r\n return (\r\n \r\n {!data && (\r\n
\r\n \r\n
\r\n )}\r\n {data && (\r\n <>\r\n
\r\n \r\n \r\n {data.products.length === 0 && data.categories.length === 0 && (\r\n
\r\n Neboli n\u00E1jden\u00E9 \u017Eiadne v\u00FDsledky\r\n
\r\n )}\r\n
\r\n {(data.products.length > 0 || data.categories.length > 0) && (\r\n
\r\n \r\n {t('ToShowAllResults')}\r\n \r\n
\r\n )}\r\n \r\n )}\r\n \r\n );\r\n}\r\n", "import { useEffect, useState } from 'react';\r\n\r\nexport function useDebounce(value: T, delay = 100): T {\r\n // State and setters for debounced value\r\n const [debouncedValue, setDebouncedValue] = useState(value);\r\n\r\n useEffect(\r\n () => {\r\n // Update debounced value after delay\r\n const handler = setTimeout(() => {\r\n setDebouncedValue(value);\r\n }, delay);\r\n\r\n // Cancel the timeout if value changes (also on delay change or unmount)\r\n // This is how we prevent debounced value from updating if value is changed ...\r\n // .. within the delay period. Timeout gets cleared and restarted.\r\n return () => {\r\n clearTimeout(handler);\r\n };\r\n },\r\n [value, delay] // Only re-call effect if value or delay changes\r\n );\r\n\r\n return debouncedValue;\r\n}\r\n", "import SearchResults from '@features/search/SearchForm/SearchResults';\r\nimport { useDebounce } from '@store/hooks/useDebounce';\r\nimport React, { useMemo, useState } from 'react';\r\nimport { useTranslation } from 'react-i18next';\r\n\r\nexport interface SearchFormProps {\r\n apiUrl: string;\r\n formUrl: string;\r\n}\r\n\r\nexport default function SearchForm({ apiUrl, formUrl }: SearchFormProps) {\r\n const { t } = useTranslation();\r\n\r\n const [searchTerm, setSearchTerm] = useState();\r\n const debounceSearchTerm = useDebounce(searchTerm, 300);\r\n\r\n const searchLink = useMemo(() => {\r\n const url = new URL(formUrl, window.location.origin);\r\n url.searchParams.set('searchTerm', debounceSearchTerm);\r\n return url.toString();\r\n }, [debounceSearchTerm, formUrl]);\r\n\r\n return (\r\n
\r\n
\r\n
\r\n setSearchTerm(event.currentTarget.value)}\r\n />\r\n
\r\n \r\n \r\n \r\n
\r\n\r\n {debounce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