diff --git a/backend/controllers/folder-controller.ts b/backend/controllers/folder-controller.ts index 44c96a2..ddc572a 100644 --- a/backend/controllers/folder-controller.ts +++ b/backend/controllers/folder-controller.ts @@ -222,15 +222,13 @@ class FolderController { const userID = req.user._id; const parent = (req.query.parent as string) || undefined; const search = (req.query.search as string) || undefined; - const folderID = (req.query.folderID as string) || undefined; - const currentParent = (req.query.currentParent as string) || undefined; + const folderIDs = (req.query.folderIDs as string[]) || []; const folderList = await folderService.getMoveFolderList( userID, parent, search, - folderID, - currentParent + folderIDs ); res.send(folderList); diff --git a/backend/db/mongoDB/folderDB.ts b/backend/db/mongoDB/folderDB.ts index ab58793..0ef7f53 100644 --- a/backend/db/mongoDB/folderDB.ts +++ b/backend/db/mongoDB/folderDB.ts @@ -48,25 +48,29 @@ class DbUtil { userID: string, parent = "/", search?: string, - folderID?: string, - currentParent?: string + folderIDs?: string[] ) => { let query: any = { owner: userID, }; - const idQuery = []; + // const idQuery = []; // if (currentParent && currentParent !== "/") { // idQuery.push(currentParent); // } - if (folderID) { - query.parentList = { $ne: folderID }; - idQuery.push(folderID); + // if (folderID) { + // query.parentList = { $ne: folderID }; + // idQuery.push(folderID); + // } + + if (folderIDs && folderIDs.length > 0) { + query._id = { $nin: folderIDs }; + query.parentList = { $nin: folderIDs }; } - query._id = { $nin: idQuery }; + // query._id = { $nin: idQuery }; if (!search || search === "") { query.parent = parent; diff --git a/backend/middleware/folders/folder-middleware.ts b/backend/middleware/folders/folder-middleware.ts index c4b8d6a..427e1ab 100644 --- a/backend/middleware/folders/folder-middleware.ts +++ b/backend/middleware/folders/folder-middleware.ts @@ -7,6 +7,10 @@ import { middlewareValidationFunction } from "../utils/middleware-utils"; export const moveFolderListValidationRules = [ query("parent").optional().isString().withMessage("Parent must be a string"), query("search").optional().isString().withMessage("Search must be a string"), + query("folderIDs") + .isArray() + .isLength({ min: 1 }) + .withMessage("FolderIDs must be an array of strings"), middlewareValidationFunction, ]; diff --git a/backend/services/folder-service/folder-service.ts b/backend/services/folder-service/folder-service.ts index ebc34de..a86ed25 100644 --- a/backend/services/folder-service/folder-service.ts +++ b/backend/services/folder-service/folder-service.ts @@ -102,15 +102,13 @@ class FolderService { userID: string, parent?: string, search?: string, - folderID?: string, - currentParent?: string + folderIDs?: string[] ) => { const folderList = await folderDB.getMoveFolderList( userID, parent, search, - folderID, - currentParent + folderIDs ); return folderList; diff --git a/src/api/foldersAPI.ts b/src/api/foldersAPI.ts index 562a9b0..6f33fba 100644 --- a/src/api/foldersAPI.ts +++ b/src/api/foldersAPI.ts @@ -41,15 +41,20 @@ export const getMoveFolderListAPI = async ({ }: QueryFunctionContext< [ string, - { parent: string; search: string; folderID?: string; currentParent: string } + { + parent: string; + search: string; + folderIDs?: string[]; + currentParent: string; + } ] >) => { - const [_key, { parent, search, folderID, currentParent }] = queryKey; + const [_key, { parent, search, folderIDs, currentParent }] = queryKey; const response = await axios.get(`/folder-service/move-folder-list`, { params: { parent, search, - folderID, + folderIDs, currentParent, }, }); diff --git a/src/components/MoverPopup/MoverPopup.tsx b/src/components/MoverPopup/MoverPopup.tsx index 54ab2be..8358b3a 100644 --- a/src/components/MoverPopup/MoverPopup.tsx +++ b/src/components/MoverPopup/MoverPopup.tsx @@ -37,10 +37,18 @@ const MoverPopup = () => { folderID: "", }); + const foldersToMove = useAppSelector((state) => { + if (state.selected.multiSelectMode) { + return Object.keys(state.selected.multiSelectMap); + } else { + return [state.selected.mainSection.id]; + } + }); + const { data: folderList, isLoading: isLoadingFolders } = useMoveFolders( parent?._id || "/", debouncedSearch, - folder?._id + foldersToMove ); const debouncedSetSearchText = useMemo( diff --git a/src/hooks/folders.ts b/src/hooks/folders.ts index bc9b23d..96e7686 100644 --- a/src/hooks/folders.ts +++ b/src/hooks/folders.ts @@ -75,7 +75,7 @@ export const useFolder = () => { export const useMoveFolders = ( parent: string, search: string, - folderID?: string + folderIDs?: string[] ) => { const params = useParams(); const moveFoldersQuery = useQuery( @@ -84,7 +84,7 @@ export const useMoveFolders = ( { parent, search, - folderID, + folderIDs, currentParent: params.id || "/", }, ],