diff --git a/src/actions/mover.js b/src/actions/mover.js index 97e705d..3d863ef 100644 --- a/src/actions/mover.js +++ b/src/actions/mover.js @@ -1,12 +1,10 @@ -export const setMoverID = (id, parent, isFile, isGoogle=false, isPersonal=false) => ({ - type: "SET_MOVER_ID", - id, - parent, - isFile, - isGoogle, - isPersonal -}) +export const setMoverID = (id, parent, isFile) => ({ + type: "SET_MOVER_ID", + id, + parent, + isFile, +}); export const resetMoverID = () => ({ - type: "RESET_MOVER_ID" -}) \ No newline at end of file + type: "RESET_MOVER_ID", +}); diff --git a/src/api/filesAPI.ts b/src/api/filesAPI.ts index 5b229dc..d22f45b 100644 --- a/src/api/filesAPI.ts +++ b/src/api/filesAPI.ts @@ -1,5 +1,6 @@ import { QueryFunctionContext } from "react-query"; import axios from "../axiosInterceptor"; +import { getUserToken } from "./user"; interface QueryKeyParams { parent: string; @@ -44,12 +45,26 @@ export const getFilesList = async ({ export const getQuickFilesList = async () => { const response = await axios.get(`/file-service/quick-list`, { params: { - limit: 12, + limit: 20, }, }); return response.data; }; +export const downloadFile = async (fileID: string) => { + await getUserToken(); + + // TODO: Change this + const url = `http://localhost:5173/api/file-service/download/${fileID}`; + + const link = document.createElement("a"); + document.body.appendChild(link); + link.href = url; + link.setAttribute("type", "hidden"); + link.setAttribute("download", "true"); + link.click(); +}; + export const getFileThumbnail = async (thumbnailID: string) => { const url = `http://localhost:5173/api/file-service/thumbnail/${thumbnailID}`; const config = { diff --git a/src/api/user.ts b/src/api/user.ts new file mode 100644 index 0000000..67a0cbe --- /dev/null +++ b/src/api/user.ts @@ -0,0 +1,6 @@ +import axios from "../axiosInterceptor"; + +export const getUserToken = async () => { + const response = await axios.post("/user-service/get-token"); + response.data; +}; diff --git a/src/components/NewContextMenu/index.jsx b/src/components/ContextMenu/index.jsx similarity index 78% rename from src/components/NewContextMenu/index.jsx rename to src/components/ContextMenu/index.jsx index 65ad962..4dbdfa3 100644 --- a/src/components/NewContextMenu/index.jsx +++ b/src/components/ContextMenu/index.jsx @@ -1,12 +1,16 @@ import classNames from "classnames"; import React, { useEffect, useRef } from "react"; import Swal from "sweetalert2"; -import { deleteFile, renameFile } from "../../api/filesAPI"; +import { deleteFile, renameFile, downloadFile } from "../../api/filesAPI"; import { useFiles, useQuickFiles } from "../../hooks/files"; +import { useDispatch } from "react-redux"; +import { setMoverID } from "../../actions/mover"; +import { setShareSelected } from "../../actions/selectedItem"; -const NewContextMenu = (props) => { +const ContextMenu = (props) => { const { invalidateFilesCache } = useFiles(); const { invalidateQuickFilesCache } = useQuickFiles(); + const dispatch = useDispatch(); const wrapperRef = useRef(); const liClassname = "flex w-full px-[20px] py-[12px] items-center font-normal justify-start no-underline transition-all duration-400 ease-in-out hover:bg-[#f6f5fd] hover:text-[#3c85ee] hover:font-medium"; @@ -51,33 +55,30 @@ const NewContextMenu = (props) => { } }; - // startMovingFile = async () => { - // this.props.dispatch( - // setMoverID( - // this.props._id, - // this.props.metadata.parent, - // true, - // this.props.metadata.drive, - // this.props.metadata.personalFile - // ) - // ); - // }; - - // startShareFile = () => { - // this.props.dispatch(setShareSelected({ ...this.props.file })); - // }; - - // startFileDownload = () => { - // console.log("start download file", this.props.file._id); - // this.props.downloadFile(this.props.file._id, this.props.file); - // }; - - const outOfBoundsClickCheck = () => { - if (wrapperRef && !wrapperRef.current.contains(event.target)) { - props.closeContext(); + const openMoveFileModal = async () => { + if (!props.folderMode) { + dispatch(setMoverID(props.file._id, props.file.metadata.parent, true)); } }; + const openShareFileModal = () => { + dispatch(setShareSelected(props.file)); + }; + + const downloadItem = () => { + downloadFile(props.file._id); + }; + + // TODO: Decide if we want it to close right on click or not + const outOfBoundsClickCheck = (e) => { + // if (wrapperRef && !wrapperRef.current.contains(e.target)) { + // props.closeContext(); + // } + setTimeout(() => { + props.closeContext(); + }, 150); + }; + useEffect(() => { document.addEventListener("mousedown", outOfBoundsClickCheck); document.addEventListener("touchstart", outOfBoundsClickCheck); @@ -93,7 +94,7 @@ const NewContextMenu = (props) => { onClick={props.stopPropagation} ref={wrapperRef} className={classNames( - "fixed min-w-[215px] bg-white shadow-[0px_2px_4px_rgba(0,0,0,0.15),_inset_0px_1px_0px_#f5f7fa] rounded-[4px] mt-[-5px] z-[2] animate-very-long", + "fixed min-w-[215px] bg-white shadow-[0px_2px_4px_rgba(0,0,0,0.15),_inset_0px_1px_0px_#f5f7fa] rounded-[4px] mt-[-5px] z-[2] mobile__context__menu", props.contextSelected.selected ? "opacity-100" : "opacity-0" )} style={ @@ -116,7 +117,7 @@ const NewContextMenu = (props) => { {!props.folderMode ? ( -
{props.state.editNameMode ? "" : capitalize(props.filename)}
- - {props.state.editNameMode ? -Are you sure you want to delete this?
- -{capitalize(props.filename)}
- {moment(props.uploadDate).format("L")} + if (props.state.movingMode) { + return ( +Moving 4 items…
+ 2 minutes remaining ++ {props.state.editNameMode ? "" : capitalize(props.filename)} +
+ + {props.state.editNameMode ? ( +Are you sure you want to delete this?
+ ++ {capitalize(props.filename)} +
+ + {moment(props.uploadDate).format("L")} + +{props.name}
-{props.name}
+Select a file or folder to view it’s details
-{this.props.selectedItem.name}
-Select a file or folder to view it’s details
+{this.props.selectedItem.name}
+