mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-13 05:39:59 +00:00
feat: face view support move (#7137)
* feat: face view support move * feat: optimize code * feat: optimize code --------- Co-authored-by: 杨国璇 <ygx@Hello-word.local>
This commit is contained in:
@@ -15,7 +15,6 @@ export const MetadataProvider = ({ repoID, currentPath, repoInfo, hideMetadataVi
|
||||
const [isLoading, setLoading] = useState(true);
|
||||
const [enableFaceRecognition, setEnableFaceRecognition] = useState(false);
|
||||
const [navigation, setNavigation] = useState([]);
|
||||
const [staticView, setStaticView] = useState([]);
|
||||
const [, setCount] = useState(0);
|
||||
|
||||
const viewsMap = useRef({});
|
||||
@@ -23,14 +22,6 @@ export const MetadataProvider = ({ repoID, currentPath, repoInfo, hideMetadataVi
|
||||
|
||||
const { enableMetadata, isBeingBuilt, setIsBeingBuilt } = useMetadataStatus();
|
||||
|
||||
const updateEnableFaceRecognition = useCallback((newValue) => {
|
||||
if (newValue === enableFaceRecognition) return;
|
||||
setEnableFaceRecognition(newValue);
|
||||
if (newValue) {
|
||||
toaster.success(gettext('Recognizing portraits. Please refresh the page later.'));
|
||||
}
|
||||
}, [enableFaceRecognition]);
|
||||
|
||||
// views
|
||||
useEffect(() => {
|
||||
setLoading(true);
|
||||
@@ -42,11 +33,6 @@ export const MetadataProvider = ({ repoID, currentPath, repoInfo, hideMetadataVi
|
||||
viewsMap.current[view._id] = view;
|
||||
});
|
||||
}
|
||||
viewsMap.current[FACE_RECOGNITION_VIEW_ID] = {
|
||||
_id: FACE_RECOGNITION_VIEW_ID,
|
||||
name: gettext('Photos - classified by people'),
|
||||
type: VIEW_TYPE.FACE_RECOGNITION,
|
||||
};
|
||||
setNavigation(navigation);
|
||||
setLoading(false);
|
||||
}).catch(error => {
|
||||
@@ -59,7 +45,6 @@ export const MetadataProvider = ({ repoID, currentPath, repoInfo, hideMetadataVi
|
||||
hideMetadataView && hideMetadataView();
|
||||
setEnableFaceRecognition(false);
|
||||
viewsMap.current = {};
|
||||
setStaticView([]);
|
||||
setNavigation([]);
|
||||
setLoading(false);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
@@ -67,7 +52,6 @@ export const MetadataProvider = ({ repoID, currentPath, repoInfo, hideMetadataVi
|
||||
|
||||
useEffect(() => {
|
||||
if (!enableMetadata) {
|
||||
setStaticView([]);
|
||||
setEnableFaceRecognition(false);
|
||||
return;
|
||||
}
|
||||
@@ -79,14 +63,6 @@ export const MetadataProvider = ({ repoID, currentPath, repoInfo, hideMetadataVi
|
||||
});
|
||||
}, [repoID, enableMetadata]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!enableFaceRecognition) {
|
||||
setStaticView([]);
|
||||
return;
|
||||
}
|
||||
setStaticView([{ _id: FACE_RECOGNITION_VIEW_ID, type: 'view' }]);
|
||||
}, [enableFaceRecognition]);
|
||||
|
||||
const selectView = useCallback((view, isSelected) => {
|
||||
if (isSelected) return;
|
||||
const node = {
|
||||
@@ -176,6 +152,24 @@ export const MetadataProvider = ({ repoID, currentPath, repoInfo, hideMetadataVi
|
||||
});
|
||||
}, [repoID]);
|
||||
|
||||
const updateEnableFaceRecognition = useCallback((newValue) => {
|
||||
if (newValue === enableFaceRecognition) return;
|
||||
if (newValue) {
|
||||
toaster.success(gettext('Recognizing portraits. Please refresh the page later.'));
|
||||
addView(gettext('Photos - classified by people'), VIEW_TYPE.FACE_RECOGNITION, () => {}, () => {});
|
||||
} else {
|
||||
if (viewsMap.current[FACE_RECOGNITION_VIEW_ID]) {
|
||||
let isSelected = false;
|
||||
if (currentPath.includes('/' + PRIVATE_FILE_TYPE.FILE_EXTENDED_PROPERTIES + '/')) {
|
||||
const currentViewId = currentPath.split('/').pop();
|
||||
isSelected = currentViewId === FACE_RECOGNITION_VIEW_ID;
|
||||
}
|
||||
deleteView(FACE_RECOGNITION_VIEW_ID, isSelected);
|
||||
}
|
||||
}
|
||||
setEnableFaceRecognition(newValue);
|
||||
}, [enableFaceRecognition, currentPath, addView, deleteView]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isLoading) return;
|
||||
if (isBeingBuilt) {
|
||||
@@ -228,7 +222,6 @@ export const MetadataProvider = ({ repoID, currentPath, repoInfo, hideMetadataVi
|
||||
isBeingBuilt,
|
||||
setIsBeingBuilt,
|
||||
navigation,
|
||||
staticView,
|
||||
viewsMap: viewsMap.current,
|
||||
selectView,
|
||||
addView,
|
||||
|
Reference in New Issue
Block a user