diff --git a/client/src/api/User.js b/client/src/api/User.js index 296dd486..803f9805 100644 --- a/client/src/api/User.js +++ b/client/src/api/User.js @@ -21,7 +21,8 @@ export const handleLogin = () => { window.location.href = "http://localhost:8080/api/auth/login" }; export const AddNewCourseAPI = async (code, name) => { - const resp = await axios.post(`${serverRoot}/api/user/course`, { code, name }); + // const resp = await axios.post(`${serverRoot}/api/user/course`, { code, name }); + const resp = await axios.post(`${serverRoot}/api/user/readonly`, { code, name }); // console.log(resp); return resp; }; diff --git a/client/src/screens/browse/components/browsefolder/index.jsx b/client/src/screens/browse/components/browsefolder/index.jsx index 93094956..95cdbb2a 100644 --- a/client/src/screens/browse/components/browsefolder/index.jsx +++ b/client/src/screens/browse/components/browsefolder/index.jsx @@ -13,6 +13,12 @@ const BrowseFolder = ({ type = "file", color, path, name, subject, folderData, p const currYear = useSelector((state) => state.fileBrowser.currentYear); const isBR = useSelector((state) => state.user.user.isBR); const [showConfirm, setShowConfirm] = useState(false); + const user = useSelector((state) => state.user.user); + const courseCode = subject || folderData?.course; + const isReadOnlyCourse = user?.readOnly?.some( + (c) => c.code.toLowerCase() === courseCode?.toLowerCase() + ); + const onClick = (folderData) => { // return; dispatch(ChangeFolder(folderData)); @@ -121,14 +127,16 @@ const BrowseFolder = ({ type = "file", color, path, name, subject, folderData, p

{""}

{name ? name : "Name"}

- {isBR && { - e.stopPropagation(); - setShowConfirm(true); - }} - title="Delete folder" - >} + {isBR && !isReadOnlyCourse && ( + { + e.stopPropagation(); + setShowConfirm(true); + }} + title="Delete folder" + > + )}

