From 7b9e6ed079eee7fbf1446269cd7dcff178a368c5 Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Thu, 1 May 2025 23:18:08 +0100 Subject: [PATCH] Refactor topic popup --- src/components/TopicDetail/TopicDetail.tsx | 44 ++++++----------- .../TopicDetail/TopicDetailLink.tsx | 48 +++++++++++++++---- .../TopicDetail/TopicDetailsTabs.tsx | 23 +++++---- .../TopicDetail/TopicProgressButton.tsx | 13 ++--- ...the-internet-work@yCnn-NfSxIybUQ2iTuUGq.md | 2 +- .../content/internet@VlNNwIEDWqQXtqkHWJYzC.md | 2 +- 6 files changed, 77 insertions(+), 55 deletions(-) diff --git a/src/components/TopicDetail/TopicDetail.tsx b/src/components/TopicDetail/TopicDetail.tsx index c524e6f1a..0fef684fa 100644 --- a/src/components/TopicDetail/TopicDetail.tsx +++ b/src/components/TopicDetail/TopicDetail.tsx @@ -21,7 +21,7 @@ import type { RoadmapContentDocument, } from '../CustomRoadmap/CustomRoadmap'; import { markdownToHtml, sanitizeMarkdown } from '../../lib/markdown'; -import { Ban, Coins, FileText, HeartHandshake, Star, X } from 'lucide-react'; +import { Ban, FileText, HeartHandshake, Star, X } from 'lucide-react'; import { getUrlParams, parseUrl } from '../../lib/browser'; import { Spinner } from '../ReactIcons/Spinner'; import { GitHubIcon } from '../ReactIcons/GitHubIcon.tsx'; @@ -396,29 +396,28 @@ export function TopicDetail(props: TopicDetailProps) { 'flex flex-col': activeTab === 'ai', })} > -
+
- {!isEmbed && ( - - )} + + + Edit this content +
@@ -560,19 +559,6 @@ export function TopicDetail(props: TopicDetailProps) { })} - {hasPaidScrimbaLinks && ( -
-
- - - Scrimba is offering{' '} - 20% off{' '} - on all courses for roadmap.sh users. - -
-
- )} - {showPaidResourceDisclaimer && ( { diff --git a/src/components/TopicDetail/TopicDetailLink.tsx b/src/components/TopicDetail/TopicDetailLink.tsx index d5b05c95e..60f3ea5e7 100644 --- a/src/components/TopicDetail/TopicDetailLink.tsx +++ b/src/components/TopicDetail/TopicDetailLink.tsx @@ -1,7 +1,7 @@ import { cn } from '../../lib/classname.ts'; import type { AllowedLinkTypes } from '../CustomRoadmap/CustomRoadmap.tsx'; -const linkTypes: Record = { +const linkTypes: Record = { article: 'bg-yellow-300', course: 'bg-green-400', opensource: 'bg-black text-white', @@ -18,6 +18,34 @@ const paidLinkTypes: Record = { course: 'bg-yellow-300', }; +type TopicLinkBadgeProps = { + isPaid: boolean; + discountText?: string; + type: AllowedLinkTypes | string; + className?: string; +}; + +function TopicLinkBadge(props: TopicLinkBadgeProps) { + const { isPaid, type, className } = props; + + const linkType = type === 'opensource' ? 'OpenSource' : type; + const isDiscount = type.includes('% off'); + + return ( + + + {linkType} + + + ); +} + type TopicDetailLinkProps = { url: string; onClick?: () => void; @@ -29,7 +57,7 @@ type TopicDetailLinkProps = { export function TopicDetailLink(props: TopicDetailLinkProps) { const { url, onClick, type, title, isPaid = false } = props; - const linkType = type === 'opensource' ? 'OpenSource' : type; + const isScrimbaLink = url.toLowerCase().includes('scrimba.com'); return ( - - {linkType} - + + {isScrimbaLink && } + {title} ); diff --git a/src/components/TopicDetail/TopicDetailsTabs.tsx b/src/components/TopicDetail/TopicDetailsTabs.tsx index 855bfe185..d82958056 100644 --- a/src/components/TopicDetail/TopicDetailsTabs.tsx +++ b/src/components/TopicDetail/TopicDetailsTabs.tsx @@ -1,4 +1,4 @@ -import { BookIcon, SparklesIcon, type LucideIcon } from 'lucide-react'; +import { Earth, WandSparkles, type LucideIcon } from 'lucide-react'; export type AllowedTopicDetailsTabs = 'content' | 'ai'; @@ -11,17 +11,18 @@ export function TopicDetailsTabs(props: TopicDetailsTabsProps) { const { activeTab, setActiveTab } = props; return ( -
+
setActiveTab('content')} /> setActiveTab('ai')} />
@@ -32,15 +33,16 @@ type TopicDetailsTabProps = { isActive: boolean; icon: LucideIcon; label: string; + isNew?: boolean; onClick: () => void; }; function TopicDetailsTab(props: TopicDetailsTabProps) { - const { isActive, icon: Icon, label, onClick } = props; + const { isActive, icon: Icon, label, isNew, onClick } = props; return ( ); } diff --git a/src/components/TopicDetail/TopicProgressButton.tsx b/src/components/TopicDetail/TopicProgressButton.tsx index d3de18842..ecbf6a5a3 100644 --- a/src/components/TopicDetail/TopicProgressButton.tsx +++ b/src/components/TopicDetail/TopicProgressButton.tsx @@ -204,6 +204,7 @@ export function TopicProgressButton(props: TopicProgressButtonProps) { console.error(err); }) .finally(() => { + setShowChangeStatus(false); setIsUpdatingProgress(false); }); }; @@ -223,9 +224,9 @@ export function TopicProgressButton(props: TopicProgressButtonProps) { if (isUpdatingProgress) { return ( - ); } @@ -233,23 +234,23 @@ export function TopicProgressButton(props: TopicProgressButtonProps) { return (
{showChangeStatus && (
{allowMarkingDone && ( diff --git a/src/data/roadmaps/frontend/content/how-does-the-internet-work@yCnn-NfSxIybUQ2iTuUGq.md b/src/data/roadmaps/frontend/content/how-does-the-internet-work@yCnn-NfSxIybUQ2iTuUGq.md index 458665bb6..a9b391000 100644 --- a/src/data/roadmaps/frontend/content/how-does-the-internet-work@yCnn-NfSxIybUQ2iTuUGq.md +++ b/src/data/roadmaps/frontend/content/how-does-the-internet-work@yCnn-NfSxIybUQ2iTuUGq.md @@ -4,7 +4,7 @@ The internet is a global network that connects computers and devices so they can Visit the following resources to learn more: -- [@roadmap@Introduction to Internet](https://roadmap.sh/guides/what-is-internet) +- [@article@Introduction to Internet](https://roadmap.sh/guides/what-is-internet) - [@article@How does the Internet Work?](https://cs.fyi/guide/how-does-internet-work) - [@article@How Does the Internet Work? MDN Docs](https://developer.mozilla.org/en-US/docs/Learn/Common_questions/How_does_the_Internet_work) - [@video@How the Internet Works in 5 Minutes](https://www.youtube.com/watch?v=7_LPdttKXPc) diff --git a/src/data/roadmaps/frontend/content/internet@VlNNwIEDWqQXtqkHWJYzC.md b/src/data/roadmaps/frontend/content/internet@VlNNwIEDWqQXtqkHWJYzC.md index de067dbaa..f34a4636f 100644 --- a/src/data/roadmaps/frontend/content/internet@VlNNwIEDWqQXtqkHWJYzC.md +++ b/src/data/roadmaps/frontend/content/internet@VlNNwIEDWqQXtqkHWJYzC.md @@ -4,5 +4,5 @@ The Internet is a global network of interconnected computer networks that use th Visit the following resources to learn more: -- [@roadmap@Introduction to Internet](https://roadmap.sh/guides/what-is-internet) +- [@article@Introduction to Internet](https://roadmap.sh/guides/what-is-internet) - [@article@The Internet](https://en.wikipedia.org/wiki/Internet)