From 20db0baec52d95c502bc9fdb778128d62b4d939a Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Wed, 12 Apr 2023 19:04:59 +0100 Subject: [PATCH] Update topic done functionality --- src/components/TopicDetail/TopicDetail.tsx | 18 +++--- ...ource-progress.ts => resource-progress.ts} | 62 +++++++++++++++++-- 2 files changed, 66 insertions(+), 14 deletions(-) rename src/lib/{user-resource-progress.ts => resource-progress.ts} (58%) diff --git a/src/components/TopicDetail/TopicDetail.tsx b/src/components/TopicDetail/TopicDetail.tsx index f78bccef2..6156a191a 100644 --- a/src/components/TopicDetail/TopicDetail.tsx +++ b/src/components/TopicDetail/TopicDetail.tsx @@ -10,9 +10,10 @@ import { httpGet } from '../../lib/http'; import { isLoggedIn } from '../../lib/jwt'; import { isTopicDone, + renderTopicProgress, ResourceType, - toggleMarkTopicDone, -} from '../../lib/user-resource-progress'; + toggleMarkTopicDone as toggleMarkTopicDoneApi, +} from '../../lib/resource-progress'; import { useKeydown } from '../../hooks/use-keydown'; export function TopicDetail() { @@ -32,22 +33,21 @@ export function TopicDetail() { const [resourceId, setResourceId] = useState(''); const [resourceType, setResourceType] = useState('roadmap'); - const toggleResourceProgress = (isDone: boolean) => { + const toggleMarkTopicDone = (isDone: boolean) => { setIsUpdatingProgress(true); - toggleMarkTopicDone({ topicId, resourceId, resourceType }, isDone) + toggleMarkTopicDoneApi({ topicId, resourceId, resourceType }, isDone) .then(() => { setIsDone(isDone); setIsActive(false); + renderTopicProgress(topicId, isDone); }) - .catch(err => { + .catch((err) => { alert(err.message); console.error(err); }) .finally(() => { setIsUpdatingProgress(false); }); - - console.log('toggle', isDone); }; // Load the topic status when the topic detail is active @@ -168,7 +168,7 @@ export function TopicDetail() { {!isUpdatingProgress && !isDone && (