Skip to content
Snippets Groups Projects
Commit 1a316561 authored by Tadeusz Miesiąc's avatar Tadeusz Miesiąc
Browse files

feat(publications): pr fixes

parent be986a76
No related branches found
No related tags found
2 merge requests!223reset the pin numbers before search results are fetch (so the results will be...,!117Feature/project info publications list submap select
Pipeline #85318 passed
import { ChangeEvent, useCallback, useEffect, useState } from 'react';
import lensIcon from '@/assets/vectors/icons/lens.svg';
import { useDebounce } from '@/hooks/useDebounce';
import { useDebounce } from 'use-debounce';
import { useAppDispatch } from '@/redux/hooks/useAppDispatch';
import { getPublications } from '@/redux/publications/publications.thunks';
import { useAppSelector } from '@/redux/hooks/useAppSelector';
......@@ -14,11 +14,13 @@ import Image from 'next/image';
import { setPublicationSearchValue } from '@/redux/publications/publications.slice';
import { DEFAULT_PAGE_SIZE } from '../PublicationsTable/PublicationsTable.constants';
const DEFAULT_DELAY = 500;
export const PublicationsSearch = (): JSX.Element => {
const dispatch = useAppDispatch();
const isLoading = useAppSelector(isLoadingSelector);
const [value, setValue] = useState('');
const debouncedValue = useDebounce<string>(value);
const [debouncedValue] = useDebounce<string>(value, DEFAULT_DELAY);
const sortColumn = useAppSelector(sortColumnSelector);
const sortOrder = useAppSelector(sortOrderSelector);
const selectedId = useAppSelector(selectedModelIdSelector);
......
import { useEffect, useState } from 'react';
const DEFAULT_DELAY = 500;
export const useDebounce = <T>(value: T, delay?: number): T => {
const [debouncedValue, setDebouncedValue] = useState<T>(value);
useEffect(() => {
const timer = setTimeout(() => setDebouncedValue(value), delay || DEFAULT_DELAY);
return () => {
clearTimeout(timer);
};
}, [value, delay]);
return debouncedValue;
};
......@@ -3,21 +3,19 @@ import { PerfectSearchParams } from '@/types/search';
import { Point } from '@/types/map';
import { GetPublicationsParams, PublicationsQueryParams } from './publications/publications.types';
const getPublicationsURLSearchParams = ({
page,
sortColumn,
sortOrder,
level,
length,
search,
}: PublicationsQueryParams): URLSearchParams => {
const getPublicationsURLSearchParams = (
providedParams: PublicationsQueryParams,
): URLSearchParams => {
const params = new URLSearchParams();
if (page) params.append('page', page.toString());
if (sortColumn) params.append('sortColumn', sortColumn);
if (sortOrder) params.append('sortOrder', sortOrder);
if (level) params.append('level', level.toString());
if (length) params.append('length', length.toString());
if (search) params.append('search', search);
const validProvidedParamsArray = Object.entries(providedParams).filter(([, value]) =>
Boolean(value),
);
validProvidedParamsArray.forEach(([key, value]) => {
params.append(key, value.toString());
});
return params;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment