mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +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
|
@ -1,11 +1,8 @@
|
|||
import React, { FC } from 'react';
|
||||
import { INode } from '~/redux/types';
|
||||
import { NodeRelatedContextProvider } from '~/utils/context/NodeRelatedContextProvider';
|
||||
import { ApiGetNodeRelatedResult, INodeRelated } from '~/redux/node/types';
|
||||
import useSWR from 'swr';
|
||||
import { API } from '~/constants/api';
|
||||
import { api } from '~/utils/api';
|
||||
import { AxiosResponse } from 'axios';
|
||||
import { INodeRelated } from '~/redux/node/types';
|
||||
import { useGetNodeRelated } from '~/utils/hooks/data/useGetNodeRelated';
|
||||
|
||||
interface NodeRelatedProviderProps {
|
||||
id: INode['id'];
|
||||
|
@ -17,16 +14,10 @@ const defaultValue: INodeRelated = {
|
|||
};
|
||||
|
||||
const NodeRelatedProvider: FC<NodeRelatedProviderProps> = ({ id, children }) => {
|
||||
const { data, isValidating } = useSWR<AxiosResponse<ApiGetNodeRelatedResult>>(
|
||||
API.NODE.RELATED(id),
|
||||
api.get
|
||||
);
|
||||
const { related, isLoading } = useGetNodeRelated(id);
|
||||
|
||||
return (
|
||||
<NodeRelatedContextProvider
|
||||
related={data?.data?.related || defaultValue}
|
||||
isLoading={isValidating}
|
||||
>
|
||||
<NodeRelatedContextProvider related={related || defaultValue} isLoading={isLoading}>
|
||||
{children}
|
||||
</NodeRelatedContextProvider>
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue