Skip to content

Commit be5f8dd

Browse files
committed
Finished
1 parent c3ab264 commit be5f8dd

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

frontend/src/ai/flows/suggest-resources.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export async function suggestResources(input: SuggestResourcesInput, userId: str
5151
if (!res.ok) throw new Error(`Failed to generate flashcards from backend agent: ${res.status}`);
5252

5353
const output = (await res.json())[0]?.content?.parts?.[0]?.text;
54+
console.log("Output: ", output);
5455
const data = await extractJsonFromResponse(output);
5556

5657
let result;

frontend/src/components/dashboard/ResourceSuggester.tsx

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import { useState } from 'react';
3+
import { useState, useEffect } from 'react';
44
import { Button } from '@/components/ui/button';
55
import { Textarea } from '@/components/ui/textarea';
66
import { Label } from '@/components/ui/label';
@@ -12,23 +12,48 @@ import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle }
1212
import Link from 'next/link';
1313

1414
export function ResourceSuggester() {
15-
const [courseContent, setCourseContent] = useState('');
15+
const [courseMaterial, setCourseMaterial] = useState('');
1616
const [suggestedResources, setSuggestedResources] = useState<SuggestedResource[]>([]);
1717
const [isLoading, setIsLoading] = useState(false);
1818
const { toast } = useToast();
19+
const [materialError, setMaterialError] = useState<string | null>(null);
20+
21+
// Load course material from localStorage on mount
22+
useEffect(() => {
23+
try {
24+
const filename = localStorage.getItem('latest_course_material');
25+
if (!filename) {
26+
setMaterialError('No course material uploaded. Please upload a PDF or PPTX first.');
27+
setCourseMaterial('');
28+
return;
29+
}
30+
const content = localStorage.getItem(`course_material_${filename}`);
31+
if (!content) {
32+
setMaterialError('Stored course material not found or corrupted. Please re-upload.');
33+
setCourseMaterial('');
34+
return;
35+
}
36+
setCourseMaterial(content);
37+
setMaterialError(null);
38+
} catch (err) {
39+
setMaterialError('Failed to load course material.');
40+
setCourseMaterial('');
41+
}
42+
}, []);
43+
1944

2045
const handleSuggestResources = async (e: React.FormEvent) => {
2146
e.preventDefault();
22-
if (!courseContent.trim()) {
47+
if (!courseMaterial.trim()) {
2348
toast({ title: 'Empty Content', description: 'Please paste your course content.', variant: 'destructive' });
2449
return;
2550
}
2651
setIsLoading(true);
2752
setSuggestedResources([]);
2853
try {
29-
const input: SuggestResourcesInput = { courseContent };
54+
const input: SuggestResourcesInput = { courseContent: courseMaterial };
3055
const userId = localStorage.getItem('userID') || '';
31-
const sessionId = localStorage.getItem('sessionId') || '';
56+
const sessionId = localStorage.getItem('session_id') || '';
3257
const result: SuggestResourcesOutput = await suggestResources(input, userId, sessionId);
3358
setSuggestedResources(result);
3459
if (result.length === 0) {
@@ -66,8 +91,8 @@ export function ResourceSuggester() {
6691
</Label>
6792
<Textarea
6893
id="resourceContent"
69-
value={courseContent}
70-
onChange={(e) => setCourseContent(e.target.value)}
94+
value={courseMaterial}
95+
onChange={(e) => setCourseMaterial(e.target.value)}
7196
placeholder="Paste course topics or specific text here..."
7297
rows={8}
7398
className="text-base"

0 commit comments

Comments
 (0)