2024-03-20 11:13:51 +08:00
|
|
|
import { KnowledgeSearchParams } from '@/constants/knowledge';
|
2024-03-31 17:44:34 +08:00
|
|
|
import { useCallback } from 'react';
|
|
|
|
import { useLocation, useNavigate, useSearchParams } from 'umi';
|
2024-02-02 18:49:54 +08:00
|
|
|
|
|
|
|
export enum SegmentIndex {
|
|
|
|
Second = '2',
|
|
|
|
Third = '3',
|
|
|
|
}
|
|
|
|
|
|
|
|
export const useSegmentedPathName = (index: SegmentIndex) => {
|
|
|
|
const { pathname } = useLocation();
|
|
|
|
|
|
|
|
const pathArray = pathname.split('/');
|
|
|
|
return pathArray[index] || '';
|
|
|
|
};
|
|
|
|
|
|
|
|
export const useSecondPathName = () => {
|
|
|
|
return useSegmentedPathName(SegmentIndex.Second);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const useThirdPathName = () => {
|
|
|
|
return useSegmentedPathName(SegmentIndex.Third);
|
|
|
|
};
|
2024-03-20 11:13:51 +08:00
|
|
|
|
|
|
|
export const useGetKnowledgeSearchParams = () => {
|
|
|
|
const [currentQueryParameters] = useSearchParams();
|
|
|
|
|
|
|
|
return {
|
|
|
|
documentId:
|
|
|
|
currentQueryParameters.get(KnowledgeSearchParams.DocumentId) || '',
|
|
|
|
knowledgeId:
|
|
|
|
currentQueryParameters.get(KnowledgeSearchParams.KnowledgeId) || '',
|
|
|
|
};
|
|
|
|
};
|
2024-03-31 17:44:34 +08:00
|
|
|
|
|
|
|
export const useNavigateWithFromState = () => {
|
|
|
|
const navigate = useNavigate();
|
|
|
|
return useCallback(
|
|
|
|
(path: string) => {
|
|
|
|
navigate(path, { state: { from: path } });
|
|
|
|
},
|
|
|
|
[navigate],
|
|
|
|
);
|
|
|
|
};
|