From b1e9198805c9da0b538a70eadaa487e34a01419e Mon Sep 17 00:00:00 2001 From: Arik Chakma Date: Sun, 4 May 2025 02:44:17 +0600 Subject: [PATCH] feat: add ai course creator id --- src/components/GenerateCourse/GenerateAICourse.tsx | 6 +++--- src/helper/generate-ai-course.ts | 13 +++++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/components/GenerateCourse/GenerateAICourse.tsx b/src/components/GenerateCourse/GenerateAICourse.tsx index f7e57f8b2..389291df6 100644 --- a/src/components/GenerateCourse/GenerateAICourse.tsx +++ b/src/components/GenerateCourse/GenerateAICourse.tsx @@ -7,7 +7,6 @@ import { generateCourse } from '../../helper/generate-ai-course'; import { useQuery } from '@tanstack/react-query'; import { getAiCourseOptions } from '../../queries/ai-course'; import { queryClient } from '../../stores/query-client'; -import { useAuth } from '../../hooks/use-auth'; type GenerateAICourseProps = {}; @@ -21,8 +20,8 @@ export function GenerateAICourse(props: GenerateAICourseProps) { const [isLoading, setIsLoading] = useState(true); const [error, setError] = useState(''); - const currentUser = useAuth(); + const [creatorId, setCreatorId] = useState(''); const [courseId, setCourseId] = useState(''); const [courseSlug, setCourseSlug] = useState(''); const [course, setCourse] = useState({ @@ -124,6 +123,7 @@ export function GenerateAICourse(props: GenerateAICourseProps) { slug: courseSlug, onCourseIdChange: setCourseId, onCourseSlugChange: setCourseSlug, + onCreatorIdChange: setCreatorId, onCourseChange: setCourse, onLoadingChange: setIsLoading, onError: setError, @@ -164,7 +164,7 @@ export function GenerateAICourse(props: GenerateAICourseProps) { return ( void; onCourseChange?: (course: AiCourse, rawData: string) => void; onLoadingChange?: (isLoading: boolean) => void; + onCreatorIdChange?: (creatorId: string) => void; onError?: (error: string) => void; src?: string; }; @@ -33,6 +34,7 @@ export async function generateCourse(options: GenerateCourseOptions) { onCourseChange, onLoadingChange, onError, + onCreatorIdChange, isForce = false, prompt, instructions, @@ -116,14 +118,17 @@ export async function generateCourse(options: GenerateCourseOptions) { const COURSE_ID_REGEX = new RegExp('@COURSEID:(\\w+)@'); const COURSE_SLUG_REGEX = new RegExp(/@COURSESLUG:([\w-]+)@/); + const CREATOR_ID_REGEX = new RegExp('@CREATORID:(\\w+)@'); await readStream(reader, { onStream: (result) => { if (result.includes('@COURSEID') || result.includes('@COURSESLUG')) { const courseIdMatch = result.match(COURSE_ID_REGEX); const courseSlugMatch = result.match(COURSE_SLUG_REGEX); + const creatorIdMatch = result.match(CREATOR_ID_REGEX); const extractedCourseId = courseIdMatch?.[1] || ''; const extractedCourseSlug = courseSlugMatch?.[1] || ''; + const extractedCreatorId = creatorIdMatch?.[1] || ''; if (extractedCourseSlug) { window.history.replaceState( @@ -140,10 +145,12 @@ export async function generateCourse(options: GenerateCourseOptions) { result = result .replace(COURSE_ID_REGEX, '') - .replace(COURSE_SLUG_REGEX, ''); + .replace(COURSE_SLUG_REGEX, '') + .replace(CREATOR_ID_REGEX, ''); onCourseIdChange?.(extractedCourseId); onCourseSlugChange?.(extractedCourseSlug); + onCreatorIdChange?.(extractedCreatorId); } try { @@ -162,7 +169,9 @@ export async function generateCourse(options: GenerateCourseOptions) { onStreamEnd: (result) => { result = result .replace(COURSE_ID_REGEX, '') - .replace(COURSE_SLUG_REGEX, ''); + .replace(COURSE_SLUG_REGEX, '') + .replace(CREATOR_ID_REGEX, ''); + onLoadingChange?.(false); queryClient.invalidateQueries(getAiCourseLimitOptions()); },