mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-08-30 20:49:49 +02:00
feat: add ai course creator id (#8592)
This commit is contained in:
@@ -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<AiCourse>({
|
||||
@@ -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 (
|
||||
<AICourseContent
|
||||
courseSlug={courseSlug}
|
||||
creatorId={currentUser?.id}
|
||||
creatorId={creatorId}
|
||||
course={course}
|
||||
isLoading={isLoading}
|
||||
error={error}
|
||||
|
@@ -19,6 +19,7 @@ type GenerateCourseOptions = {
|
||||
onCourseSlugChange?: (courseSlug: string) => 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());
|
||||
},
|
||||
|
Reference in New Issue
Block a user