mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: mark lectures as done
This commit is contained in:
parent
cf7285b6f9
commit
a9c3d24c62
3 changed files with 47 additions and 24 deletions
|
|
@ -10,6 +10,7 @@ import styled from "styled-components";
|
||||||
import { getCourse, getCourseMetadata } from "../../../../../../../services/courses/courses";
|
import { getCourse, getCourseMetadata } from "../../../../../../../services/courses/courses";
|
||||||
import VideoLecture from "@components/LectureViews/Video/Video";
|
import VideoLecture from "@components/LectureViews/Video/Video";
|
||||||
import { Check } from "lucide-react";
|
import { Check } from "lucide-react";
|
||||||
|
import { maskLectureAsComplete } from "@services/courses/activity";
|
||||||
|
|
||||||
function LecturePage(params: any) {
|
function LecturePage(params: any) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
@ -32,6 +33,11 @@ function LecturePage(params: any) {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function markLectureAsCompleteFront() {
|
||||||
|
const activity = await maskLectureAsComplete("" + lectureid, courseid, lecture.lecture_id.replace("lecture_", ""));
|
||||||
|
fetchCourseData();
|
||||||
|
}
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (lectureid) {
|
if (lectureid) {
|
||||||
fetchLectureData();
|
fetchLectureData();
|
||||||
|
|
@ -85,10 +91,24 @@ function LecturePage(params: any) {
|
||||||
{lecture.type == "video" && <VideoLecture course={course} lecture={lecture} />}
|
{lecture.type == "video" && <VideoLecture course={course} lecture={lecture} />}
|
||||||
|
|
||||||
<ActivityMarkerWrapper>
|
<ActivityMarkerWrapper>
|
||||||
<button> <i><Check size={20}></Check></i> Mark as complete</button>
|
{course.activity.lectures_marked_complete.includes("lecture_"+lectureid) ? (
|
||||||
|
<button style={{ backgroundColor: "green" }}>
|
||||||
|
<i>
|
||||||
|
<Check size={20}></Check>
|
||||||
|
</i>{" "}
|
||||||
|
Already completed
|
||||||
|
</button>
|
||||||
|
) : (
|
||||||
|
<button onClick={markLectureAsCompleteFront}>
|
||||||
|
{" "}
|
||||||
|
<i>
|
||||||
|
<Check size={20}></Check>
|
||||||
|
</i>{" "}
|
||||||
|
Mark as complete
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
</ActivityMarkerWrapper>
|
</ActivityMarkerWrapper>
|
||||||
</CourseContent>
|
</CourseContent>
|
||||||
|
|
||||||
</LectureLayout>
|
</LectureLayout>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|
@ -169,8 +189,7 @@ const ActivityMarkerWrapper = styled.div`
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
||||||
|
button {
|
||||||
button{
|
|
||||||
background-color: #151515;
|
background-color: #151515;
|
||||||
border: none;
|
border: none;
|
||||||
padding: 18px;
|
padding: 18px;
|
||||||
|
|
@ -190,20 +209,17 @@ const ActivityMarkerWrapper = styled.div`
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
letter-spacing: -0.05em;
|
letter-spacing: -0.05em;
|
||||||
box-shadow: 0px 13px 33px -13px rgba(0, 0, 0, 0.42);
|
box-shadow: 0px 13px 33px -13px rgba(0, 0, 0, 0.42);
|
||||||
|
|
||||||
|
|
||||||
i{
|
i {
|
||||||
margin-right: 5px;
|
margin-right: 5px;
|
||||||
|
|
||||||
// center the icon
|
// center the icon
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&:hover{
|
&:hover {
|
||||||
background-color: #000000;
|
background-color: #000000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,3 +22,10 @@ export async function closeActivity(org_id: string, activity_id: string) {
|
||||||
.catch((error) => console.log("error", error));
|
.catch((error) => console.log("error", error));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function maskLectureAsComplete(org_id: string, course_id: string, lecture_id: string) {
|
||||||
|
const result: any = await fetch(`${getAPIUrl()}activity/${org_id}/add_lecture/${course_id}/${lecture_id}`, RequestBody("POST", null))
|
||||||
|
.then((result) => result.json())
|
||||||
|
.catch((error) => console.log("error", error));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
from cmath import log
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import json
|
import json
|
||||||
from typing import List, Literal, Optional
|
from typing import List, Literal, Optional
|
||||||
|
|
@ -14,8 +15,8 @@ class Activity(BaseModel):
|
||||||
course_id: str
|
course_id: str
|
||||||
status: Optional[Literal['ongoing', 'done', 'closed']] = 'ongoing'
|
status: Optional[Literal['ongoing', 'done', 'closed']] = 'ongoing'
|
||||||
masked: Optional[bool] = False
|
masked: Optional[bool] = False
|
||||||
lectures_marked_complete: Optional[List[str]]
|
lectures_marked_complete: Optional[List[str]] = []
|
||||||
lectures_data: Optional[List[dict]]
|
lectures_data: Optional[List[dict]] = []
|
||||||
|
|
||||||
|
|
||||||
class ActivityInDB(Activity):
|
class ActivityInDB(Activity):
|
||||||
|
|
@ -70,29 +71,28 @@ async def get_user_activities(request: Request, user: PublicUser, org_id: str):
|
||||||
|
|
||||||
async def add_lecture_to_activity(request: Request, user: PublicUser, org_id: str, course_id: str, lecture_id: str):
|
async def add_lecture_to_activity(request: Request, user: PublicUser, org_id: str, course_id: str, lecture_id: str):
|
||||||
activities = request.app.db["activities"]
|
activities = request.app.db["activities"]
|
||||||
|
print(lecture_id)
|
||||||
|
course_id = f"course_{course_id}"
|
||||||
|
lecture_id = f"lecture_{lecture_id}"
|
||||||
|
print(lecture_id)
|
||||||
activity = activities.find_one(
|
activity = activities.find_one(
|
||||||
{"course_id": course_id,
|
{"course_id": course_id,
|
||||||
"user_id": user.user_id,
|
"user_id": user.user_id
|
||||||
"org_id": org_id
|
}, {'_id': 0})
|
||||||
})
|
|
||||||
|
|
||||||
if not activity:
|
if not activity:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_409_CONFLICT, detail="Activity not found")
|
status_code=status.HTTP_409_CONFLICT, detail="Activity not found")
|
||||||
|
|
||||||
if lecture_id in activity['lectures_marked_complete']:
|
if lecture_id not in activity['lectures_marked_complete']:
|
||||||
|
activity['lectures_marked_complete'].append(str(lecture_id))
|
||||||
|
activities.update_one(
|
||||||
|
{"activity_id": activity['activity_id']}, {"$set": activity})
|
||||||
|
return activity
|
||||||
|
else:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_409_CONFLICT, detail="Lecture already marked complete")
|
status_code=status.HTTP_409_CONFLICT, detail="Lecture already marked complete")
|
||||||
|
|
||||||
activity['lectures_marked_complete'].append(lecture_id)
|
|
||||||
|
|
||||||
activities.update_one(
|
|
||||||
{"activity_id": activity['activity_id']}, {"$set": activity})
|
|
||||||
|
|
||||||
# send 200 custom message
|
|
||||||
return {"message": "Lecture added to activity"}
|
|
||||||
|
|
||||||
|
|
||||||
async def close_activity(request: Request, user: PublicUser, activity_id: str, org_id: str,):
|
async def close_activity(request: Request, user: PublicUser, activity_id: str, org_id: str,):
|
||||||
activities = request.app.db["activities"]
|
activities = request.app.db["activities"]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue