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:
parent
11b39b8766
commit
31e433af3e
17 changed files with 41 additions and 192 deletions
23
src/hooks/tag/useTagAutocomplete.ts
Normal file
23
src/hooks/tag/useTagAutocomplete.ts
Normal 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 || [];
|
||||
};
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue