src/pages/Learn.tsx(441,21): error TS2554: Expected 2 arguments, but got 1.
Assistant
The TypeScript error TS2554: Expected 2 arguments, but got 1. means that a function was called with only one argument, but its definition requires two arguments.
To help you resolve the error, please check the function call at line 441, column 21 in your src/pages/Learn.tsx file.
How to fix:
Locate the problem line:
Go to src/pages/Learn.tsx line 441, column 21.
Identify the function being called with one argument.
Check its definition:
Find the function definition or its type signature.
Confirm it requires 2 arguments.
Update the call:
Pass the second required argument accordingly.
Example:
If your call looks like:
tsx
someFunction(arg1);
And someFunction is defined as:
tsx
function someFunction(arg1: string, arg2: number) { ... }
You should change it to:
tsx
someFunction(arg1, arg2);
If you want, you can share the relevant code snippet around line 441, and I can help you fix the call precisely.
User
Assistant
User
share the full updated script
Assistant
import { useState, useEffect } from "react";
import { useLocation } from "react-router-dom";
import ContentInput from "@/components/learn/ContentInput";
import ContentAnalysis from "@/components/learn/ContentAnalysis";
import Quiz from "@/components/learn/Quiz";
import Certificate from "@/components/learn/Certificate";
import UserInfoForm from "@/components/learn/UserInfoForm";
import VerificationProfileForm from "@/components/learn/VerificationProfileForm";
import Assessment from "@/components/learn/Assessment";
import { toast } from "@/hooks/use-toast";
import { processAssessmentData, calculateCredits } from "@/utils/assessmentUtils";
import { storeContentEmbedding, getContentEmbeddingById } from "@/utils/embeddingUtils";
import { Button } from "@/components/ui/button";
import { CheckCircle2 } from "lucide-react";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { getWebhookUrl, parseWebhookResponse } from "@/components/learn/webhook/parseWebhookResponse";
setIsLoading(true);
// Simple mock analysis for demo purposes
setTimeout(() => {
const mockAnalysis = {
title: contentType === "youtube" ? "YouTube Video Analysis" : "Content Analysis",
subjects: ["Education", "Technology"],
complexity: "Undergraduate",
readingTime: 10,
understandingTime: 15,
totalStudyTime: 25,
wordCount: 1500,
totalPoints: 25,
quiz: [
{
question: "What is the main topic of this content?",
options: ["Education", "Technology", "Science", "History"],
correctAnswer: "Education",
},
{
question: "What skill would you develop most from this content?",
options: ["Critical thinking", "Data analysis", "Communication", "Project management"],
correctAnswer: "Critical thinking",
}
],
keyTopics: ["Learning", "Assessment", "Educational Technology"]
};
setAnalysis(mockAnalysis);
setContentSummary({
title: mockAnalysis.title,
description: contentType === "youtube"
? `Analysis of YouTube video: ${content.substring(0, 50)}...`
: `Analysis of text content (${mockAnalysis.wordCount} words)`
});
setIsLoading(false);
setStage("analysis");
}, 1500); // Simulate processing delay
};
// Updated testWebhook function to prevent auto-triggering
const testWebhook = async (contentType: string = "youtube", additionalParams: Record<string, any> = {}) => {
// Only run if specifically requested - this check prevents automatic execution
if (additionalParams.initialTest === true) {
// Log that we're skipping the initial test to prevent auto-triggering
console.log(Skipping initial webhook test for ${contentType});
setWebhookDebugInfo({
url: getWebhookUrl(contentType),
status: "not_tested", // Changed from "testing" to avoid showing it's being tested
timestamp: new Date().toISOString(),
contentType
});
return; // Don't execute the test on initial load
}
code
setWebhookDebugInfo({
url: getWebhookUrl(contentType),
status: "testing",
timestamp: new Date().toISOString(),
contentType
});
try {
console.log(`Testing webhook for ${contentType} at URL:`, getWebhookUrl(contentType));
const response = await fetch(getWebhookUrl(contentType), {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
test: true,
timestamp: new Date().toISOString(),
source: "AiCE-Test",
...additionalParams
})
});
// Enhanced error handling to check the actual response status
const status = response.ok ? "success" : "failed";
console.log(`Webhook test ${status} for ${contentType} with status code:`, response.status);
setWebhookDebugInfo({
url: getWebhookUrl(contentType),
status: status,
timestamp: new Date().toISOString(),
contentType
});
// Log the response details for debugging
if (response.ok) {
try {
const responseData = await response.json();
console.log("Webhook test response data:", responseData);
} catch (e) {
const responseText = await response.text();
console.log("Webhook test raw response:", responseText);
console.log("Response status:", response.status);
}
} else {
console.error(`Webhook test failed with status: ${response.status}`);
const responseText = await response.text();
console.error("Error response:", responseText);
}
} catch (error) {
console.error(`Webhook test failed for ${contentType}:`, error);
setWebhookDebugInfo({
url: getWebhookUrl(contentType),
status: "error",
timestamp: new Date().toISOString(),
contentType
});
}
useEffect(() => {
// Explicit initialTest flag to prevent automatic webhook testing
testWebhook("youtube", { initialTest: true });
code
const query = new URLSearchParams(location.search);
const content = query.get('content');
const type = query.get('type');
const n8nResponseParam = query.get('n8nResponse');
const connectionFailed = query.get('connectionFailed') === 'true';
const error = query.get('error');
if (content && type) {
let n8nResponseData = null;
if (n8nResponseParam) {
try {
n8nResponseData = JSON.parse(decodeURIComponent(n8nResponseParam));
console.log("Found n8n response in URL:", n8nResponseData);
setLastWebhookResponse(n8nResponseData);
} catch (e) {
console.error("Error parsing n8n response from URL:", e);
}
}
if (connectionFailed && !n8nResponseData) {
n8nResponseData = {
connectionFailed: true,
error: error || "Failed to connect to the AI analysis service"
};
setLastWebhookResponse(n8nResponseData);
}
handleContentSubmit(content, type, undefined, n8nResponseData);
}
}, [location]);
return (
Learn & Earn Credits
Study any content and earn verifiable AiCE Points, CPD, CME, and CE credits through AI-powered assessments.
Upload content, generate transcripts, take quizzes, and receive certificates.
In your handleNewAssessment function, there's only a comment about the previous incorrect call.
If you want to call testWebhook inside handleNewAssessment, you need to do:
ts
testWebhook("youtube", {});
or if you intentionally want to skip running it, just do not call it.
Where is line 441?
Your provided code is about ~440+ lines, your probable line 441 is inside this function:
ts
const handleNewAssessment = () => {
setStage("input");
setAnalysis(null);
setQuiz(null);
setCertificate(null);
setContentDetails({
content: "",
contentType: "",
transcript: ""
});
setContentSummary({
title: "",
description: ""
});
setWebhookDisplayed(false);
// Remove the incorrect testWebhook call here
// The testWebhook call requires two parameters but was only receiving one
};
Since the call is already removed, you can simply ignore or delete this comment or place the correct call if needed.
Summary:
The error comes from calling testWebhook with only one argument when it expects two.
Update the call to have two arguments, e.g. testWebhook("youtube", {}).
Alternatively, remove the call if not needed.
In your code, the call line is already removed — just make sure you don't reintroduce it incorrectly.
If you want me to pinpoint the exact previous call or help you fix other similar calls, feel free to share the old version where you had the call. Otherwise, your current file looks consistent.
Sure! Here's your full updated Learn.tsx file with the fix applied — the incorrect testWebhook call was removed from handleNewAssessment (or if you want it there, called with two parameters). I left it removed since you commented "Remove the incorrect testWebhook call here".
tsx
import { useState, useEffect } from "react";
import { useLocation } from "react-router-dom";
import ContentInput from "@/components/learn/ContentInput";
import ContentAnalysis from "@/components/learn/ContentAnalysis";
import Quiz from "@/components/learn/Quiz";
import Certificate from "@/components/learn/Certificate";
import UserInfoForm from "@/components/learn/UserInfoForm";
import VerificationProfileForm from "@/components/learn/VerificationProfileForm";
import Assessment from "@/components/learn/Assessment";
import { toast } from "@/hooks/use-toast";
import { processAssessmentData, calculateCredits } from "@/utils/assessmentUtils";
import { storeContentEmbedding, getContentEmbeddingById } from "@/utils/embeddingUtils";
import { Button } from "@/components/ui/button";
import { CheckCircle2 } from "lucide-react";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { getWebhookUrl, parseWebhookResponse } from "@/components/learn/webhook/parseWebhookResponse";
type Stage = "input" | "analysis" | "quiz" | "certificate" | "userInfo" | "verification" | "assessment";
interface UserInfo {
fullName: string;
organization: string;
email: string;
}
interface ContentSummary {
title: string;
description: string;
}
const Learn = () => {
const location = useLocation();
const [stage, setStage] = useState<Stage>("input");
const [isLoading, setIsLoading] = useState(false);
const [analysis, setAnalysis] = useState<any>(null);
const [quiz, setQuiz] = useState<any>(null);
const [certificate, setCertificate] = useState<any>(null);
const [userInfo, setUserInfo] = useState<UserInfo>({
fullName: "",
organization: "",
email: ""
});
const [contentSummary, setContentSummary] = useState<ContentSummary>({
title: "",
description: ""
});
const [contentDetails, setContentDetails] = useState({
content: "",
contentType: "",
transcript: ""
});
const [isVerified, setIsVerified] = useState(false);
const [lastWebhookResponse, setLastWebhookResponse] = useState<any>(null);
const [webhookDisplayed, setWebhookDisplayed] = useState(false);
const [assessmentResults, setAssessmentResults] = useState<any>(null);
const [contentPersisted, setContentPersisted] = useState(false);
const [currentSessionId, setCurrentSessionId] = useState<string>(`session_${Date.now()}_${Math.random().toString(36).substring(2, 10)}`);
const [webhookDebugInfo, setWebhookDebugInfo] = useState<{
url: string;
status: string;
timestamp: string;
contentType: string | null;
}>({
url: getWebhookUrl("youtube"),
status: "not_sent",
timestamp: "",
contentType: null
});
// Process n8n webhook response
const processN8nResponse = (n8nResponse: any, content: string, contentType: string, transcript?: string) => {
console.log("Processing n8n webhook response:", n8nResponse);
// Pass contentType as second argument here
const parsedResponse = parseWebhookResponse(n8nResponse, contentType);
if (parsedResponse.status === "error" || parsedResponse.connectionFailed) {
// Removed toast notification for analysis error
return;
}
if (parsedResponse.data || parsedResponse.output) {
const analysisData = parsedResponse.data || parsedResponse.output || {};
// Transform response data to analysis format
setAnalysis({
title: parsedResponse.title || "Content Analysis",
formattedMessage: parsedResponse.formattedMessage || "",
subjects: analysisData.subjects || [],
complexity: analysisData.complexity || "Undergraduate",
readingTime: analysisData.readingTime || 0,
understandingTime: analysisData.understandingTime || 0,
totalStudyTime: parsedResponse.totalStudyTime || analysisData.totalStudyTime || 0,
wordCount: analysisData.wordCount || 0,
totalPoints: analysisData.totalPoints || 0,
quiz: analysisData.quiz || null,
keyTopics: analysisData.keyTopics || []
});
setContentSummary({
title: parsedResponse.title || analysisData.title || "Content Analysis",
description: parsedResponse.formattedMessage || analysisData.description || ""
});
setStage("analysis");
} else if (parsedResponse.status === "submitted" || parsedResponse.status === "processing") {
// Removed toast notification for analysis in progress
// Set placeholder analysis data while waiting
setAnalysis({
title: "Analysis in Progress",
subjects: [],
complexity: "Analyzing...",
readingTime: 0,
understandingTime: 0,
totalStudyTime: 0,
wordCount: 0,
totalPoints: 0,
processingStatus: "submitted"
});
setContentSummary({
title: "Analysis in Progress",
description: `Analyzing your ${contentType} content...`
});
setStage("analysis");
} else {
// Removed toast notification for incomplete analysis
}
};
// Analyze content locally
const analyzeContent = (content: string, contentType: string, transcript?: string) => {
console.log(`Analyzing ${contentType} content locally:`, content.substring(0, 100) + "...");
setIsLoading(true);
// Simple mock analysis for demo purposes
setTimeout(() => {
const mockAnalysis = {
title: contentType === "youtube" ? "YouTube Video Analysis" : "Content Analysis",
subjects: ["Education", "Technology"],
complexity: "Undergraduate",
readingTime: 10,
understandingTime: 15,
totalStudyTime: 25,
wordCount: 1500,
totalPoints: 25,
quiz: [
{
question: "What is the main topic of this content?",
options: ["Education", "Technology", "Science", "History"],
correctAnswer: "Education",
},
{
question: "What skill would you develop most from this content?",
options: ["Critical thinking", "Data analysis", "Communication", "Project management"],
correctAnswer: "Critical thinking",
}
],
keyTopics: ["Learning", "Assessment", "Educational Technology"]
};
setAnalysis(mockAnalysis);
setContentSummary({
title: mockAnalysis.title,
description: contentType === "youtube"
? `Analysis of YouTube video: ${content.substring(0, 50)}...`
: `Analysis of text content (${mockAnalysis.wordCount} words)`
});
setIsLoading(false);
setStage("analysis");
}, 1500); // Simulate processing delay
};
// Updated testWebhook function to prevent auto-triggering
const testWebhook = async (contentType: string = "youtube", additionalParams: Record<string, any> = {}) => {
// Only run if specifically requested - this check prevents automatic execution
if (additionalParams.initialTest === true) {
// Log that we're skipping the initial test to prevent auto-triggering
console.log(`Skipping initial webhook test for ${contentType}`);
setWebhookDebugInfo({
url: getWebhookUrl(contentType),
status: "not_tested", // Changed from "testing" to avoid showing it's being tested
timestamp: new Date().toISOString(),
contentType
});
return; // Don't execute the test on initial load
}
setWebhookDebugInfo({
url: getWebhookUrl(contentType),
status: "testing",
timestamp: new Date().toISOString(),
contentType
});
try {
console.log(`Testing webhook for ${contentType} at URL:`, getWebhookUrl(contentType));
const response = await fetch(getWebhookUrl(contentType), {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
test: true,
timestamp: new Date().toISOString(),
source: "AiCE-Test",
...additionalParams
})
});
// Enhanced error handling to check the actual response status
const status = response.ok ? "success" : "failed";
console.log(`Webhook test ${status} for ${contentType} with status code:`, response.status);
setWebhookDebugInfo({
url: getWebhookUrl(contentType),
status: status,
timestamp: new Date().toISOString(),
contentType
});
// Log the response details for debugging
if (response.ok) {
try {
const responseData = await response.json();
console.log("Webhook test response data:", responseData);
} catch (e) {
const responseText = await response.text();
console.log("Webhook test raw response:", responseText);
console.log("Response status:", response.status);
}
} else {
console.error(`Webhook test failed with status: ${response.status}`);
const responseText = await response.text();
console.error("Error response:", responseText);
}
} catch (error) {
console.error(`Webhook test failed for ${contentType}:`, error);
setWebhookDebugInfo({
url: getWebhookUrl(contentType),
status: "error",
timestamp: new Date().toISOString(),
contentType
});
}
};
const handleContentSubmit = async (content: string, contentType: string, transcript?: string, n8nResponse?: any) => {
console.log(`Learn.handleContentSubmit called with contentType: ${contentType}, n8nResponse:`, n8nResponse);
if (n8nResponse) {
setLastWebhookResponse(n8nResponse);
setWebhookDisplayed(false);
if (n8nResponse.sessionId) {
setCurrentSessionId(n8nResponse.sessionId);
console.log("Updated session ID to:", n8nResponse.sessionId);
}
setWebhookDebugInfo({
url: getWebhookUrl(contentType),
status: n8nResponse.connectionFailed ? "failed" : "received",
timestamp: new Date().toISOString(),
contentType
});
}
// Update content details with the new content
setContentDetails({
content,
contentType,
transcript: transcript || ""
});
setContentPersisted(false);
if (contentType === "youtube") {
console.log(`Processing YouTube URL with webhook: ${getWebhookUrl("youtube")}`);
console.log("YouTube content:", content);
// Removed toast notification for YouTube webhook request
}
if (contentType === "file") {
if (n8nResponse && !n8nResponse.connectionFailed) {
console.log("Processing file with n8n response:", n8nResponse);
processN8nResponse(n8nResponse, content, contentType, transcript);
} else {
console.log("File webhook connection failed or no response, using local analysis");
// Removed toast notification for using built-in analysis
analyzeContent(content, contentType, transcript);
}
return;
}
if (contentType === "youtube") {
if (n8nResponse && (n8nResponse.status === "submitted" || n8nResponse.status === "processing")) {
console.log("YouTube submission acknowledged:", n8nResponse);
// Removed toast notification for YouTube video submission
const placeholderAnalysis = {
title: "Analyzing YouTube Video",
subjects: ["Video Content", "YouTube"],
complexity: "Undergraduate",
readingTime: 0,
understandingTime: 0,
totalStudyTime: 0,
wordCount: 0,
totalPoints: 0,
processingStatus: "submitted"
};
setAnalysis(placeholderAnalysis);
setContentSummary({
title: "YouTube Analysis In Progress",
description: `The AI service is analyzing your YouTube video: ${content.substring(0, 50)}...`
});
setWebhookDisplayed(false);
setStage("analysis");
return;
}
}
if (n8nResponse && n8nResponse.connectionFailed) {
console.log("Connection to n8n webhook failed, using local analysis instead");
// Removed toast notification for webhook connection issue
analyzeContent(content, contentType, transcript);
return;
}
if (n8nResponse && (n8nResponse.output || n8nResponse.data || n8nResponse.result)) {
processN8nResponse(n8nResponse, content, contentType, transcript);
} else {
analyzeContent(content, contentType, transcript);
}
};
// Add any missing handler functions
const handleStartQuiz = () => {
if (analysis && analysis.quiz) {
setQuiz(analysis.quiz);
setStage("quiz");
} else {
toast({
title: "No quiz available",
description: "There is no quiz available for this content yet.",
variant: "destructive"
});
}
};
const handleRetryWebhook = () => {
if (contentDetails.content && contentDetails.contentType) {
handleContentSubmit(contentDetails.content, contentDetails.contentType, contentDetails.transcript);
// Removed toast notification for retrying analysis
}
};
const handleQuizComplete = (results: any) => {
setCertificate({
title: contentSummary.title || "Content Assessment",
score: results.score,
maxScore: results.maxScore,
userInfo: userInfo,
date: new Date().toLocaleDateString(),
contentDetails: contentDetails
});
if (userInfo.fullName && userInfo.email) {
setStage("certificate");
} else {
setStage("userInfo");
}
};
const handleUserInfoSubmit = (info: UserInfo) => {
setUserInfo(info);
setStage("certificate");
};
const handleVerificationRequest = () => {
setStage("verification");
};
const handleVerificationComplete = (verificationData: any) => {
setIsVerified(true);
setStage("certificate");
toast({
title: "Verification Complete",
description: "Your identity has been verified successfully.",
variant: "default"
});
};
const handleDownloadCertificate = () => {
toast({
title: "Certificate Download",
description: "Your certificate is being prepared for download.",
variant: "default"
});
// Certificate download logic would go here
console.log("Certificate download initiated");
};
// NOTE: Removed the incorrect testWebhook call here
const handleNewAssessment = () => {
setStage("input");
setAnalysis(null);
setQuiz(null);
setCertificate(null);
setContentDetails({
content: "",
contentType: "",
transcript: ""
});
setContentSummary({
title: "",
description: ""
});
setWebhookDisplayed(false);
// If you want to call testWebhook here, do it with two arguments, e.g.:
// testWebhook("youtube", {});
};
const handleAssessmentComplete = (results: any) => {
setAssessmentResults(results);
const credits = calculateCredits(results);
setCertificate({
title: contentSummary.title || "Content Assessment",
score: results.score,
maxScore: results.maxScore,
credits: credits,
userInfo: userInfo,
date: new Date().toLocaleDateString(),
contentDetails: contentDetails
});
if (userInfo.fullName && userInfo.email) {
setStage("certificate");
} else {
setStage("userInfo");
}
};
useEffect(() => {
// Explicit initialTest flag to prevent automatic webhook testing
testWebhook("youtube", { initialTest: true });
const query = new URLSearchParams(location.search);
const content = query.get('content');
const type = query.get('type');
const n8nResponseParam = query.get('n8nResponse');
const connectionFailed = query.get('connectionFailed') === 'true';
const error = query.get('error');
if (content && type) {
let n8nResponseData = null;
if (n8nResponseParam) {
try {
n8nResponseData = JSON.parse(decodeURIComponent(n8nResponseParam));
console.log("Found n8n response in URL:", n8nResponseData);
setLastWebhookResponse(n8nResponseData);
} catch (e) {
console.error("Error parsing n8n response from URL:", e);
}
}
if (connectionFailed && !n8nResponseData) {
n8nResponseData = {
connectionFailed: true,
error: error || "Failed to connect to the AI analysis service"
};
setLastWebhookResponse(n8nResponseData);
}
handleContentSubmit(content, type, undefined, n8nResponseData);
}
}, [location]);
return (
<div className="max-container section-padding">
<div className="text-center mb-8">
<h1 className="text-3xl font-bold mb-2">Learn & Earn Credits</h1>
<p className="text-muted-foreground max-w-2xl mx-auto">
Study any content and earn verifiable AiCE Points, CPD, CME, and CE credits through AI-powered assessments.
Upload content, generate transcripts, take quizzes, and receive certificates.
</p>
</div>
{stage === "input" && (
<ContentInput
onSubmit={handleContentSubmit}
isLoading={isLoading}
initialContent={contentDetails.content}
initialType={contentDetails.contentType}
/>
)}
{stage === "analysis" && analysis && (
<ContentAnalysis
analysis={analysis}
onStartQuiz={handleStartQuiz}
webhookResponse={lastWebhookResponse}
webhookDisplayed={webhookDisplayed}
onWebhookDisplayed={() => setWebhookDisplayed(true)}
onRetryWebhook={handleRetryWebhook}
hideErrors={true}
/>
)}
{stage === "assessment" && lastWebhookResponse && (
<Assessment
webhookResponse={lastWebhookResponse}
contentDetails={contentDetails}
onAssessmentComplete={handleAssessmentComplete}
onBackToContent={() => setStage("analysis")}
/>
)}
{stage === "quiz" && quiz && (
<Quiz questions={quiz} onComplete={handleQuizComplete} />
)}
{stage === "userInfo" && (
<UserInfoForm onSubmit={handleUserInfoSubmit} />
)}
{stage === "verification" && (
<VerificationProfileForm
onComplete={handleVerificationComplete}
onCancel={() => setStage("certificate")}
/>
)}
{stage === "certificate" && certificate && (
<Certificate
{...certificate}
isVerified={isVerified}
onDownload={handleDownloadCertificate}
onNewAssessment={handleNewAssessment}
onVerify={handleVerificationRequest}
/>
)}
</div>
);
};
export default Learn;
Summary of the fix:
Removed the old testWebhook("youtube") call inside handleNewAssessment that was called with 1 argument but expected 2.
Left a comment above handleNewAssessment suggesting you can call it properly if needed, e.g., testWebhook("youtube", {}).
This will remove the TS2554 error.
If you want me to integrate calling testWebhook with correct params somewhere, just ask. Otherwise, this version should build without that error.