1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 12:56:41 +07:00

removed tag reducer

This commit is contained in:
Fedor Katurov 2022-01-03 13:15:17 +07:00
parent 11b39b8766
commit 31e433af3e
17 changed files with 41 additions and 192 deletions

View file

@ -0,0 +1,23 @@
import useSWR from 'swr';
import { API } from '~/constants/api';
import { apiGetTagSuggestions } from '~/api/tags';
import { useEffect, useState } from 'react';
export const useTagAutocomplete = (input: string, exclude: string[]): string[] => {
const [search, setSearch] = useState('');
useEffect(() => {
const timeout = setTimeout(() => setSearch(input), 200);
return () => clearTimeout(timeout);
}, [input]);
const { data } = useSWR(
`${API.TAG.AUTOCOMPLETE}?tag=${search}&exclude=${exclude.join(',')}`,
async () => {
const result = await apiGetTagSuggestions({ search, exclude });
return result.tags || [];
}
);
return data || [];
};

View file

@ -4,8 +4,7 @@ import { API } from '~/constants/api';
import { flatten, isNil } from 'ramda';
import useSWRInfinite from 'swr/infinite';
import { useCallback } from 'react';
import { apiGetNodesOfTag } from '~/redux/tag/api';
import { COMMENTS_DISPLAY } from '~/constants/node';
import { apiGetNodesOfTag } from '~/api/tags';
const PAGE_SIZE = 10;