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

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

Loading…
Cancel
Save