feat/ai-courses
Arik Chakma 2 months ago
parent f7558fadc4
commit 587dd66739
  1. 12
      src/components/GenerateCourse/AICourse.tsx
  2. 5
      src/components/GenerateCourse/AICourseContent.tsx

@ -1,6 +1,8 @@
import { Loader2Icon, SearchIcon, WandIcon } from 'lucide-react';
import { useState } from 'react';
import { cn } from '../../lib/classname';
import { isLoggedIn } from '../../lib/jwt';
import { showLoginPopup } from '../../lib/popup';
export const difficultyLevels = [
'beginner',
@ -14,18 +16,20 @@ type AICourseProps = {};
export function AICourse(props: AICourseProps) {
const [keyword, setKeyword] = useState('');
const [difficulty, setDifficulty] = useState<DifficultyLevel>('intermediate');
const [isLoading, setIsLoading] = useState(false);
const handleKeyDown = (e: React.KeyboardEvent) => {
if (e.key === 'Enter' && keyword.trim() && !isLoading) {
if (e.key === 'Enter' && keyword.trim()) {
onSubmit();
}
};
function onSubmit() {
if (typeof window !== 'undefined') {
window.location.href = `/ai-tutor/search?term=${encodeURIComponent(keyword)}&difficulty=${difficulty}`;
if (!isLoggedIn()) {
showLoginPopup();
return;
}
window.location.href = `/ai-tutor/search?term=${encodeURIComponent(keyword)}&difficulty=${difficulty}`;
}
return (

@ -12,6 +12,7 @@ import { readAICourseStream } from '../../helper/read-stream';
import { cn } from '../../lib/classname';
import { getUrlParams } from '../../lib/browser';
import { AICourseModuleView } from './AICourseModuleView';
import { isLoggedIn } from '../../lib/jwt';
type Lesson = string;
@ -125,6 +126,10 @@ export function AICourseContent(props: AICourseContentProps) {
difficulty?: string;
slug?: string;
}) => {
if (!isLoggedIn()) {
return;
}
setIsLoading(true);
setStreamedCourse({ title: '', modules: [] });
setExpandedModules({});

Loading…
Cancel
Save