fix: update favourite

feat/roadmaps
Arik Chakma 2 months ago
parent 484471d727
commit edb0329a6d
  1. 34
      src/components/Roadmaps/RoadmapsPage.tsx

@ -9,6 +9,9 @@ import {
setUrlParams, setUrlParams,
} from '../../lib/browser.ts'; } from '../../lib/browser.ts';
import { RoadmapCard } from './RoadmapCard.tsx'; import { RoadmapCard } from './RoadmapCard.tsx';
import { httpGet } from '../../lib/http.ts';
import type { UserProgressResponse } from '../HeroSection/FavoriteRoadmaps.tsx';
import { isLoggedIn } from '../../lib/jwt.ts';
const groupNames = [ const groupNames = [
'Absolute Beginners', 'Absolute Beginners',
@ -474,6 +477,37 @@ export function RoadmapsPage() {
]); ]);
}, [activeGroup]); }, [activeGroup]);
async function loadProgress() {
const { response: progressList, error } =
await httpGet<UserProgressResponse>(
`${import.meta.env.PUBLIC_API_URL}/v1-get-hero-roadmaps`,
);
if (error || !progressList) {
return;
}
progressList?.forEach((progress) => {
window.dispatchEvent(
new CustomEvent('mark-favorite', {
detail: {
resourceId: progress.resourceId,
resourceType: progress.resourceType,
isFavorite: progress.isFavorite,
},
}),
);
});
}
useEffect(() => {
if (!isLoggedIn()) {
return;
}
loadProgress().finally(() => {});
}, []);
useEffect(() => { useEffect(() => {
const { g } = getUrlParams() as { g: AllowGroupNames }; const { g } = getUrlParams() as { g: AllowGroupNames };
if (!g) { if (!g) {

Loading…
Cancel
Save