chore: cache resources active tab
This commit is contained in:
@@ -0,0 +1,20 @@
|
|||||||
|
import { getDefaultStore } from 'jotai';
|
||||||
|
import { atomWithStorage } from 'jotai/utils';
|
||||||
|
|
||||||
|
export const tabActiveAtom = atomWithStorage<Map<string, any>>(
|
||||||
|
'tabActiveStatus',
|
||||||
|
new Map()
|
||||||
|
);
|
||||||
|
|
||||||
|
export const setActiveStatus = (key: string, value: any) => {
|
||||||
|
const store = getDefaultStore();
|
||||||
|
const cache = store.get(tabActiveAtom);
|
||||||
|
cache.set(key, value);
|
||||||
|
store.set(tabActiveAtom, cache);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getActiveStatus = (key: string) => {
|
||||||
|
const store = getDefaultStore();
|
||||||
|
const cache = store.get(tabActiveAtom);
|
||||||
|
return cache.get(key);
|
||||||
|
};
|
||||||
@@ -21,6 +21,7 @@ const CheckboxWrapper = styled.div`
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
.check-text {
|
.check-text {
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
|
color: var(--ant-color-warning);
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import { getActiveStatus, setActiveStatus } from '@/atoms/tab-active';
|
||||||
|
|
||||||
|
const tabsMap = {
|
||||||
|
resources: 'resources'
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function useTabActive() {
|
||||||
|
const setTabActive = (key: string, value: any) => {
|
||||||
|
setActiveStatus(key, value);
|
||||||
|
};
|
||||||
|
const getTabActive = (key: string) => {
|
||||||
|
return getActiveStatus(key);
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
setTabActive,
|
||||||
|
getTabActive,
|
||||||
|
tabsMap
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -306,7 +306,7 @@ const ModelFiles = () => {
|
|||||||
handleDelete(
|
handleDelete(
|
||||||
{
|
{
|
||||||
...record,
|
...record,
|
||||||
name: record.local_path
|
name: record.resolved_paths?.[0]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
checkConfig: {
|
checkConfig: {
|
||||||
@@ -488,8 +488,8 @@ const ModelFiles = () => {
|
|||||||
type="link"
|
type="link"
|
||||||
btnStyle={{ width: 18, paddingInline: 2 }}
|
btnStyle={{ width: 18, paddingInline: 2 }}
|
||||||
></CopyButton>
|
></CopyButton>
|
||||||
{renderParts(record)}
|
|
||||||
</span>
|
</span>
|
||||||
|
{renderParts(record)}
|
||||||
</PathWrapper>
|
</PathWrapper>
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import useTabActive from '@/hooks/use-tab-active';
|
||||||
import { PageContainer } from '@ant-design/pro-components';
|
import { PageContainer } from '@ant-design/pro-components';
|
||||||
import { useIntl } from '@umijs/max';
|
import { useIntl } from '@umijs/max';
|
||||||
import type { TabsProps } from 'antd';
|
import type { TabsProps } from 'antd';
|
||||||
@@ -14,7 +15,10 @@ const Wrapper = styled.div`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
const Resources = () => {
|
const Resources = () => {
|
||||||
const [activeKey, setActiveKey] = useState('workers');
|
const { setTabActive, getTabActive, tabsMap } = useTabActive();
|
||||||
|
const [activeKey, setActiveKey] = useState(
|
||||||
|
getTabActive(tabsMap.resources) || 'workers'
|
||||||
|
);
|
||||||
|
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
|
||||||
@@ -38,6 +42,7 @@ const Resources = () => {
|
|||||||
|
|
||||||
const handleChangeTab = useCallback((key: string) => {
|
const handleChangeTab = useCallback((key: string) => {
|
||||||
setActiveKey(key);
|
setActiveKey(key);
|
||||||
|
setTabActive(tabsMap.resources, key);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user