Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/src/api/Contribution.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
5 changes: 3 additions & 2 deletions client/src/reducers/filebrowser_reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion client/src/screens/browse/components/collapsible/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
30 changes: 17 additions & 13 deletions client/src/screens/browse/components/folder-info/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,23 @@ const FolderInfo = ({ path, name, canDownload, contributionHandler, folderId, co
</div>
</div>
</div>
<div className="btn-container">
{/* <button
className="btn download"
style={{ display: canDownload ? "inline-block" : "none" }}
>
<span className="icon download-icon"></span>
<span className="text">Download All Files</span>
</button> */}
<button className="btn plus" onClick={contributionHandler}>
<span className="icon plus-icon"></span>
<span className="text">Contribute</span>
</button>
</div>
{
canDownload?
<div className="btn-container">
{/* <button
className="btn download"
style={{ display: canDownload ? "inline-block" : "none" }}
>
<span className="icon download-icon"></span>
<span className="text">Download All Files</span>
</button> */}
<button className="btn plus" onClick={contributionHandler}>
<span className="icon plus-icon"></span>
<span className="text">Contribute</span>
</button>
</div>
: <></>
}
</div>
<Share link={`${clientRoot}/browse/${courseCode}/${folderId}`} />
</>
Expand Down
157 changes: 42 additions & 115 deletions client/src/screens/contributions/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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 (
<SectionC>
<Wrapper>
<div className="head">Contribute to CourseHub</div>
<form>
<div className="course">
<label htmlFor="course" className="label_course">
COURSE CODE :
</label>
<input
placeholder="Course Code"
name="course"
className="input_course"
value={courseCode? courseCode : ""}
onChange={(e) => setCourseCode(e.target.value)}
></input>
</div>
<div className="section">
<label htmlFor="section" className="label_section">
SECTION :
</label>
<select
name="section"
className="select_section"
onChange={(e) => setFolder(e.target.value)}
>
<option value="Books">Books</option>
<option value="Lecture Slides">Lecture Slides</option>
<option value="Tutorials">Tutorials</option>
<option value="Exams">Exams</option>
<option value="Notes">Notes</option>
<option value="Assignments">Assignments</option>
</select>
</div>
<div className="year">
<label htmlFor="year" className="label_year">
YEAR :
</label>
<select
name="year"
className="select_year"
onChange={(e) => setYear(e.target.value)}
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
strokeWidth="1.5"
stroke="currentColor"
className="w-6 h-6"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M19.5 8.25l-7.5 7.5-7.5-7.5"
/>
</svg>
<option value="2022">2023</option>
<option value="2022">2022</option>
<option value="2022">2021</option>
<option value="2022">2020</option>
<option value="2019">2019</option>
<option value="2018">2018</option>
<option value="2017">2017</option>
<option value="2022">2016</option>
<option value="2022">2015</option>
<option value="2022">2014</option>
<option value="2022">2013</option>
<option value="2022">2012</option>
</select>
</div>
<div className="description">
<label htmlFor="description" className="label_description">
DESCRIPTION :
Expand All @@ -172,21 +106,14 @@ const Contributions = () => {
name="description"
className="input_description"
placeholder="Give a brief description"
value={description? description : ""}
value={description ? description : ""}
onChange={(e) => setDescription(e.target.value)}
></textarea>
</div>
<div className="year">
<label htmlFor="course" className="label_year">
ANONYMOUS:
</label>
<span className="toggle-container">
<ToggleSwitch label={"toggle"} />
</span>
</div>
</form>
<div className="file_pond">
<FilePond
name="file"
allowMultiple={true}
maxFiles={40}
server={{
Expand Down
Binary file not shown.
Binary file removed server/external/mobile/rust_book~undefined.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion server/modules/contribution/contribution.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ async function HandleFileUpload(req, res, next) {
if (fileId) {
await HandleFileToDB(contributionId, fileId);
}
await fs.promises.unlink(finalPath+finalFileName);
return res.json({ file });
}

Expand All @@ -88,7 +89,6 @@ async function CreateNewContribution(req, res, next) {
parentFolder: Joi.string().required(),
approved: Joi.bool(),
description: Joi.string().required(),
isAnonymous: Joi.boolean().required(),
};
const data = req.body;

Expand Down
2 changes: 1 addition & 1 deletion server/modules/contribution/contribution.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const ContributionSchema = Schema(
approved: { type: Boolean, default: false },
//year: { type: String },
description: { type: String },
isAnonymous: { type: Boolean, default: false },
// isAnonymous: { type: Boolean, default: false },
// url: { type: String },
},
{ timestamps: true }
Expand Down
1 change: 1 addition & 0 deletions server/modules/user/user.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const getUser = async (req, res, next) => {
const isBR = await BR.findOne({ email: user.email });

const responseUser = {
_id: user._id,
name: user.name,
email: user.email,
rollNumber: user.rollNumber,
Expand Down
5 changes: 0 additions & 5 deletions server/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading