Added metadata creation (#2086)

* Reworked metadata creation

* Fix from PR

* Removed consolelog
This commit is contained in:
Lucas Bordeau
2023-10-17 20:59:41 +02:00
committed by GitHub
parent c4fa36402b
commit a40516df83
24 changed files with 286 additions and 164 deletions

View File

@ -0,0 +1,46 @@
import { useMemo } from 'react';
import { useQuery } from '@apollo/client';
import {
MetadataObjectsQuery,
MetadataObjectsQueryVariables,
} from '~/generated-metadata/graphql';
import { GET_ALL_OBJECTS } from '../graphql/queries';
import { formatPagedMetadataObjectsToMetadataObjects } from '../utils/formatPagedMetadataObjectsToMetadataObjects';
import { useApolloMetadataClient } from './useApolloClientMetadata';
// TODO: test fetchMore
export const useFindAllMetadata = () => {
const apolloMetadataClient = useApolloMetadataClient();
const { data, fetchMore: fetchMoreInternal } = useQuery<
MetadataObjectsQuery,
MetadataObjectsQueryVariables
>(GET_ALL_OBJECTS, {
client: apolloMetadataClient ?? ({} as any),
skip: !apolloMetadataClient,
});
const hasMore = data?.objects?.pageInfo?.hasNextPage;
const fetchMore = () =>
fetchMoreInternal({
variables: {
afterCursor: data?.objects?.pageInfo?.endCursor,
},
});
const metadataObjects = useMemo(() => {
return formatPagedMetadataObjectsToMetadataObjects({
pagedMetadataObjects: data,
});
}, [data]);
return {
metadataObjects,
hasMore,
fetchMore,
};
};