@@ -137,12 +145,14 @@ const BrowseFolder = ({ type = "file", color, path, name, subject, folderData, p

- {isBR &&} + {isBR && !isReadOnlyCourse && ( + + )} ); }; diff --git a/client/src/screens/browse/components/file-display/index.jsx b/client/src/screens/browse/components/file-display/index.jsx index 09fe0d5b..7ca3c3dd 100644 --- a/client/src/screens/browse/components/file-display/index.jsx +++ b/client/src/screens/browse/components/file-display/index.jsx @@ -44,6 +44,9 @@ const FileDisplay = ({ file, path, code }) => { const currCourseCode = useSelector((state) => state.fileBrowser?.currentCourseCode); const currFolderId = useSelector((state) => state.fileBrowser?.currentFolder?._id); const currentUser = useSelector((state) => state.user.user); + const isReadOnlyCourse = currentUser?.readOnly?.some( + (c) => c.code.toLowerCase() === currCourseCode?.toLowerCase() + ); if (!file.isVerified && !currentUser?.isBR) { return null; @@ -180,7 +183,7 @@ const FileDisplay = ({ file, path, code }) => { }} >
- {user?.isBR && ( + {user?.isBR && !isReadOnlyCourse && ( <> {!(file.isVerified)? : <>} diff --git a/client/src/screens/browse/components/folder-info/index.jsx b/client/src/screens/browse/components/folder-info/index.jsx index a401a4b3..13d2dd45 100644 --- a/client/src/screens/browse/components/folder-info/index.jsx +++ b/client/src/screens/browse/components/folder-info/index.jsx @@ -27,6 +27,11 @@ const FolderInfo = ({ const [newFolderName, setNewFolderName] = useState(""); const [childType, setChildType] = useState("File"); + const user = useSelector((state) => state.user.user); + const isReadOnlyCourse = user?.readOnly?.some( + (c) => c.code.toLowerCase() === courseCode?.toLowerCase() + ); + const handleShare = () => { const sectionShare = document.getElementById("share"); sectionShare.classList.add("show"); @@ -97,7 +102,7 @@ const FolderInfo = ({
- {canDownload ? ( + {!isReadOnlyCourse && canDownload ? (
{/*
- {isBR? + {isBR && !isReadOnlyCourse?
{course &&
diff --git a/client/src/screens/browse/index.jsx b/client/src/screens/browse/index.jsx index 81c65751..229401fc 100644 --- a/client/src/screens/browse/index.jsx +++ b/client/src/screens/browse/index.jsx @@ -202,29 +202,46 @@ const BrowseScreen = () => { ? "" : user.user?.courses?.map((course, idx) => { return ( - + ); })} {user.localCourses?.map((course, idx) => { return ; })} - {user.user?.isBR && ( -

PREVIOUS COURSES

+ + {user.user?.readOnly?.length > 0 && ( +

OTHERS

)} + + {user.user?.readOnly?.map((course, idx) => ( + + ))} + + {user.user?.isBR &&

PREVIOUS COURSES

} {!(user.user?.isBR && user.user?.previousCourses?.length > 0) ? "" : `

PREVIOUS COURSES

` && - user.user?.previousCourses?.map((course, idx) => { - return ( - - ); - })} + user.user?.previousCourses?.map((course, idx) => { + return ( + + ); + })}
{folderData && ( { {!folderData ? (
{HeaderText}
) : folderData?.childType === "File" ? ( - folderData?.children?.length === 0 ? -

No files available.

- : + folderData?.children?.length === 0 ? ( +

No files available.

+ ) : ( + + ) ) : folderData?.children?.length === 0 ? (

No folders available.

diff --git a/client/src/screens/dashboard/components/addcoursemodal/index.jsx b/client/src/screens/dashboard/components/addcoursemodal/index.jsx index 97b293fd..758c2454 100644 --- a/client/src/screens/dashboard/components/addcoursemodal/index.jsx +++ b/client/src/screens/dashboard/components/addcoursemodal/index.jsx @@ -6,6 +6,7 @@ import "./styles.scss"; import Space from "../../../../components/space"; import { useState } from "react"; import { useEffect } from "react"; +import { useSelector } from "react-redux"; import { GetSearchResult } from "../../../../api/Search"; import Result from "./components/result"; const AddCourseModal = ({ handleAddCourse }) => { @@ -14,6 +15,14 @@ const AddCourseModal = ({ handleAddCourse }) => { const [err, setErr] = useState(null); const [results, setResults] = useState([]); const [loading, setLoading] = useState(false); + const user = useSelector((state) => state.user); + const userCourses = user.user?.courses || []; + const previousCourses = user.user?.previousCourses || []; + const readOnlyCourses = user.user?.readOnly || []; + + const allUserCourseCodes = [...userCourses, ...previousCourses, ...readOnlyCourses].map((c) => + c.code?.replace(/\s+/g, "").toLowerCase() + ); useEffect(() => { if (code.length > 2) { @@ -30,12 +39,13 @@ const AddCourseModal = ({ handleAddCourse }) => { setLoading(true); setErr(null); let searchArr; - if(/\d/.test(code)){ //if code contains number then pass it as one element array + if (/\d/.test(code)) { + //if code contains number then pass it as one element array let codeWithoutSpace = code.replace(/\s+/g, ""); - searchArr= [codeWithoutSpace] - } - else{ //if code does not contain number then split it and pass array of words - searchArr= code.split(" ") + searchArr = [codeWithoutSpace]; + } else { + //if code does not contain number then split it and pass array of words + searchArr = code.split(" "); } const { data } = await GetSearchResult(searchArr); if (data?.found === true) { @@ -61,7 +71,9 @@ const AddCourseModal = ({ handleAddCourse }) => { return ( -
Add new course
+
Add New Course
+
This course will be read only
+
No space between course code, for e.g- CS101
e.preventDefault()}>