-
Notifications
You must be signed in to change notification settings - Fork 526
Lesson Feedback - fix missing params #70726
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,6 @@ import i18n from '@cdo/locale'; | |
| import ActionButtons from './ActionButtons'; | ||
| import FeedbackTextbox from './FeedbackTextbox'; | ||
| import RecommendedActions from './RecommendedActions'; | ||
| import {useLessonFeedback} from './useLessonFeedback'; | ||
|
|
||
| import styles from './lessonFeeedback.module.scss'; | ||
|
|
||
|
|
@@ -17,6 +16,7 @@ interface LessonFeedbackWidgetProps { | |
| teacherHasEnabledAi: boolean; | ||
| studentId: number | null; | ||
| unitId: number | null; | ||
| sectionId: number | null; | ||
| } | ||
|
|
||
| interface LessonFeedbackData { | ||
|
|
@@ -34,6 +34,7 @@ const LessonFeedbackWidget: React.FC<LessonFeedbackWidgetProps> = ({ | |
| teacherHasEnabledAi = false, | ||
| studentId, | ||
| unitId, | ||
| sectionId, | ||
| }) => { | ||
| const [feedbackText, setFeedbackText] = React.useState<string>(''); | ||
| const [existingFeedbackData, setExistingFeedbackData] = | ||
|
|
@@ -51,17 +52,19 @@ const LessonFeedbackWidget: React.FC<LessonFeedbackWidgetProps> = ({ | |
| resource_link: '', | ||
| }, | ||
| ]); | ||
| const [isLoading, setIsLoading] = React.useState<boolean>(false); | ||
|
|
||
| // Fetch lesson feedback from backend, and if not found, try generating ai feedback | ||
| React.useEffect(() => { | ||
| async function getAiLessonFeedback( | ||
| lessonId: number, | ||
| unitId: number, | ||
| studentId: number | ||
| studentId: number, | ||
| sectionId: number | ||
| ) { | ||
| try { | ||
| const response = await fetch( | ||
| `/student_snapshots/ai_generated_lesson_feedback?lesson_id=${lessonId}&unit_id=${unitId}&student_id=${studentId}` | ||
| `/student_snapshots/ai_generated_lesson_feedback?lesson_id=${lessonId}&unit_id=${unitId}&student_id=${studentId}§ion_id=${sectionId}` | ||
| ); | ||
| if (!response.ok) { | ||
| throw new Error( | ||
|
|
@@ -77,7 +80,7 @@ const LessonFeedbackWidget: React.FC<LessonFeedbackWidgetProps> = ({ | |
| } | ||
|
|
||
| async function fetchLessonFeedback() { | ||
| if (!lessonId || !studentId || !unitId) { | ||
| if (!lessonId || !studentId || !unitId || !sectionId) { | ||
| setFeedbackText(''); | ||
| setResourceData([ | ||
| {recommended_action: '', resource_name: '', resource_link: ''}, | ||
|
|
@@ -95,7 +98,12 @@ const LessonFeedbackWidget: React.FC<LessonFeedbackWidgetProps> = ({ | |
|
|
||
| if (!response.ok) { | ||
| // Try getting AI feedback from student work. | ||
| const aiData = await getAiLessonFeedback(lessonId, unitId, studentId); | ||
| const aiData = await getAiLessonFeedback( | ||
| lessonId, | ||
| unitId, | ||
| studentId, | ||
| sectionId | ||
| ); | ||
| if (aiData && aiData.json) { | ||
| const aiGeneratedInitialFeedback = JSON.parse(aiData.json).feedback; | ||
| setFeedbackText(aiGeneratedInitialFeedback); | ||
|
|
@@ -122,15 +130,15 @@ const LessonFeedbackWidget: React.FC<LessonFeedbackWidgetProps> = ({ | |
| setResourceData([ | ||
| {recommended_action: '', resource_name: '', resource_link: ''}, | ||
| ]); | ||
| } finally { | ||
| setIsLoading(false); | ||
| } | ||
| } | ||
| fetchLessonFeedback(); | ||
| }, [lessonId, studentId, unitId]); | ||
| // Existing hook usage | ||
| const {isLoading, scrollable, handleSendToStudent} = useLessonFeedback({ | ||
| lessonId, | ||
| teacherHasEnabledAi, | ||
| }); | ||
| if (lessonId && studentId && unitId && sectionId) { | ||
| setIsLoading(true); | ||
| fetchLessonFeedback(); | ||
| } | ||
| }, [lessonId, sectionId, studentId, unitId]); | ||
|
Comment on lines
137
to
141
|
||
|
|
||
| // Save as draft: update local state and persist to backend | ||
| const handleSaveAsDraft = async () => { | ||
|
|
@@ -207,7 +215,9 @@ const LessonFeedbackWidget: React.FC<LessonFeedbackWidgetProps> = ({ | |
| /> | ||
| <ActionButtons | ||
| onSaveAsDraft={handleSaveAsDraft} | ||
| onSendToStudent={handleSendToStudent} | ||
| onSendToStudent={() => { | ||
| console.log('Send to student:', feedbackText, resourceData); | ||
| }} | ||
|
Comment on lines
+218
to
+220
|
||
| /> | ||
| </div> | ||
| ); | ||
|
|
@@ -218,7 +228,7 @@ const LessonFeedbackWidget: React.FC<LessonFeedbackWidgetProps> = ({ | |
| gridWidth={2} | ||
| gridHeight={2} | ||
| loading={isLoading} | ||
| scrollable={scrollable} | ||
| scrollable={true} | ||
| > | ||
| {widgetContent} | ||
| </WidgetTemplate> | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,20 +31,19 @@ def ai_generated_lesson_feedback | |
| lesson_id = params[:lesson_id] | ||
| unit_id = params[:unit_id] | ||
| student_id = params[:student_id] | ||
|
|
||
| section_id = nil | ||
| teacher_id = nil | ||
| if student_id && unit_id | ||
| student = User.find_by(id: student_id) | ||
| if student | ||
| section = student.sections_as_student.joins(:script).where(scripts: {id: unit_id}).first | ||
| section_id = section&.id | ||
| teacher_id = section&.teacher&.id | ||
| end | ||
| end | ||
| teacher_id = current_user.id | ||
| section_id = params[:section_id] | ||
|
|
||
| return render json: {error: "Missing required parameters"}, status: :bad_request unless lesson_id && unit_id && student_id && section_id | ||
|
Comment on lines
31
to
37
|
||
|
|
||
| # Validate that the section belongs to the current teacher | ||
| section = Section.find_by(id: section_id) | ||
| return render json: {error: "Section not found"}, status: :not_found unless section | ||
|
|
||
| unless section.user_id == teacher_id || section.instructors.exists?(id: teacher_id) | ||
| return render json: {error: "Unauthorized access to section"}, status: :forbidden | ||
| end | ||
|
|
||
| response = AiStudentSnapshotHelper.generate_lesson_feedback(unit_id, lesson_id, teacher_id, student_id, section_id) | ||
|
|
||
| render json: response | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isLoadingis set totruewhen the effect runs, but there’s no correspondingsetIsLoading(false)shown afterfetchLessonFeedbackcompletes (or when the guard prevents fetching). This can leave the widget in a perpetual loading state. Consider movingsetIsLoading(true)inside theif (lessonId && studentId && unitId && sectionId)block and ensuringsetIsLoading(false)is set in afinallyblock withinfetchLessonFeedback(and also in any early-return paths).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: I took this feedback