Skip to content

Commit 97bc9ed

Browse files
feat: Add course_id to CommentsSections component
This commit adds the course_id prop to the CommentsSections component in multiple files. The course_id is used to ensure that comments are associated with the correct course when rendering and submitting comments. This enhancement improves the accuracy and functionality of the CommentsSections component.
1 parent 82d83f8 commit 97bc9ed

File tree

6 files changed

+38
-8
lines changed

6 files changed

+38
-8
lines changed

app/dashboard/notifications/page.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ export default async function NotificationsPage ({ searchParams }: {
4242
<>
4343
<div className="flex justify-between items-center px-8 py-4 border-b border-gray-200 dark:border-gray-700">
4444
<h1 className="text-2xl font-bold text-gray-800 dark:text-gray-200">
45-
Notifications
45+
Notifications
4646
</h1>
4747
<button className="text-lg text-blue-500">Settings</button>
4848
</div>
4949
<div className="grid md:grid-cols-3 grid-cols-1 gap-4 mt-4 px-8">
5050
<aside className="bg-gray-50 dark:bg-gray-800 p-4 rounded-lg">
5151
<h2 className="text-lg font-semibold text-gray-800 dark:text-gray-200 mb-4">
52-
Filter by type
52+
Filter by type
5353
</h2>
5454
<NotificationSidebarFilter />
5555
</aside>
@@ -75,8 +75,17 @@ export default async function NotificationsPage ({ searchParams }: {
7575
<span>Like</span>
7676
</button> */}
7777
<NotificationsReadButton notification={notification}>
78-
<Eye className="h-5 w-5" />
79-
<span>View</span>
78+
{notification.read ? (
79+
<>
80+
<Eye className="h-5 w-5" />
81+
<span>Viewed</span>
82+
</>
83+
) : (
84+
<>
85+
<Eye className="h-5 w-5" />
86+
<span>View</span>
87+
</>
88+
)}
8089
</NotificationsReadButton>
8190
</div>
8291
</div>

app/dashboard/student/courses/[courseId]/lessons/[lessonsId]/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export default async function StudentLessonPage ({
7878
<TabsContent value="comments">
7979
<Suspense fallback={<div>Loading...</div>}>
8080
<CommentsSections
81+
course_id={Number(params.courseId)}
8182
lesson_id={lessonData.data.id}
8283
lesson_comments={lessonData.data.lesson_comments}
8384
/>

app/dashboard/teacher/courses/[courseId]/lessons/[lessonId]/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export default async function TeacherLessonPage ({
4646
sideBar={
4747
<CommentsSections
4848
lesson_id={lesson?.data?.id}
49+
course_id={lesson?.data?.courses?.course_id}
4950
lesson_comments={lesson?.data?.lesson_comments}
5051
/>
5152
}

components/dashboards/Common/CommentsSections.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ import CommentCard from './comments/CommentsCard'
88

99
export default async function CommentsSections ({
1010
lesson_id,
11+
course_id,
1112
lesson_comments
13+
}: {
14+
lesson_id: number
15+
course_id: number
16+
lesson_comments: any[]
17+
1218
}) {
1319
const supabase = createClient()
1420
const usersIds = lesson_comments.map((comment) => comment.user_id)
@@ -47,6 +53,7 @@ export default async function CommentsSections ({
4753
allComments={lesson_comments}
4854
profiles={profiles.data} // Pass profiles data here
4955
currentUser={currentUser.data.user}
56+
course_id={course_id}
5057
/>
5158
)
5259
})}
@@ -56,7 +63,10 @@ export default async function CommentsSections ({
5663
<CardTitle className="text-lg font-medium">Add a Comment</CardTitle>
5764
</CardHeader>
5865
<CardContent>
59-
<CommentEditor lesson_id={lesson_id} />
66+
<CommentEditor
67+
course_id={course_id}
68+
lesson_id={lesson_id}
69+
/>
6070
</CardContent>
6171
</Card>
6272
</div>

components/dashboards/Common/comments/CommentsCard.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ const CommentCard = ({
3737
isReactionPresent,
3838
allComments,
3939
profiles,
40-
currentUser
40+
currentUser,
41+
course_id
4142
}: {
4243
comment: Tables<'lesson_comments'>
4344
name: string
@@ -49,6 +50,7 @@ const CommentCard = ({
4950
allComments: any[]
5051
profiles: Array<Tables<'profiles'>>
5152
currentUser: User
53+
course_id: number
5254
}) => {
5355
const [showReplies, setShowReplies] = useState(false)
5456
const [isEditing, setIsEditing] = useState(false)
@@ -124,6 +126,7 @@ const CommentCard = ({
124126
<CommentEditor
125127
lesson_id={comment.lesson_id}
126128
comment_id={comment.id}
129+
course_id={course_id}
127130
parent_comment_id={comment.parent_comment_id}
128131
callback={() => setIsEditing(false)}
129132
/>
@@ -133,7 +136,10 @@ const CommentCard = ({
133136
{showReplies && (
134137
<div className="ml-1 mt-2">
135138
<div className="flex flex-col gap-4">
136-
<CommentEditor lesson_id={comment.lesson_id} parent_comment_id={comment.id} callback={() => { setShowReplies(false) }} />
139+
<CommentEditor
140+
course_id={course_id}
141+
lesson_id={comment.lesson_id} parent_comment_id={comment.id} callback={() => { setShowReplies(false) }}
142+
/>
137143
<Button variant="destructive" onClick={toggleReplies}>Cancel</Button>
138144
</div>
139145
</div>
@@ -190,6 +196,7 @@ const CommentCard = ({
190196
<CommentCard
191197
key={reply.id}
192198
comment={reply}
199+
course_id={course_id}
193200
name={replyUser?.full_name || 'Unknown'}
194201
avatar={replyUser?.avatar_url || '/img/favicon.png'}
195202
date={dayjs(reply.created_at).format('DD/MM/YYYY: HH:mm')}

components/dashboards/student/course/lessons/CommentEditor.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ export default function CommentEditor ({
1111
lesson_id,
1212
parent_comment_id,
1313
comment_id,
14+
course_id,
1415
callback
1516
}: {
1617
lesson_id: number
1718
parent_comment_id?: number
19+
course_id: number
1820
comment_id?: number
1921
callback?: () => void
2022
}) {
@@ -23,7 +25,7 @@ export default function CommentEditor ({
2325
const { toast } = useToast()
2426

2527
const submitComment = async () => {
26-
const payload = comment_id ? { content: commentState, commentId: comment_id } : { comment: commentState, lesson_id, parent_comment_id }
28+
const payload = comment_id ? { content: commentState, commentId: comment_id } : { comment: commentState, lesson_id, parent_comment_id, course_id }
2729
const action = comment_id ? updateComment : studentSubmitLessonComment
2830

2931
try {

0 commit comments

Comments
 (0)