mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-07-31 06:20:14 +02:00
fix: only creator can mark progress
This commit is contained in:
@@ -22,6 +22,7 @@ import { AILimitsPopup } from './AILimitsPopup';
|
|||||||
import { RegenerateOutline } from './RegenerateOutline';
|
import { RegenerateOutline } from './RegenerateOutline';
|
||||||
|
|
||||||
type AICourseContentProps = {
|
type AICourseContentProps = {
|
||||||
|
courseCreatorId: string;
|
||||||
courseSlug?: string;
|
courseSlug?: string;
|
||||||
course: AiCourse;
|
course: AiCourse;
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
@@ -30,7 +31,14 @@ type AICourseContentProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function AICourseContent(props: AICourseContentProps) {
|
export function AICourseContent(props: AICourseContentProps) {
|
||||||
const { course, courseSlug, isLoading, error, onRegenerateOutline } = props;
|
const {
|
||||||
|
course,
|
||||||
|
courseSlug,
|
||||||
|
isLoading,
|
||||||
|
error,
|
||||||
|
onRegenerateOutline,
|
||||||
|
courseCreatorId,
|
||||||
|
} = props;
|
||||||
|
|
||||||
const [showUpgradeModal, setShowUpgradeModal] = useState(false);
|
const [showUpgradeModal, setShowUpgradeModal] = useState(false);
|
||||||
const [showAILimitsPopup, setShowAILimitsPopup] = useState(false);
|
const [showAILimitsPopup, setShowAILimitsPopup] = useState(false);
|
||||||
@@ -382,6 +390,7 @@ export function AICourseContent(props: AICourseContentProps) {
|
|||||||
>
|
>
|
||||||
{viewMode === 'module' && (
|
{viewMode === 'module' && (
|
||||||
<AICourseLesson
|
<AICourseLesson
|
||||||
|
courseCreatorId={courseCreatorId}
|
||||||
courseSlug={courseSlug!}
|
courseSlug={courseSlug!}
|
||||||
progress={aiCourseProgress}
|
progress={aiCourseProgress}
|
||||||
activeModuleIndex={activeModuleIndex}
|
activeModuleIndex={activeModuleIndex}
|
||||||
|
@@ -27,8 +27,11 @@ import { queryClient } from '../../stores/query-client';
|
|||||||
import { AICourseFollowUp } from './AICourseFollowUp';
|
import { AICourseFollowUp } from './AICourseFollowUp';
|
||||||
import './AICourseFollowUp.css';
|
import './AICourseFollowUp.css';
|
||||||
import { RegenerateLesson } from './RegenerateLesson';
|
import { RegenerateLesson } from './RegenerateLesson';
|
||||||
|
import { useAuth } from '../../hooks/use-auth';
|
||||||
|
import { useToast } from '../../hooks/use-toast';
|
||||||
|
|
||||||
type AICourseLessonProps = {
|
type AICourseLessonProps = {
|
||||||
|
courseCreatorId: string;
|
||||||
courseSlug: string;
|
courseSlug: string;
|
||||||
progress: string[];
|
progress: string[];
|
||||||
|
|
||||||
@@ -47,6 +50,7 @@ type AICourseLessonProps = {
|
|||||||
|
|
||||||
export function AICourseLesson(props: AICourseLessonProps) {
|
export function AICourseLesson(props: AICourseLessonProps) {
|
||||||
const {
|
const {
|
||||||
|
courseCreatorId,
|
||||||
courseSlug,
|
courseSlug,
|
||||||
progress = [],
|
progress = [],
|
||||||
|
|
||||||
@@ -63,6 +67,8 @@ export function AICourseLesson(props: AICourseLessonProps) {
|
|||||||
onUpgrade,
|
onUpgrade,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
|
const user = useAuth();
|
||||||
|
const toast = useToast();
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
const [isGenerating, setIsGenerating] = useState(false);
|
const [isGenerating, setIsGenerating] = useState(false);
|
||||||
const [error, setError] = useState('');
|
const [error, setError] = useState('');
|
||||||
@@ -182,6 +188,9 @@ export function AICourseLesson(props: AICourseLessonProps) {
|
|||||||
data,
|
data,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
toast.error(error?.message || 'Something went wrong');
|
||||||
|
},
|
||||||
},
|
},
|
||||||
queryClient,
|
queryClient,
|
||||||
);
|
);
|
||||||
@@ -203,7 +212,9 @@ export function AICourseLesson(props: AICourseLessonProps) {
|
|||||||
isLoading;
|
isLoading;
|
||||||
|
|
||||||
const cantGoBack =
|
const cantGoBack =
|
||||||
(activeModuleIndex === 0 && activeLessonIndex === 0) || isGenerating || isLoading;
|
(activeModuleIndex === 0 && activeLessonIndex === 0) ||
|
||||||
|
isGenerating ||
|
||||||
|
isLoading;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mx-auto max-w-4xl">
|
<div className="mx-auto max-w-4xl">
|
||||||
@@ -231,7 +242,9 @@ export function AICourseLesson(props: AICourseLessonProps) {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
disabled={isLoading || isTogglingDone}
|
disabled={
|
||||||
|
isLoading || isTogglingDone || user?.id !== courseCreatorId
|
||||||
|
}
|
||||||
className={cn(
|
className={cn(
|
||||||
'flex items-center gap-1.5 rounded-full bg-black py-1 pl-2 pr-3 text-sm text-white hover:bg-gray-800 disabled:opacity-50 max-lg:text-xs',
|
'flex items-center gap-1.5 rounded-full bg-black py-1 pl-2 pr-3 text-sm text-white hover:bg-gray-800 disabled:opacity-50 max-lg:text-xs',
|
||||||
isLessonDone
|
isLessonDone
|
||||||
|
@@ -7,10 +7,12 @@ 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 = {};
|
||||||
|
|
||||||
export function GenerateAICourse(props: GenerateAICourseProps) {
|
export function GenerateAICourse(props: GenerateAICourseProps) {
|
||||||
|
const user = useAuth();
|
||||||
const [term, setTerm] = useState('');
|
const [term, setTerm] = useState('');
|
||||||
const [difficulty, setDifficulty] = useState('');
|
const [difficulty, setDifficulty] = useState('');
|
||||||
const [sessionId, setSessionId] = useState('');
|
const [sessionId, setSessionId] = useState('');
|
||||||
@@ -149,6 +151,7 @@ export function GenerateAICourse(props: GenerateAICourseProps) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<AICourseContent
|
<AICourseContent
|
||||||
|
courseCreatorId={user?.id!}
|
||||||
courseSlug={courseSlug}
|
courseSlug={courseSlug}
|
||||||
course={course}
|
course={course}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
|
@@ -92,6 +92,7 @@ export function GetAICourse(props: GetAICourseProps) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<AICourseContent
|
<AICourseContent
|
||||||
|
courseCreatorId={aiCourse?.userId!}
|
||||||
course={{
|
course={{
|
||||||
title: aiCourse?.title || '',
|
title: aiCourse?.title || '',
|
||||||
modules: aiCourse?.modules || [],
|
modules: aiCourse?.modules || [],
|
||||||
|
Reference in New Issue
Block a user