perf(CollectionHistoryProvider): remove loading

This commit is contained in:
Zeke Zhang 2024-11-06 07:22:09 +08:00
parent 0cb80753ad
commit 33341c02f9

View File

@ -10,7 +10,6 @@
import React, { createContext, useCallback, useContext, useMemo } from 'react'; import React, { createContext, useCallback, useContext, useMemo } from 'react';
import { useAPIClient, useRequest } from '../api-client'; import { useAPIClient, useRequest } from '../api-client';
import { useIsAdminPage } from '../application/CustomRouterContextProvider'; import { useIsAdminPage } from '../application/CustomRouterContextProvider';
import { useAppSpin } from '../application/hooks/useAppSpin';
export interface CollectionHistoryContextValue { export interface CollectionHistoryContextValue {
historyCollections: any[]; historyCollections: any[];
@ -40,7 +39,6 @@ export const CollectionHistoryProvider: React.FC = (props) => {
const api = useAPIClient(); const api = useAPIClient();
const isAdminPage = useIsAdminPage(); const isAdminPage = useIsAdminPage();
const token = api.auth.getToken() || ''; const token = api.auth.getToken() || '';
const { render } = useAppSpin();
const service = useRequest<{ const service = useRequest<{
data: any; data: any;
@ -63,16 +61,12 @@ export const CollectionHistoryProvider: React.FC = (props) => {
}; };
}, [refreshCH, service.data?.data]); }, [refreshCH, service.data?.data]);
if (service.loading) {
return render();
}
return <CollectionHistoryContext.Provider value={value}>{props.children}</CollectionHistoryContext.Provider>; return <CollectionHistoryContext.Provider value={value}>{props.children}</CollectionHistoryContext.Provider>;
}; };
export const useHistoryCollectionsByNames = (collectionNames: string[]) => { export const useHistoryCollectionsByNames = (collectionNames: string[]) => {
const { historyCollections } = useContext(CollectionHistoryContext); const { historyCollections } = useContext(CollectionHistoryContext);
return historyCollections.filter((i) => collectionNames.includes(i.name)); return historyCollections?.filter((i) => collectionNames.includes(i.name)) || [];
}; };
export const useCollectionHistory = () => { export const useCollectionHistory = () => {