diff --git a/src/api.jsx b/src/api.jsx
index 047e991..42b6765 100644
--- a/src/api.jsx
+++ b/src/api.jsx
@@ -341,21 +341,33 @@ export const addSharedFileInOrganization = async (
};
// 공유파일 내용 조회
-export const useGetSharedFileContent = (organizationName, fileName,filePath) => {
- return useQuery(["file"], () => getSharedFileContent(organizationName, fileName,filePath), {
- staleTime: 5000,
- cacheTime: Infinity,
- enabled: filePath.length > 0,
- });
+export const useGetSharedFileContent = (
+ organizationName,
+ fileName,
+ filePath
+) => {
+ return useQuery(
+ ["file"],
+ () => getSharedFileContent(organizationName, fileName, filePath),
+ {
+ staleTime: 5000,
+ cacheTime: Infinity,
+ enabled: filePath.length > 0,
+ }
+ );
};
-export const getSharedFileContent = async (organizationName, fileName,filePath) => {
+export const getSharedFileContent = async (
+ organizationName,
+ fileName,
+ filePath
+) => {
try {
const response = await axios.post(
`${SERVER}/api/v1/${organizationName}/sharedFile/${fileName}/info`,
filePath
);
- console.log("api test:"+ JSON.stringify(response.data));
+ console.log("api test:" + JSON.stringify(response.data));
return response.data;
} catch (err) {
throw new Error("fetch shared file content error");
@@ -457,17 +469,19 @@ export const getAllFile = async () => {
};
// 파일 저장
-export const addFile = async (fileInfo) => {
+export const addFile = async (contents, originalPath, updatePath) => {
try {
- const response = await axiosInstance.post(
- `${SERVER}/api/v1/files`,
- fileInfo
- );
- if (response.status === 200) {
- alert("파일이 저장되었습니다.");
- }
+ console.log(contents);
+ console.log(originalPath);
+ console.log(updatePath);
+ const response = await axiosInstance.post(`${SERVER}/api/v1/files`, {
+ contents: contents,
+ originalPath: originalPath,
+ updatePath: updatePath,
+ });
+ return response;
} catch (error) {
- throw new Error("sign up user error");
+ throw new Error("file save error");
}
};
diff --git a/src/axiosInterceptor.jsx b/src/axiosInterceptor.jsx
index 1a8220e..a95e990 100644
--- a/src/axiosInterceptor.jsx
+++ b/src/axiosInterceptor.jsx
@@ -83,7 +83,6 @@ function addSubscriber(requestCallback) {
// subscriber 에 담긴 요청들 실행
function executeSubscriber(accessToken) {
- console.log(subscribers.length);
subscribers.map((callback) => callback(accessToken));
subscribers = [];
}
diff --git a/src/components/organisms/fileView.jsx b/src/components/organisms/fileView.jsx
index a462db4..0b0f900 100644
--- a/src/components/organisms/fileView.jsx
+++ b/src/components/organisms/fileView.jsx
@@ -9,6 +9,7 @@ import {
AiOutlineFile,
} from "react-icons/ai";
import { IoIosClose } from "react-icons/io";
+import { BiSave } from "react-icons/bi";
import Button from "../atoms/button";
import { CONSOLE, TERMINAL } from "../../constants";
import styled from "styled-components";
@@ -28,8 +29,9 @@ import {
addSharedFileInOrganization,
deleteSharedFile,
useGetSharedFileContent,
+ addFile,
} from "../../api";
-import { useMutation } from "@tanstack/react-query";
+import { QueryClient, useMutation } from "@tanstack/react-query";
import { BsFolderPlus } from "react-icons/bs";
import { FiFilePlus } from "react-icons/fi";
import { BiGroup } from "react-icons/bi";
@@ -172,10 +174,23 @@ const FileView = () => {
data: sharedFileData,
} = useGetSharedFileContent(opendGroupName, openedFileName, filePathInfo);
- if (!myFilesIsLoading) {
- // console.log(myFiles);
- // TODO : 내 파일들의 path 저장
- }
+ // 파일 저장
+ const queryClient = new QueryClient();
+
+ const fileSaveMutation = useMutation(
+ () =>
+ addFile(
+ fileContents.contents,
+ filePathInfo.filePath,
+ filePathInfo.filePath
+ ),
+ {
+ onSuccess: () => {
+ alert("파일이 저장되었습니다");
+ queryClient.invalidateQueries();
+ },
+ }
+ );
useEffect(() => {
if (!getOrganizationIsLoading) {
@@ -210,6 +225,9 @@ const FileView = () => {
if (localStorage.getItem("isAdmin") === "true") {
setAdmin(true);
}
+ }, []);
+
+ useEffect(() => {
if (isFileClicked) {
refetch().then(() => {
setSharedFileOrganizationName(fileData.organizationName);
@@ -543,7 +561,7 @@ const FileView = () => {
{openedFileName}