diff --git a/client/src/components/Classroom/Content.tsx b/client/src/components/Classroom/Content.tsx index 4205bf6..a849c72 100644 --- a/client/src/components/Classroom/Content.tsx +++ b/client/src/components/Classroom/Content.tsx @@ -1,6 +1,6 @@ -import { Group, Stack, Text } from "@mantine/core"; +import { Collapse, Group, Stack, Text } from "@mantine/core"; import { BiSolidBook } from "react-icons/bi"; -import React from "react"; +import React, { useState } from "react"; import { BsThreeDotsVertical } from "react-icons/bs"; import { GrAnnounce } from "react-icons/gr"; @@ -20,6 +20,7 @@ type Post = { }; const Content = ({ post }: { post: Post }) => { + const [isDVisible,setIsDVisible] = useState(false); let attachment_id = ""; if (post.attachments_url.length > 0) { let url = post.attachments_url[0]; @@ -28,7 +29,7 @@ const Content = ({ post }: { post: Post }) => { } const router = useRouter(); return ( - { border: "1px solid #CED4DA", cursor: "pointer", }} - onClick={() => { - const hub_id = router.query.hub_id as string; - if (attachment_id === "") - router.push(`http://localhost:3000/hub/${hub_id}/${post.uuid}`); - else - router.push( - `http://localhost:3000/hub/${hub_id}/${post.uuid}/${attachment_id}` - ); - }} > - {post.type === "announcement" ? ( - - ) : ( - - )} + { + const hub_id = router.query.hub_id as string; + if (attachment_id === "") { + setIsDVisible(!isDVisible); + } else + router.push( + `http://localhost:3000/hub/${hub_id}/${post.uuid}/${attachment_id}` + ); + }} + > + {post.type === "announcement" ? ( + + ) : ( + + )} - {post.title} - {post.created_at.substring(0, 10)} - - + {post.title} + {post.created_at.substring(0, 10)} + + + {post.type === "announcement" && ( + + {post.description} + + )} + ); }; diff --git a/client/src/components/Classroom/LeftBar.tsx b/client/src/components/Classroom/LeftBar.tsx index 1a5806f..b1f33bc 100644 --- a/client/src/components/Classroom/LeftBar.tsx +++ b/client/src/components/Classroom/LeftBar.tsx @@ -19,54 +19,19 @@ const LeftBar = ({ role: string; theme_color:string }) => { - const router = useRouter(); const { - isCreatePostVisible, setIsCreatePostVisible, - currentHubData, - appendPost, setRoomId, - recordingData, roomId, } = useContext(HubContext); const [isCreateRecordingVisible, setIsCreateRecordingVisible] = useState(false); const [teacherCode, setTeacherCode] = useState(null); - const { token } = useContext(AppContext); - const { introductory } = currentHubData!; - const { _id } = introductory!; - const hub_id = router.query.hub_id as string; + const [studentCode, setStudentCode] = useState(null); const managementToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3MTQzODc0MzIsImV4cCI6MTcxNTUxMDYzMiwianRpIjoiMDBjMTMyNDItZjAwMS00NzM0LTlhYjgtMmEwNjk3MDI3ZTQ3IiwidHlwZSI6Im1hbmFnZW1lbnQiLCJ2ZXJzaW9uIjoyLCJuYmYiOjE3MTQzODc0MzIsImFjY2Vzc19rZXkiOiI2NjBmY2I1NWJhYmMzM2YwMGU0YWI5NjcifQ.J3CU5ks1zdZ4hX0bm2UB4LwAmXMUjqEFMBlRkWLXYn0"; - const handleMakeAnnouncement = async (studentRoomCode: string) => { - const formData = new FormData(); - formData.append("type", "announcement"); - formData.append( - "title", - `Join Live class here http://localhost:3000/hub/662e9873bc5597d4fda393cc/live/${studentRoomCode}` - ); - formData.append("topic", "Live Class"); - - try { - const resp = await fetch( - `http://127.0.0.1:5000/api/${btoa(hub_id)}/create-post`, - { - method: "POST", - headers: { - Authorization: `${token}`, - }, - body: formData, - } - ); - const data = await resp.json(); - appendPost(data); - setIsCreatePostVisible(false); - } catch (error) { - console.log(error); - } - }; const handleCreateRoom = async () => { try { @@ -111,8 +76,7 @@ const LeftBar = ({ } } setTeacherCode(teacherCode); - - await handleMakeAnnouncement(studentCode); + setStudentCode(studentCode); setIsCreateRecordingVisible(true); } catch (error) { console.error(error); @@ -180,6 +144,7 @@ const LeftBar = ({ setIsCreateRecordingVisible={setIsCreateRecordingVisible} roomId={roomId as string} teacherCode={teacherCode as string} + studentCode={studentCode as string} > )} diff --git a/client/src/components/Modals/CreateRecording.tsx b/client/src/components/Modals/CreateRecording.tsx index 5552c86..e833550 100644 --- a/client/src/components/Modals/CreateRecording.tsx +++ b/client/src/components/Modals/CreateRecording.tsx @@ -10,11 +10,13 @@ const CreateRecordingModal: React.FC<{ setIsCreateRecordingVisible: (isCreateRecordingVisible: boolean) => void; roomId: string; teacherCode: string; + studentCode: string; }> = ({ isCreateRecordingVisible, setIsCreateRecordingVisible, roomId, teacherCode, + studentCode }) => { const router = useRouter(); const [title, setTitle] = useState(""); @@ -22,8 +24,37 @@ const CreateRecordingModal: React.FC<{ const [description, setDescription] = useState(""); const [loading, setLoading] = useState(false); const { token } = useContext(AppContext); + const {appendPost} = useContext(HubContext); const hub_id = router.query.hub_id as string; + const handleMakeAnnouncement = async () => { + const formData = new FormData(); + formData.append("type", "announcement"); + formData.append("title",`Live Class on topic ${topic} has started.`) + formData.append( + "description", + `Join Live class here http://localhost:3000/hub/662e9873bc5597d4fda393cc/live/${studentCode}` + ); + formData.append("topic", "Live Class"); + + try { + const resp = await fetch( + `http://127.0.0.1:5000/api/${btoa(hub_id)}/create-post`, + { + method: "POST", + headers: { + Authorization: `${token}`, + }, + body: formData, + } + ); + const data = await resp.json(); + appendPost(data); + } catch (error) { + console.log(error); + } + }; + const handleCreateRecording = async () => { setLoading(true); try { @@ -40,11 +71,10 @@ const CreateRecordingModal: React.FC<{ room_id: roomId, }), }); + await handleMakeAnnouncement(); setLoading(false); - console.log("successful") - await router.push(`http://localhost:3000/hub/${hub_id}/live/${teacherCode}`); - console.log("redirecting") setIsCreateRecordingVisible(false); + await router.push(`http://localhost:3000/hub/${hub_id}/live/${teacherCode}`); } catch (error) { console.log(error); } @@ -85,7 +115,6 @@ const CreateRecordingModal: React.FC<{ /> diff --git a/server/app/routes/post_routes.py b/server/app/routes/post_routes.py index bcde4c8..dd2dfff 100644 --- a/server/app/routes/post_routes.py +++ b/server/app/routes/post_routes.py @@ -290,7 +290,7 @@ def create_post(hub_id): @post_blueprint.route("/api//get-post/", methods=["GET"]) @limiter.limit("5 per minute") -@firebase_token_required +# @firebase_token_required def get_post(hub_id, post_id): """ Retrieve a specific post within a hub.