1
0
mirror of https://github.com/kamranahmedse/developer-roadmap.git synced 2025-04-16 13:25:05 +02:00

fix: only creator can mark progress

This commit is contained in:
Arik Chakma 2025-03-18 21:52:36 +06:00
parent 6449c24398
commit dee4bec9c6
4 changed files with 29 additions and 3 deletions

View File

@ -22,6 +22,7 @@ import { AILimitsPopup } from './AILimitsPopup';
import { RegenerateOutline } from './RegenerateOutline';
type AICourseContentProps = {
courseCreatorId: string;
courseSlug?: string;
course: AiCourse;
isLoading: boolean;
@ -30,7 +31,14 @@ type 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 [showAILimitsPopup, setShowAILimitsPopup] = useState(false);
@ -382,6 +390,7 @@ export function AICourseContent(props: AICourseContentProps) {
>
{viewMode === 'module' && (
<AICourseLesson
courseCreatorId={courseCreatorId}
courseSlug={courseSlug!}
progress={aiCourseProgress}
activeModuleIndex={activeModuleIndex}

View File

@ -27,8 +27,11 @@ import { queryClient } from '../../stores/query-client';
import { AICourseFollowUp } from './AICourseFollowUp';
import './AICourseFollowUp.css';
import { RegenerateLesson } from './RegenerateLesson';
import { useAuth } from '../../hooks/use-auth';
import { useToast } from '../../hooks/use-toast';
type AICourseLessonProps = {
courseCreatorId: string;
courseSlug: string;
progress: string[];
@ -47,6 +50,7 @@ type AICourseLessonProps = {
export function AICourseLesson(props: AICourseLessonProps) {
const {
courseCreatorId,
courseSlug,
progress = [],
@ -63,6 +67,8 @@ export function AICourseLesson(props: AICourseLessonProps) {
onUpgrade,
} = props;
const user = useAuth();
const toast = useToast();
const [isLoading, setIsLoading] = useState(true);
const [isGenerating, setIsGenerating] = useState(false);
const [error, setError] = useState('');
@ -182,6 +188,9 @@ export function AICourseLesson(props: AICourseLessonProps) {
data,
);
},
onError: (error) => {
toast.error(error?.message || 'Something went wrong');
},
},
queryClient,
);
@ -203,7 +212,9 @@ export function AICourseLesson(props: AICourseLessonProps) {
isLoading;
const cantGoBack =
(activeModuleIndex === 0 && activeLessonIndex === 0) || isGenerating || isLoading;
(activeModuleIndex === 0 && activeLessonIndex === 0) ||
isGenerating ||
isLoading;
return (
<div className="mx-auto max-w-4xl">
@ -231,7 +242,9 @@ export function AICourseLesson(props: AICourseLessonProps) {
}}
/>
<button
disabled={isLoading || isTogglingDone}
disabled={
isLoading || isTogglingDone || user?.id !== courseCreatorId
}
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',
isLessonDone

View File

@ -7,10 +7,12 @@ 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 = {};
export function GenerateAICourse(props: GenerateAICourseProps) {
const user = useAuth();
const [term, setTerm] = useState('');
const [difficulty, setDifficulty] = useState('');
const [sessionId, setSessionId] = useState('');
@ -149,6 +151,7 @@ export function GenerateAICourse(props: GenerateAICourseProps) {
return (
<AICourseContent
courseCreatorId={user?.id!}
courseSlug={courseSlug}
course={course}
isLoading={isLoading}

View File

@ -92,6 +92,7 @@ export function GetAICourse(props: GetAICourseProps) {
return (
<AICourseContent
courseCreatorId={aiCourse?.userId!}
course={{
title: aiCourse?.title || '',
modules: aiCourse?.modules || [],