From 359cc332ece713a732ce9f954e2fcc5d27dccdcd Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Mon, 4 Mar 2024 16:01:31 +0000 Subject: [PATCH] Update UI for roadmap search --- .../GenerateRoadmap/GenerateRoadmap.tsx | 53 +++++++++++++++---- .../GenerateRoadmap/RoadmapSearch.tsx | 33 ++++++++++-- 2 files changed, 71 insertions(+), 15 deletions(-) diff --git a/src/components/GenerateRoadmap/GenerateRoadmap.tsx b/src/components/GenerateRoadmap/GenerateRoadmap.tsx index e74580118..1b16d960f 100644 --- a/src/components/GenerateRoadmap/GenerateRoadmap.tsx +++ b/src/components/GenerateRoadmap/GenerateRoadmap.tsx @@ -8,7 +8,7 @@ import { readAIRoadmapStream } from '../../helper/read-stream'; import { isLoggedIn, removeAuthToken } from '../../lib/jwt'; import { RoadmapSearch } from './RoadmapSearch.tsx'; import { Spinner } from '../ReactIcons/Spinner.tsx'; -import { Download, PenSquare, Wand } from 'lucide-react'; +import { Ban, Download, PenSquare, StopCircleIcon, Wand } from 'lucide-react'; import { ShareRoadmapButton } from '../ShareRoadmapButton.tsx'; import { httpGet, httpPost } from '../../lib/http.ts'; import { pageProgressMessage } from '../../stores/page.ts'; @@ -19,6 +19,8 @@ import { } from '../../lib/browser.ts'; import { downloadGeneratedRoadmapImage } from '../../helper/download-image.ts'; import { showLoginPopup } from '../../lib/popup.ts'; +import { cn } from '../../lib/classname.ts'; +import { StopIcon } from '../ReactIcons/StopIcon.tsx'; const ROADMAP_ID_REGEX = new RegExp('@ROADMAPID:(\\w+)@'); @@ -46,15 +48,13 @@ export function GenerateRoadmap() { const handleSubmit = async (e: FormEvent) => { e.preventDefault(); - setIsLoading(true); - setHasSubmitted(true); - if (!roadmapTopic) { - toast.error('Please enter a topic'); - setIsLoading(false); return; } + setIsLoading(true); + setHasSubmitted(true); + if (roadmapLimitUsed >= roadmapLimit) { toast.error('You have reached your limit of generating roadmaps'); setIsLoading(false); @@ -241,6 +241,7 @@ export function GenerateRoadmap() { } const pageUrl = `https://roadmap.sh/ai?id=${roadmapId}`; + const canGenerateMore = roadmapLimitUsed < roadmapLimit; return (
@@ -255,7 +256,18 @@ export function GenerateRoadmap() {
- {roadmapLimitUsed} of {roadmapLimit} roadmaps generated + + {roadmapLimitUsed} of {roadmapLimit} + {' '} + roadmaps generated {!isLoggedIn() && ( <> {' '} @@ -285,10 +297,31 @@ export function GenerateRoadmap() { />
diff --git a/src/components/GenerateRoadmap/RoadmapSearch.tsx b/src/components/GenerateRoadmap/RoadmapSearch.tsx index 1ae3d92a3..5db9a124e 100644 --- a/src/components/GenerateRoadmap/RoadmapSearch.tsx +++ b/src/components/GenerateRoadmap/RoadmapSearch.tsx @@ -21,6 +21,8 @@ export function RoadmapSearch(props: RoadmapSearchProps) { limitUsed = 0, } = props; + const canGenerateMore = limitUsed < limit; + return (
@@ -43,9 +45,29 @@ export function RoadmapSearch(props: RoadmapSearchProps) { value={roadmapTopic} onInput={(e) => setRoadmapTopic((e.target as HTMLInputElement).value)} /> -
@@ -53,9 +75,10 @@ export function RoadmapSearch(props: RoadmapSearchProps) { You have generated{' '}