diff --git a/src/components/TopicDetail/TopicDetail.tsx b/src/components/TopicDetail/TopicDetail.tsx index 287db0823..ff5c9d132 100644 --- a/src/components/TopicDetail/TopicDetail.tsx +++ b/src/components/TopicDetail/TopicDetail.tsx @@ -1,8 +1,5 @@ -import { useEffect, useMemo, useRef, useState } from 'preact/hooks'; -import CheckIcon from '../../icons/check.svg'; +import { useMemo, useRef, useState } from 'preact/hooks'; import CloseIcon from '../../icons/close.svg'; -import ProgressIcon from '../../icons/progress.svg'; -import ResetIcon from '../../icons/reset.svg'; import SpinnerIcon from '../../icons/spinner.svg'; import { useKeydown } from '../../hooks/use-keydown'; @@ -12,14 +9,13 @@ import { useToggleTopic } from '../../hooks/use-toggle-topic'; import { httpGet } from '../../lib/http'; import { isLoggedIn } from '../../lib/jwt'; import { - getTopicStatus, isTopicDone, renderTopicProgress, - ResourceProgressType, ResourceType, updateResourceProgress as updateResourceProgressApi, } from '../../lib/resource-progress'; import { pageLoadingMessage, sponsorHidden } from '../../stores/page'; +import { TopicProgressButton } from './TopicProgressButton'; export function TopicDetail() { const [isActive, setIsActive] = useState(false); @@ -27,9 +23,6 @@ export function TopicDetail() { const [error, setError] = useState(''); const [topicHtml, setTopicHtml] = useState(''); - const [progress, setProgress] = useState('pending'); - const [isUpdatingProgress, setIsUpdatingProgress] = useState(true); - const isGuest = useMemo(() => !isLoggedIn(), []); const topicRef = useRef(null); @@ -52,45 +45,6 @@ export function TopicDetail() { } }; - const handleUpdateResourceProgress = (progress: ResourceProgressType) => { - setIsUpdatingProgress(true); - updateResourceProgressApi( - { - topicId, - resourceId, - resourceType, - }, - progress - ) - .then(() => { - setProgress(progress); - setIsActive(false); - renderTopicProgress(topicId, progress); - }) - .catch((err) => { - alert(err.message); - console.error(err); - }) - .finally(() => { - setIsUpdatingProgress(false); - }); - }; - - // Load the topic status when the topic detail is active - useEffect(() => { - if (!topicId || !resourceId || !resourceType) { - return; - } - - setIsUpdatingProgress(true); - getTopicStatus({ topicId, resourceId, resourceType }) - .then((status) => { - setIsUpdatingProgress(false); - setProgress(status); - }) - .catch(console.error); - }, [topicId, resourceId, resourceType]); - // Close the topic detail when user clicks outside the topic detail useOutsideClick(topicRef, () => { setIsActive(false); @@ -191,10 +145,6 @@ export function TopicDetail() { resourceType === 'roadmap' ? 'roadmaps' : 'best-practices'; const contributionUrl = `https://github.com/kamranahmedse/developer-roadmap/tree/master/src/data/${contributionDir}/${resourceId}/content`; - const allowMarkingDone = ['pending', 'learning'].includes(progress); - const allowMarkingLearning = ['pending'].includes(progress); - const allowMarkingPending = ['done', 'learning'].includes(progress); - return (
{/* Actions for the topic */}
- {isGuest && ( -
- - -
- )} - - {!isGuest && ( -
- {isUpdatingProgress && ( - - )} - - {!isUpdatingProgress && allowMarkingDone && ( - - )} - - {!isUpdatingProgress && allowMarkingLearning && ( - - )} - - {!isUpdatingProgress && allowMarkingPending && ( - - )} -
- )} + { + setIsActive(false); + }} + /> + ); + } + + if (isGuest) { + return ( +
+ + +
+ ); + } + + return ( +
+ {allowMarkingDone && ( + + )} + + {allowMarkingLearning && ( + + )} + + {allowMarkingPending && ( + + )} +
+ ); +}