mirror of
https://github.com/strapi/strapi.git
synced 2025-12-28 07:33:17 +00:00
Chore: Use named export
This commit is contained in:
parent
32523eff19
commit
95970ec91b
@ -1,5 +1,5 @@
|
||||
export { default as useConfigurations } from './useConfigurations';
|
||||
export { default as useModels } from './useModels';
|
||||
export { useModels } from './useModels';
|
||||
export { default as useFetchPermissionsLayout } from './useFetchPermissionsLayout';
|
||||
export { default as useFetchRole } from './useFetchRole';
|
||||
export { default as useMenu } from './useMenu';
|
||||
|
||||
@ -1,47 +1 @@
|
||||
import { useAPIErrorHandler, useFetchClient, useNotification } from '@strapi/helper-plugin';
|
||||
import { useQueries } from 'react-query';
|
||||
|
||||
const useModels = () => {
|
||||
const { get } = useFetchClient();
|
||||
const { formatAPIError } = useAPIErrorHandler();
|
||||
const toggleNotification = useNotification();
|
||||
const queries = useQueries(
|
||||
['components', 'content-types'].map((type) => {
|
||||
return {
|
||||
queryKey: [type],
|
||||
async queryFn() {
|
||||
const {
|
||||
data: { data },
|
||||
} = await get(`/content-manager/${type}`);
|
||||
|
||||
return data;
|
||||
},
|
||||
onError(error) {
|
||||
toggleNotification({
|
||||
type: 'warning',
|
||||
message: formatAPIError(error),
|
||||
});
|
||||
},
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
const [components, contentTypes] = queries;
|
||||
const isLoading = components.isLoading || contentTypes.isLoading;
|
||||
|
||||
const collectionTypes = (contentTypes?.data ?? []).filter(
|
||||
(contentType) => contentType.kind === 'collectionType' && contentType.isDisplayed
|
||||
);
|
||||
const singleTypes = (contentTypes?.data ?? []).filter(
|
||||
(contentType) => contentType.kind !== 'collectionType' && contentType.isDisplayed
|
||||
);
|
||||
|
||||
return {
|
||||
isLoading,
|
||||
components: components.data,
|
||||
collectionTypes,
|
||||
singleTypes,
|
||||
};
|
||||
};
|
||||
|
||||
export default useModels;
|
||||
export * from './useModels';
|
||||
|
||||
47
packages/core/admin/admin/src/hooks/useModels/useModels.js
Normal file
47
packages/core/admin/admin/src/hooks/useModels/useModels.js
Normal file
@ -0,0 +1,47 @@
|
||||
import { useAPIErrorHandler, useFetchClient, useNotification } from '@strapi/helper-plugin';
|
||||
import { useQueries } from 'react-query';
|
||||
|
||||
export function useModels() {
|
||||
const { get } = useFetchClient();
|
||||
const { formatAPIError } = useAPIErrorHandler();
|
||||
const toggleNotification = useNotification();
|
||||
const queries = useQueries(
|
||||
['components', 'content-types'].map((type) => {
|
||||
return {
|
||||
queryKey: [type],
|
||||
async queryFn() {
|
||||
const {
|
||||
data: { data },
|
||||
} = await get(`/content-manager/${type}`);
|
||||
|
||||
return data;
|
||||
},
|
||||
onError(error) {
|
||||
toggleNotification({
|
||||
type: 'warning',
|
||||
message: formatAPIError(error),
|
||||
});
|
||||
},
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
const [components, contentTypes] = queries;
|
||||
const isLoading = components.isLoading || contentTypes.isLoading;
|
||||
|
||||
const collectionTypes = (contentTypes?.data ?? []).filter(
|
||||
(contentType) => contentType.kind === 'collectionType' && contentType.isDisplayed
|
||||
);
|
||||
const singleTypes = (contentTypes?.data ?? []).filter(
|
||||
(contentType) => contentType.kind !== 'collectionType' && contentType.isDisplayed
|
||||
);
|
||||
|
||||
return {
|
||||
isLoading,
|
||||
components: components.data,
|
||||
collectionTypes,
|
||||
singleTypes,
|
||||
};
|
||||
}
|
||||
|
||||
export default useModels;
|
||||
Loading…
x
Reference in New Issue
Block a user