fix: load collections history only admin pages

This commit is contained in:
chenos 2023-01-06 08:47:43 +08:00
parent d062c8fd99
commit 2cba502f60

View File

@ -1,5 +1,6 @@
import { Spin } from 'antd';
import React, { createContext, useContext, useEffect, useState } from 'react';
import React, { createContext, useContext, useEffect } from 'react';
import { useLocation } from 'react-router-dom';
import { APIClientContext, useRequest } from '../api-client';
export interface CollectionHistoryContextValue {
@ -28,7 +29,21 @@ export const CollectionHistoryProvider: React.FC = (props) => {
},
};
const service = useRequest(options);
const location = useLocation();
// console.log('location', location);
const service = useRequest(options, {
manual: true,
});
const isAdminPage = location.pathname.startsWith('/admin');
useEffect(() => {
if (isAdminPage) {
service.run();
}
}, [isAdminPage]);
// 刷新 collecionHistory
const refreshCH = async () => {