mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-09-01 05:21:43 +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 { useQuery } from '@tanstack/react-query';
|
||||||
import { getAiCourseOptions } from '../../queries/ai-course';
|
import { getAiCourseOptions } from '../../queries/ai-course';
|
||||||
import { queryClient } from '../../stores/query-client';
|
import { queryClient } from '../../stores/query-client';
|
||||||
import { useAuth } from '../../hooks/use-auth';
|
|
||||||
|
|
||||||
type GenerateAICourseProps = {};
|
type GenerateAICourseProps = {};
|
||||||
|
|
||||||
@@ -21,8 +20,8 @@ export function GenerateAICourse(props: GenerateAICourseProps) {
|
|||||||
|
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
const [error, setError] = useState('');
|
const [error, setError] = useState('');
|
||||||
const currentUser = useAuth();
|
|
||||||
|
|
||||||
|
const [creatorId, setCreatorId] = useState('');
|
||||||
const [courseId, setCourseId] = useState('');
|
const [courseId, setCourseId] = useState('');
|
||||||
const [courseSlug, setCourseSlug] = useState('');
|
const [courseSlug, setCourseSlug] = useState('');
|
||||||
const [course, setCourse] = useState<AiCourse>({
|
const [course, setCourse] = useState<AiCourse>({
|
||||||
@@ -124,6 +123,7 @@ export function GenerateAICourse(props: GenerateAICourseProps) {
|
|||||||
slug: courseSlug,
|
slug: courseSlug,
|
||||||
onCourseIdChange: setCourseId,
|
onCourseIdChange: setCourseId,
|
||||||
onCourseSlugChange: setCourseSlug,
|
onCourseSlugChange: setCourseSlug,
|
||||||
|
onCreatorIdChange: setCreatorId,
|
||||||
onCourseChange: setCourse,
|
onCourseChange: setCourse,
|
||||||
onLoadingChange: setIsLoading,
|
onLoadingChange: setIsLoading,
|
||||||
onError: setError,
|
onError: setError,
|
||||||
@@ -164,7 +164,7 @@ export function GenerateAICourse(props: GenerateAICourseProps) {
|
|||||||
return (
|
return (
|
||||||
<AICourseContent
|
<AICourseContent
|
||||||
courseSlug={courseSlug}
|
courseSlug={courseSlug}
|
||||||
creatorId={currentUser?.id}
|
creatorId={creatorId}
|
||||||
course={course}
|
course={course}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
error={error}
|
error={error}
|
||||||
|
@@ -19,6 +19,7 @@ type GenerateCourseOptions = {
|
|||||||
onCourseSlugChange?: (courseSlug: string) => void;
|
onCourseSlugChange?: (courseSlug: string) => void;
|
||||||
onCourseChange?: (course: AiCourse, rawData: string) => void;
|
onCourseChange?: (course: AiCourse, rawData: string) => void;
|
||||||
onLoadingChange?: (isLoading: boolean) => void;
|
onLoadingChange?: (isLoading: boolean) => void;
|
||||||
|
onCreatorIdChange?: (creatorId: string) => void;
|
||||||
onError?: (error: string) => void;
|
onError?: (error: string) => void;
|
||||||
src?: string;
|
src?: string;
|
||||||
};
|
};
|
||||||
@@ -33,6 +34,7 @@ export async function generateCourse(options: GenerateCourseOptions) {
|
|||||||
onCourseChange,
|
onCourseChange,
|
||||||
onLoadingChange,
|
onLoadingChange,
|
||||||
onError,
|
onError,
|
||||||
|
onCreatorIdChange,
|
||||||
isForce = false,
|
isForce = false,
|
||||||
prompt,
|
prompt,
|
||||||
instructions,
|
instructions,
|
||||||
@@ -116,14 +118,17 @@ export async function generateCourse(options: GenerateCourseOptions) {
|
|||||||
|
|
||||||
const COURSE_ID_REGEX = new RegExp('@COURSEID:(\\w+)@');
|
const COURSE_ID_REGEX = new RegExp('@COURSEID:(\\w+)@');
|
||||||
const COURSE_SLUG_REGEX = new RegExp(/@COURSESLUG:([\w-]+)@/);
|
const COURSE_SLUG_REGEX = new RegExp(/@COURSESLUG:([\w-]+)@/);
|
||||||
|
const CREATOR_ID_REGEX = new RegExp('@CREATORID:(\\w+)@');
|
||||||
|
|
||||||
await readStream(reader, {
|
await readStream(reader, {
|
||||||
onStream: (result) => {
|
onStream: (result) => {
|
||||||
if (result.includes('@COURSEID') || result.includes('@COURSESLUG')) {
|
if (result.includes('@COURSEID') || result.includes('@COURSESLUG')) {
|
||||||
const courseIdMatch = result.match(COURSE_ID_REGEX);
|
const courseIdMatch = result.match(COURSE_ID_REGEX);
|
||||||
const courseSlugMatch = result.match(COURSE_SLUG_REGEX);
|
const courseSlugMatch = result.match(COURSE_SLUG_REGEX);
|
||||||
|
const creatorIdMatch = result.match(CREATOR_ID_REGEX);
|
||||||
const extractedCourseId = courseIdMatch?.[1] || '';
|
const extractedCourseId = courseIdMatch?.[1] || '';
|
||||||
const extractedCourseSlug = courseSlugMatch?.[1] || '';
|
const extractedCourseSlug = courseSlugMatch?.[1] || '';
|
||||||
|
const extractedCreatorId = creatorIdMatch?.[1] || '';
|
||||||
|
|
||||||
if (extractedCourseSlug) {
|
if (extractedCourseSlug) {
|
||||||
window.history.replaceState(
|
window.history.replaceState(
|
||||||
@@ -140,10 +145,12 @@ export async function generateCourse(options: GenerateCourseOptions) {
|
|||||||
|
|
||||||
result = result
|
result = result
|
||||||
.replace(COURSE_ID_REGEX, '')
|
.replace(COURSE_ID_REGEX, '')
|
||||||
.replace(COURSE_SLUG_REGEX, '');
|
.replace(COURSE_SLUG_REGEX, '')
|
||||||
|
.replace(CREATOR_ID_REGEX, '');
|
||||||
|
|
||||||
onCourseIdChange?.(extractedCourseId);
|
onCourseIdChange?.(extractedCourseId);
|
||||||
onCourseSlugChange?.(extractedCourseSlug);
|
onCourseSlugChange?.(extractedCourseSlug);
|
||||||
|
onCreatorIdChange?.(extractedCreatorId);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -162,7 +169,9 @@ export async function generateCourse(options: GenerateCourseOptions) {
|
|||||||
onStreamEnd: (result) => {
|
onStreamEnd: (result) => {
|
||||||
result = result
|
result = result
|
||||||
.replace(COURSE_ID_REGEX, '')
|
.replace(COURSE_ID_REGEX, '')
|
||||||
.replace(COURSE_SLUG_REGEX, '');
|
.replace(COURSE_SLUG_REGEX, '')
|
||||||
|
.replace(CREATOR_ID_REGEX, '');
|
||||||
|
|
||||||
onLoadingChange?.(false);
|
onLoadingChange?.(false);
|
||||||
queryClient.invalidateQueries(getAiCourseLimitOptions());
|
queryClient.invalidateQueries(getAiCourseLimitOptions());
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user