1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-23 20:37:42 +00:00

feat: metadata status callback (#7716)

* feat: metadata status callback

* feat: optimzie code

---------

Co-authored-by: 杨国璇 <ygx@Hello-word.local>
This commit is contained in:
杨国璇
2025-04-08 15:00:02 +08:00
committed by GitHub
parent a865aecb6f
commit 53bedae485
2 changed files with 16 additions and 8 deletions

View File

@@ -7,7 +7,7 @@ import { MetadataAIOperationsProvider } from './metadata-ai-operation';
// This hook provides content related to seahub interaction, such as whether to enable extended attributes
const MetadataStatusContext = React.createContext(null);
export const MetadataStatusProvider = ({ repoID, repoInfo, hideMetadataView, updateUsedRepoTags, clearRepoTags, children }) => {
export const MetadataStatusProvider = ({ repoID, repoInfo, hideMetadataView, statusCallback, children }) => {
const enableMetadataManagement = useMemo(() => {
if (repoInfo?.encrypted) return false;
return window.app.pageOptions.enableMetadataManagement;
@@ -60,9 +60,6 @@ export const MetadataStatusProvider = ({ repoID, repoInfo, hideMetadataView, upd
if (!enableMetadata) {
cancelMetadataURL();
}
if (enableTags) {
updateUsedRepoTags();
}
setEnableTags(enableTags);
setTagsLang(tagsLang || 'en');
setDetailsSettings(JSON.parse(detailsSettings));
@@ -79,6 +76,11 @@ export const MetadataStatusProvider = ({ repoID, repoInfo, hideMetadataView, upd
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [repoID, enableMetadataManagement]);
useEffect(() => {
statusCallback && statusCallback({ enableMetadata, enableTags });
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [enableMetadata, enableTags]);
const updateEnableMetadata = useCallback((newValue) => {
if (newValue === enableMetadata) return;
if (!newValue) {
@@ -96,12 +98,10 @@ export const MetadataStatusProvider = ({ repoID, repoInfo, hideMetadataView, upd
if (newValue === enableTags && lang === tagsLang) return;
if (!newValue) {
cancelMetadataURL(true);
clearRepoTags();
}
setEnableTags(newValue);
if (newValue) updateUsedRepoTags();
setTagsLang(lang);
}, [enableTags, tagsLang, cancelMetadataURL, clearRepoTags, updateUsedRepoTags]);
}, [enableTags, tagsLang, cancelMetadataURL]);
const updateEnableOCR = useCallback((newValue) => {
if (newValue === enableOCR) return;