1
0
mirror of https://github.com/kamranahmedse/developer-roadmap.git synced 2025-09-03 14:22:41 +02:00

fix: roadmap regenerate

This commit is contained in:
Arik Chakma
2025-06-25 21:41:38 +06:00
parent 7329936822
commit 0f8f6eea57
3 changed files with 70 additions and 52 deletions

View File

@@ -136,10 +136,11 @@ export function AIRoadmapRegenerate(props: AIRoadmapRegenerateProps) {
queryClient, queryClient,
); );
const isCurrentUserCreator = currentUser?.id === aiRoadmap?.userId;
const showUpdatePreferences = const showUpdatePreferences =
aiRoadmap?.questionAndAnswers && aiRoadmap?.questionAndAnswers &&
aiRoadmap.questionAndAnswers.length > 0 && aiRoadmap.questionAndAnswers.length > 0 &&
currentUser?.id === aiRoadmap.userId; isCurrentUserCreator;
return ( return (
<> <>
@@ -186,6 +187,8 @@ export function AIRoadmapRegenerate(props: AIRoadmapRegenerateProps) {
</button> </button>
{isDropdownVisible && ( {isDropdownVisible && (
<div className="absolute top-full right-0 min-w-[190px] translate-y-1 overflow-hidden rounded-md border border-gray-200 bg-white shadow-md"> <div className="absolute top-full right-0 min-w-[190px] translate-y-1 overflow-hidden rounded-md border border-gray-200 bg-white shadow-md">
{isCurrentUserCreator && (
<>
{showUpdatePreferences && ( {showUpdatePreferences && (
<ActionButton <ActionButton
onClick={() => { onClick={() => {
@@ -230,6 +233,8 @@ export function AIRoadmapRegenerate(props: AIRoadmapRegenerateProps) {
/> />
<hr className="my-1 border-gray-200" /> <hr className="my-1 border-gray-200" />
</>
)}
<ActionButton <ActionButton
onClick={() => { onClick={() => {

View File

@@ -1,5 +1,5 @@
import { useQuery } from '@tanstack/react-query'; import { useQuery } from '@tanstack/react-query';
import { ExternalLink } from 'lucide-react'; import { AlertCircleIcon, ExternalLink } from 'lucide-react';
import { useMemo, useState } from 'react'; import { useMemo, useState } from 'react';
import { flushSync } from 'react-dom'; import { flushSync } from 'react-dom';
import { generateGuide } from '../../helper/generate-ai-guide'; import { generateGuide } from '../../helper/generate-ai-guide';
@@ -35,10 +35,11 @@ export function AIGuide(props: AIGuideProps) {
// only fetch the guide if the guideSlug is provided // only fetch the guide if the guideSlug is provided
// otherwise we are still generating the guide // otherwise we are still generating the guide
const { data: aiGuide, isLoading: isLoadingBySlug } = useQuery( const {
getAiGuideOptions(guideSlug), data: aiGuide,
queryClient, isLoading: isLoadingBySlug,
); error: aiGuideError,
} = useQuery(getAiGuideOptions(guideSlug), queryClient);
const { const {
data: tokenUsage, data: tokenUsage,
@@ -125,15 +126,26 @@ export function AIGuide(props: AIGuideProps) {
return ( return (
<AITutorLayout <AITutorLayout
wrapperClassName="flex-row p-0 lg:p-0 overflow-hidden bg-white" wrapperClassName="flex-row p-0 lg:p-0 relative overflow-hidden bg-white"
containerClassName="h-[calc(100vh-49px)] overflow-hidden relative" containerClassName="h-[calc(100vh-49px)] overflow-hidden relative"
> >
{showUpgradeModal && ( {showUpgradeModal && (
<UpgradeAccountModal onClose={() => setShowUpgradeModal(false)} /> <UpgradeAccountModal onClose={() => setShowUpgradeModal(false)} />
)} )}
{!isLoading && aiGuideError && (
<div className="absolute inset-0 z-10 flex h-full flex-col items-center justify-center bg-white">
<div className="flex flex-col items-center justify-center gap-2">
<AlertCircleIcon className="size-10 text-gray-500" />
<p className="text-center">
{aiGuideError?.message || 'Something went wrong'}
</p>
</div>
</div>
)}
<div className="grow overflow-y-auto p-4 pt-0"> <div className="grow overflow-y-auto p-4 pt-0">
{guideSlug && ( {guideSlug && !aiGuideError && (
<AIGuideContent <AIGuideContent
html={regeneratedHtml || aiGuide?.html || ''} html={regeneratedHtml || aiGuide?.html || ''}
onRegenerate={handleRegenerate} onRegenerate={handleRegenerate}
@@ -141,7 +153,9 @@ export function AIGuide(props: AIGuideProps) {
guideSlug={guideSlug} guideSlug={guideSlug}
/> />
)} )}
{!guideSlug && <GenerateAIGuide onGuideSlugChange={setGuideSlug} />} {!guideSlug && !aiGuideError && (
<GenerateAIGuide onGuideSlugChange={setGuideSlug} />
)}
{aiGuide && !isRegenerating && ( {aiGuide && !isRegenerating && (
<div className="mx-auto mt-12 mb-12 max-w-4xl"> <div className="mx-auto mt-12 mb-12 max-w-4xl">

View File

@@ -48,7 +48,6 @@ export function getAiGuideOptions(guideSlug?: string) {
}; };
}, },
enabled: !!guideSlug, enabled: !!guideSlug,
refetchOnMount: false,
}); });
} }