add is loading + not found

This commit is contained in:
hamid zarghami
2026-02-07 16:59:18 +03:30
parent 433bd65cb0
commit aae0706e03
+13 -2
View File
@@ -7,20 +7,21 @@ import { Link } from 'react-router-dom'
import { Pages } from '../../config/Pages' import { Pages } from '../../config/Pages'
import { useOutsideClick } from '../../hooks/useOutSideClick' import { useOutsideClick } from '../../hooks/useOutSideClick'
import { clx } from '../../helpers/utils' import { clx } from '../../helpers/utils'
import MoonLoader from 'react-spinners/MoonLoader'
const Search: FC = () => { const Search: FC = () => {
const { t } = useTranslation('global') const { t } = useTranslation('global')
const [search, setSearch] = useState<string>('') const [search, setSearch] = useState<string>('')
const [showSearch, setShowSearch] = useState<boolean>(false) const [showSearch, setShowSearch] = useState<boolean>(false)
const { data } = useGetServiceSearch(search) const { data, isPending } = useGetServiceSearch(search)
const ref = useOutsideClick(() => { const ref = useOutsideClick(() => {
setShowSearch(false) setShowSearch(false)
}) })
useEffect(() => { useEffect(() => {
if (data?.data && data?.data?.services?.length) { if (search.length) {
setShowSearch(true) setShowSearch(true)
} else { } else {
setShowSearch(false) setShowSearch(false)
@@ -41,6 +42,16 @@ const Search: FC = () => {
showSearch && showSearch &&
<div ref={ref} className='absolute shadow bg-white top-[100%] rounded-xl right-0 w-[270px] p-4 flex flex-col gap-4 overflow-y-auto max-h-screen'> <div ref={ref} className='absolute shadow bg-white top-[100%] rounded-xl right-0 w-[270px] p-4 flex flex-col gap-4 overflow-y-auto max-h-screen'>
{ {
isPending ?
<div className='flex justify-center'>
<MoonLoader color='black' size={20} />
</div>
:
data?.data?.services?.length === 0 ?
<div className='flex justify-center text-sm text-gray-400'>
نتیجه ای یافت نشد.
</div>
:
data?.data?.services?.map((item: ServiceType, index: number) => { data?.data?.services?.map((item: ServiceType, index: number) => {
return ( return (
<Link onClick={() => setShowSearch(false)} to={Pages.services.detail + item.slug} key={item.id} className={clx( <Link onClick={() => setShowSearch(false)} to={Pages.services.detail + item.slug} key={item.id} className={clx(