Skip to content

Commit

Permalink
Merge pull request #57 from CNU-OOHub/#52/connect-file-sharing
Browse files Browse the repository at this point in the history
feat: 파일 공유, 공유 중지 구현 (#52)
  • Loading branch information
miraekwak authored Nov 4, 2022
2 parents c162764 + bd6cfe0 commit 0d77a0b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 15 deletions.
23 changes: 18 additions & 5 deletions src/api.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,17 +315,25 @@ export const getAllSharedFiles = async (organizationName) => {
// 그룹 내 공유 파일 추가
export const addSharedFileInOrganization = async (
organizationName,
sharedFileInfo
filePathInfo
) => {
try {
const response = await axiosInstance.post(
`${SERVER}/api/v1/${organizationName}/sharedFile`,
sharedFileInfo
filePathInfo,
{
headers: {
Authorization: "Bearer " + sessionStorage.getItem("accessToken"),
},
}
);
if (response.status === 200) {
alert("공유파일이 등록되었습니다");
}
} catch (error) {
if (error.response.data.status === 404) {
alert(error.response.data.message);
}
console.log(error);
throw new Error("Add shared file in organization error");
}
Expand Down Expand Up @@ -354,10 +362,15 @@ export const getSharedFileContent = async (organizationName, fileName,filePath)
};

// 그룹내 파일 공유 중지
export const deleteSharedFile = async (organizationName, fileName) => {
export const deleteSharedFile = async (
organizationName,
fileName,
filePathInfo
) => {
try {
const response = await axiosInstance.delete(
`${SERVER}/api/v1/${organizationName}/sharedFile/${fileName}`
const response = await axiosInstance.post(
`${SERVER}/api/v1/${organizationName}/sharedFile/${fileName}`,
filePathInfo
);
if (response.status === 200) {
alert("파일 공유가 중지되었습니다");
Expand Down
4 changes: 4 additions & 0 deletions src/components/atoms/dropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const DropDown = ({
backgroundColor = "white",
color = "black",
fontSize = 1.1,
disabled = false,
selectedValue,
}) => {
return (
<DropDownBox
Expand All @@ -28,6 +30,8 @@ const DropDown = ({
backgroundColor={backgroundColor}
color={color}
fontSize={fontSize}
disabled={disabled}
value={selectedValue}
>
<option value={placeholder} hidden color={color}>
{placeholder}
Expand Down
35 changes: 25 additions & 10 deletions src/components/organisms/fileView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
useGetAllSharedFiles,
useGetFiles,
useGetFile,
addSharedFileInOrganization,
deleteSharedFile,
useGetSharedFileContent
} from "../../api";
import { useMutation } from "@tanstack/react-query";
Expand Down Expand Up @@ -170,7 +172,7 @@ const FileView = () => {
} = useGetSharedFileContent(opendGroupName, openedFileName, filePathInfo);

if (!myFilesIsLoading) {
console.log(myFiles);
// console.log(myFiles);
// TODO : 내 파일들의 path 저장
}

Expand Down Expand Up @@ -209,14 +211,10 @@ const FileView = () => {
}
if (isFileClicked) {
refetch().then(() => {
setIsFileClicked(false);
setSharedFileOrganizationName(fileData.organizationName);
changeFileContent("contents", fileData.contents.join("\r\n"));
setIsFileShared(fileData.isShared);
setSharedFileOrganizationName(
fileData.organizationName === ""
? "그룹명"
: fileData.organizationName
);
setIsFileClicked(false);
});
}

Expand Down Expand Up @@ -329,6 +327,15 @@ const FileView = () => {
};


const clickedFileSharing = () => {
addSharedFileInOrganization(sharedFileOrganizationName, filePathInfo);
};

const clickedFileSharingStop = () => {
deleteSharedFile(sharedFileOrganizationName, openedFileName, filePathInfo);
setSharedFileOrganizationName("");
};

return (
<>
<FileList>
Expand Down Expand Up @@ -546,11 +553,13 @@ const FileView = () => {
setSharedFileOrganizationName(e.target.value);
}}
options={getOrganizationIsLoading ? [] : groupNames}
placeholder={sharedFileOrganizationName}
placeholder={"그룹명"}
selectedValue={sharedFileOrganizationName}
color={theme.textGreyColor}
height={2}
fontSize={1.0}
backgroundColor="#373737"
disabled={isFileShared}
/>
</div>
<FlexRow flexGrow={1} justifyContent="center">
Expand All @@ -559,10 +568,16 @@ const FileView = () => {
</Text>
<Switch
onChange={(e) => {
if (sharedFileOrganizationName === "") {
if (sharedFileOrganizationName === "그룹명") {
alert("그룹명을 선택하여 주세요.");
} else {
console.log(e.target);
if (isFileShared) {
setIsFileShared(false);
clickedFileSharingStop();
} else {
setIsFileShared(true);
clickedFileSharing();
}
}
}}
checked={isFileShared}
Expand Down

0 comments on commit 0d77a0b

Please sign in to comment.