2024-03-27 17:56:34 +08:00
|
|
|
import { IKnowledgeFile } from '@/interfaces/database/knowledge';
|
|
|
|
import { IChangeParserConfigRequestBody } from '@/interfaces/request/document';
|
|
|
|
import { useCallback, useState } from 'react';
|
2024-04-07 17:41:29 +08:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2024-03-27 17:56:34 +08:00
|
|
|
import { useSetModalState } from './commonHooks';
|
|
|
|
import { useSetDocumentParser } from './documentHooks';
|
|
|
|
import { useOneNamespaceEffectsLoading } from './storeHooks';
|
2024-04-07 17:41:29 +08:00
|
|
|
import { useSaveSetting } from './userSettingHook';
|
2024-03-27 17:56:34 +08:00
|
|
|
|
|
|
|
export const useChangeDocumentParser = (documentId: string) => {
|
|
|
|
const setDocumentParser = useSetDocumentParser();
|
|
|
|
|
|
|
|
const {
|
|
|
|
visible: changeParserVisible,
|
|
|
|
hideModal: hideChangeParserModal,
|
|
|
|
showModal: showChangeParserModal,
|
|
|
|
} = useSetModalState();
|
|
|
|
const loading = useOneNamespaceEffectsLoading('kFModel', [
|
|
|
|
'document_change_parser',
|
|
|
|
]);
|
|
|
|
|
|
|
|
const onChangeParserOk = useCallback(
|
|
|
|
async (parserId: string, parserConfig: IChangeParserConfigRequestBody) => {
|
|
|
|
const ret = await setDocumentParser(parserId, documentId, parserConfig);
|
|
|
|
if (ret === 0) {
|
|
|
|
hideChangeParserModal();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[hideChangeParserModal, setDocumentParser, documentId],
|
|
|
|
);
|
|
|
|
|
|
|
|
return {
|
|
|
|
changeParserLoading: loading,
|
|
|
|
onChangeParserOk,
|
|
|
|
changeParserVisible,
|
|
|
|
hideChangeParserModal,
|
|
|
|
showChangeParserModal,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export const useSetSelectedRecord = <T = IKnowledgeFile>() => {
|
|
|
|
const [currentRecord, setCurrentRecord] = useState<T>({} as T);
|
|
|
|
|
|
|
|
const setRecord = (record: T) => {
|
|
|
|
setCurrentRecord(record);
|
|
|
|
};
|
|
|
|
|
|
|
|
return { currentRecord, setRecord };
|
|
|
|
};
|
2024-04-07 17:41:29 +08:00
|
|
|
|
|
|
|
export const useChangeLanguage = () => {
|
|
|
|
const { i18n } = useTranslation();
|
|
|
|
const saveSetting = useSaveSetting();
|
|
|
|
|
|
|
|
const changeLanguage = (lng: string) => {
|
|
|
|
i18n.changeLanguage(lng === 'Chinese' ? 'zh' : 'en');
|
|
|
|
saveSetting({ language: lng });
|
|
|
|
};
|
|
|
|
|
|
|
|
return changeLanguage;
|
|
|
|
};
|