diff --git a/client/src/api/Contribution.js b/client/src/api/Contribution.js
index 59b6fcad..12c3ea40 100644
--- a/client/src/api/Contribution.js
+++ b/client/src/api/Contribution.js
@@ -3,7 +3,7 @@ axios.defaults.withCredentials = true;
import root from "./server";
export const CreateNewContribution = async (data) => {
- console.log(data);
+ // console.log(data);
const resp = await axios.post(`${root}/api/contribution/`, data);
return resp;
};
diff --git a/client/src/reducers/filebrowser_reducer.js b/client/src/reducers/filebrowser_reducer.js
index 80ec9393..13cd650c 100644
--- a/client/src/reducers/filebrowser_reducer.js
+++ b/client/src/reducers/filebrowser_reducer.js
@@ -24,14 +24,15 @@ const FileBrowserReducer = (
// console.log("Updated");
let arr = state.allCourseData;
if (
- !arr.find(
+ arr.find(
(course) =>
course.code?.toLowerCase() ===
action.payload.currentCourse.code.toLowerCase()
)
) {
- arr.push(action.payload.currentCourse);
+ arr = arr.filter((course) => course.code?.toLowerCase() !== action.payload.currentCourse.code.toLowerCase())
}
+ arr.push(action.payload.currentCourse);
sessionStorage.setItem("AllCourses", JSON.stringify(arr));
return {
...state,
diff --git a/client/src/screens/browse/components/collapsible/index.jsx b/client/src/screens/browse/components/collapsible/index.jsx
index a1ce2560..49779caa 100644
--- a/client/src/screens/browse/components/collapsible/index.jsx
+++ b/client/src/screens/browse/components/collapsible/index.jsx
@@ -35,7 +35,7 @@ const Collapsible = ({ course, color, state }) => {
let insessionStorage = null;
try {
currCourse = allCourseData.find(
- (course) => course.code.toLowerCase() === code.toLowerCase()
+ (course) => course.code.toLowerCase() === code.toLowerCase().replaceAll(" ", "")
);
} catch (error) {
sessionStorage.removeItem("AllCourses");
diff --git a/client/src/screens/browse/components/file-display/index.jsx b/client/src/screens/browse/components/file-display/index.jsx
index 1ad78db0..b14520d1 100644
--- a/client/src/screens/browse/components/file-display/index.jsx
+++ b/client/src/screens/browse/components/file-display/index.jsx
@@ -11,7 +11,6 @@ import clientRoot from "../../../../api/client";
import capitalise from "../../../../utils/capitalise.js";
import Share from "../../../share";
const FileDisplay = ({ file, path, code }) => {
- console.log(file);
const fileSize = formatFileSize(file.size);
const fileType = formatFileType(file.name);
let name = file.name;
diff --git a/client/src/screens/browse/components/folder-info/index.jsx b/client/src/screens/browse/components/folder-info/index.jsx
index 62d25555..165e1c4f 100644
--- a/client/src/screens/browse/components/folder-info/index.jsx
+++ b/client/src/screens/browse/components/folder-info/index.jsx
@@ -34,19 +34,23 @@ const FolderInfo = ({ path, name, canDownload, contributionHandler, folderId, co
-
- {/* */}
-
-
+ {
+ canDownload?
+
+ {/* */}
+
+
+ : <>>
+ }
>
diff --git a/client/src/screens/contributions/index.jsx b/client/src/screens/contributions/index.jsx
index 28c5a382..e8d17aa1 100644
--- a/client/src/screens/contributions/index.jsx
+++ b/client/src/screens/contributions/index.jsx
@@ -4,84 +4,66 @@ import axios from "axios";
import { FilePond, registerPlugin } from "react-filepond";
import "filepond/dist/filepond.min.css";
import { useEffect, useRef, useState } from "react";
-import Footer from "../../components/footer";
-import Cookies from "js-cookie";
-import ToggleSwitch from "./components/ToggleSwitch";
import "./styles.scss";
import { v4 as uuidv4 } from "uuid";
import { CreateNewContribution } from "../../api/Contribution";
import { useSelector } from "react-redux";
import { toast } from "react-toastify";
import googleFormLink from "../../api/googleFormLink";
+import { useDispatch } from "react-redux";
+
+import { getCourse } from "../../api/Course";
+import { UpdateCourses } from "../../actions/filebrowser_actions";
const Contributions = () => {
const uploadedBy = useSelector((state) => state.user.user._id);
const userName = useSelector((state) => state.user.user.name);
+ const currentFolder = useSelector((state) => state.fileBrowser.currentFolder);
+ const code = currentFolder?.course;
const [contributionId, setContributionId] = useState("");
+ const dispatch = useDispatch();
useEffect(() => {
setContributionId(uuidv4());
}, []);
- const [courseCode, setCourseCode] = useState(null);
- const [folder, setFolder] = useState("Lecture Slides");
const [description, setDescription] = useState(null);
- const [year, setYear] = useState("2022");
const [submitEnabled, setSubmitEnabled] = useState(false);
useEffect(() => {
- if (!courseCode || !folder || !year || !description || courseCode?.length < 3) {
+ if (!description) {
setSubmitEnabled(false);
return;
}
setSubmitEnabled(true);
- }, [courseCode, folder, description, year]);
+ }, [description]);
// const [contributionId, setContributionId] = useState("");
let pond = useRef();
async function handleSubmit() {
- if (!courseCode || !folder || !year || !description) {
+ if (!description) {
toast.error("Please fill the complete form.");
return;
}
- if (courseCode?.length < 3) {
- toast.error("Invalid course code length!");
- return;
- }
- await pond.current.processFiles();
const collection = document.getElementsByClassName("contri");
const contributionSection = collection[0];
- pond.current.removeFiles();
- const toggle = document.getElementById("toggle");
// console.log(toggle);
- let isAnoynmous = toggle.checked;
// console.log(isAnoynmous);
try {
setSubmitEnabled(false);
- if (isAnoynmous) {
- let resp = await CreateNewContribution({
- courseCode,
- folder,
- description,
- year,
- approved: false,
- contributionId,
- uploadedBy: `63ef67f7ab9bcbea9195147c`,
- });
- // console.log(resp);
- } else {
- let resp = await CreateNewContribution({
- courseCode,
- folder,
- description,
- year,
- approved: false,
- contributionId,
- uploadedBy,
- });
- // console.log(resp);
- }
+ // console.log(resp);
+ let resp = await CreateNewContribution({
+ parentFolder: currentFolder._id,
+ courseCode: currentFolder.course,
+ description,
+ approved: false,
+ contributionId,
+ uploadedBy,
+ });
+ // console.log(resp);
+ await pond.current.processFiles();
+ pond.current.removeFiles();
contributionSection.classList.remove("show");
toast.success("Files uploaded successfully!");
setContributionId(uuidv4());
@@ -92,78 +74,30 @@ const Contributions = () => {
toast.error("Failed to upload! Please try again.");
console.log(error);
}
+
+ //refresh the course in session storage to include the new file.
+ try {
+ let loadingCourseToastId = toast.loading("Loading course data...");
+ const currCourse = await getCourse(code);
+ const { data } = currCourse;
+ if (!data.found) {
+ toast.dismiss(loadingCourseToastId);
+ toast.error("Course data not found!");
+ return;
+ }
+ toast.dismiss(loadingCourseToastId);
+ dispatch(UpdateCourses(data));
+ } catch (error) {
+ return null;
+ }
+ location.reload();
}
+
return (
Contribute to CourseHub
{
const isBR = await BR.findOne({ email: user.email });
const responseUser = {
+ _id: user._id,
name: user.name,
email: user.email,
rollNumber: user.rollNumber,
diff --git a/server/yarn.lock b/server/yarn.lock
index 46c8594e..12f358fc 100644
--- a/server/yarn.lock
+++ b/server/yarn.lock
@@ -1541,11 +1541,6 @@ fs.realpath@^1.0.0:
resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz"
integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==
-fsevents@~2.3.2:
- version "2.3.2"
- resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz"
- integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==
-
function-bind@^1.1.1:
version "1.1.1"
resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz"