Merge branch 'master' of https://github.com/payloadcms/payload into fix/search-row-titles

This commit is contained in:
PatrikKozak
2023-03-13 14:30:05 -04:00
3 changed files with 16 additions and 4 deletions

View File

@@ -12,7 +12,7 @@ export const requests = {
}
return fetch(`${url}${query}`, {
credentials: 'include',
headers: options.headers,
...options,
});
},

View File

@@ -93,7 +93,10 @@ export const DocumentDrawerContent: React.FC<DocumentDrawerProps> = ({
if (isError) return null;
return (
<DocumentInfoProvider collection={collectionConfig}>
<DocumentInfoProvider
collection={collectionConfig}
id={id}
>
<RenderCustomComponent
DefaultComponent={DefaultEdit}
CustomComponent={collectionConfig.admin?.components?.views?.Edit}

View File

@@ -43,12 +43,15 @@ const usePayloadAPI: UsePayloadAPI = (url, options = {}) => {
});
useEffect(() => {
const abortController = new AbortController();
const fetchData = async () => {
setIsError(false);
setIsLoading(true);
try {
const response = await requests.get(`${url}${search}`, {
signal: abortController.signal,
headers: {
'Accept-Language': i18n.language,
},
@@ -62,8 +65,10 @@ const usePayloadAPI: UsePayloadAPI = (url, options = {}) => {
setData(json);
setIsLoading(false);
} catch (error) {
setIsError(true);
setIsLoading(false);
if (!abortController.signal.aborted) {
setIsError(true);
setIsLoading(false);
}
}
};
@@ -73,6 +78,10 @@ const usePayloadAPI: UsePayloadAPI = (url, options = {}) => {
setIsError(false);
setIsLoading(false);
}
return () => {
abortController.abort();
};
}, [url, locale, search, i18n.language]);
return [{ data, isLoading, isError }, { setParams }];