1
0
Fork 0
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:
Fedor Katurov 2021-11-21 21:23:07 +07:00
parent 2eb10c4da7
commit 64cc47a116
5 changed files with 45 additions and 45 deletions

View 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 };
};

View 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 };
};