mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 21:06:42 +07:00
made node editor use SWR
This commit is contained in:
parent
2eb10c4da7
commit
64cc47a116
5 changed files with 45 additions and 45 deletions
19
src/utils/hooks/data/useGetNode.ts
Normal file
19
src/utils/hooks/data/useGetNode.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
import { INode } from '~/redux/types';
|
||||
import useSWR from 'swr';
|
||||
import { AxiosResponse } from 'axios';
|
||||
import { ApiGetNodeResponse } from '~/redux/node/types';
|
||||
import { API } from '~/constants/api';
|
||||
import { api } from '~/utils/api';
|
||||
|
||||
export const useGetNode = (id?: INode['id']) => {
|
||||
const { data, isValidating: isLoading } = useSWR<AxiosResponse<ApiGetNodeResponse>>(
|
||||
API.NODE.GET_NODE(id || ''),
|
||||
api.get
|
||||
);
|
||||
|
||||
if (!id) {
|
||||
return { node: undefined, isLoading: false };
|
||||
}
|
||||
|
||||
return { node: data?.data.node, isLoading };
|
||||
};
|
15
src/utils/hooks/data/useGetNodeRelated.ts
Normal file
15
src/utils/hooks/data/useGetNodeRelated.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import { INode } from '~/redux/types';
|
||||
import useSWR from 'swr';
|
||||
import { AxiosResponse } from 'axios';
|
||||
import { ApiGetNodeRelatedResult } from '~/redux/node/types';
|
||||
import { API } from '~/constants/api';
|
||||
import { api } from '~/utils/api';
|
||||
|
||||
export const useGetNodeRelated = (id?: INode['id']) => {
|
||||
const { data, isValidating: isLoading } = useSWR<AxiosResponse<ApiGetNodeRelatedResult>>(
|
||||
API.NODE.RELATED(id),
|
||||
api.get
|
||||
);
|
||||
|
||||
return { related: data?.data.related, isLoading };
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue