Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev-deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
KartVen committed Dec 3, 2024
2 parents c0842a2 + faa4a69 commit c3d2fb0
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/components/layout/navbar/middle/SearchBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use client';
import React, { useEffect, useState } from 'react';
import React, { useEffect, useMemo, useState } from 'react';
import { SlMagnifier } from 'react-icons/sl';
import Modal from '@/components/utils/Modal';
import SearchBar from '@/components/utils/SearchBar';
Expand All @@ -17,31 +17,31 @@ export default function SearchBlock() {
const openModal = () => setIsOpen(true);
const closeModal = () => setIsOpen(false);

const searchParams = {
page: 1,
size: DEFAULT_PAGE_SIZE,
sort: MaterialSortField.ID,
sort_direction: SortDirection.ASC,
};
const SEARCH_PARAMS = useMemo(
() => ({
page: 1,
size: DEFAULT_PAGE_SIZE,
sort: MaterialSortField.ID,
sort_direction: SortDirection.ASC,
}),
[],
);

const { data: materials, status, fetch: fetchMaterials } = useFetchState<Pageable<MaterialSearch>>();

if (!isOpen) return <></>;

useEffect(() => {
isOpen &&
fetchMaterials(() => {
return MaterialService.getMaterials(searchParams);
});
}, []);
if (isOpen) {
fetchMaterials(() => MaterialService.getMaterials(SEARCH_PARAMS));
}
}, [isOpen, fetchMaterials, SEARCH_PARAMS]);

if (status === Status.PENDING)
if (isOpen && status === Status.PENDING)
return (
<div className="pt-8">
<Loading scale="small" />
</div>
);
if (status === Status.ERROR || !materials) return <Error />;
if (isOpen && (status === Status.ERROR || !materials)) return <Error />;

return (
<>
Expand All @@ -62,7 +62,7 @@ export default function SearchBlock() {
>
<div className="flex flex-col gap-4">
<h2 className="text-lg font-semibold">{TEXT.WHAT_LOOKING_FOR}</h2>
<SearchBar onClose={closeModal} data={materials.content} searchFields={['title', 'description']} />
<SearchBar onClose={closeModal} data={materials!.content} searchFields={['title', 'description']} />
</div>
</Modal>
)}
Expand Down

0 comments on commit c3d2fb0

Please sign in to comment.