mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-09-01 21:32:35 +02:00
wip
This commit is contained in:
@@ -1,10 +1,7 @@
|
|||||||
import { Loader2Icon, PersonStandingIcon } from 'lucide-react';
|
import { Loader2Icon, PersonStandingIcon } from 'lucide-react';
|
||||||
import { useState } from 'react';
|
import { useMemo, useState } from 'react';
|
||||||
import { usePersonalizedRoadmap } from '../../hooks/use-personalized-roadmap';
|
import { usePersonalizedRoadmap } from '../../hooks/use-personalized-roadmap';
|
||||||
import {
|
import { renderTopicProgress } from '../../lib/resource-progress';
|
||||||
loadFreshProgress,
|
|
||||||
renderTopicProgress,
|
|
||||||
} from '../../lib/resource-progress';
|
|
||||||
import { PersonalizedRoadmapModal } from './PersonalizedRoadmapModal';
|
import { PersonalizedRoadmapModal } from './PersonalizedRoadmapModal';
|
||||||
import { useMutation, useQuery } from '@tanstack/react-query';
|
import { useMutation, useQuery } from '@tanstack/react-query';
|
||||||
import { httpPost } from '../../lib/query-http';
|
import { httpPost } from '../../lib/query-http';
|
||||||
@@ -12,6 +9,7 @@ import { useToast } from '../../hooks/use-toast';
|
|||||||
import { queryClient } from '../../stores/query-client';
|
import { queryClient } from '../../stores/query-client';
|
||||||
import { userResourceProgressOptions } from '../../queries/resource-progress';
|
import { userResourceProgressOptions } from '../../queries/resource-progress';
|
||||||
import { useAuth } from '../../hooks/use-auth';
|
import { useAuth } from '../../hooks/use-auth';
|
||||||
|
import { roadmapJSONOptions } from '../../queries/roadmap';
|
||||||
|
|
||||||
type BulkUpdateResourceProgressBody = {
|
type BulkUpdateResourceProgressBody = {
|
||||||
done: string[];
|
done: string[];
|
||||||
@@ -31,11 +29,19 @@ export function PersonalizedRoadmap(props: PersonalizedRoadmapProps) {
|
|||||||
const currentUser = useAuth();
|
const currentUser = useAuth();
|
||||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||||
|
|
||||||
const { data: userResourceProgress } = useQuery(
|
const { data: roadmap } = useQuery(
|
||||||
userResourceProgressOptions('roadmap', roadmapId),
|
roadmapJSONOptions(roadmapId),
|
||||||
queryClient,
|
queryClient,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const allClickableNodes = useMemo(() => {
|
||||||
|
return (
|
||||||
|
roadmap?.json?.nodes?.filter((node) =>
|
||||||
|
['topic', 'subtopic'].includes(node?.type ?? ''),
|
||||||
|
) ?? []
|
||||||
|
);
|
||||||
|
}, [roadmap]);
|
||||||
|
|
||||||
const { mutate: bulkUpdateResourceProgress, isPending: isBulkUpdating } =
|
const { mutate: bulkUpdateResourceProgress, isPending: isBulkUpdating } =
|
||||||
useMutation(
|
useMutation(
|
||||||
{
|
{
|
||||||
@@ -67,16 +73,17 @@ export function PersonalizedRoadmap(props: PersonalizedRoadmapProps) {
|
|||||||
onData: (data) => {
|
onData: (data) => {
|
||||||
const { topicIds } = data;
|
const { topicIds } = data;
|
||||||
topicIds.forEach((topicId) => {
|
topicIds.forEach((topicId) => {
|
||||||
renderTopicProgress(topicId, 'skipped');
|
renderTopicProgress(topicId, 'pending');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onFinish: (data) => {
|
onFinish: (data) => {
|
||||||
console.log('-'.repeat(20));
|
const { topicIds } = data;
|
||||||
console.log('onFinish', data);
|
const remainingTopicIds = allClickableNodes
|
||||||
console.log('-'.repeat(20));
|
.filter((node) => !topicIds.includes(node?.id ?? ''))
|
||||||
|
.map((node) => node?.id ?? '');
|
||||||
|
|
||||||
bulkUpdateResourceProgress({
|
bulkUpdateResourceProgress({
|
||||||
skipped: data.topicIds,
|
skipped: remainingTopicIds,
|
||||||
learning: [],
|
learning: [],
|
||||||
done: [],
|
done: [],
|
||||||
pending: [],
|
pending: [],
|
||||||
@@ -119,9 +126,8 @@ export function PersonalizedRoadmap(props: PersonalizedRoadmapProps) {
|
|||||||
<PersonalizedRoadmapModal
|
<PersonalizedRoadmapModal
|
||||||
onClose={() => setIsModalOpen(false)}
|
onClose={() => setIsModalOpen(false)}
|
||||||
onSubmit={(information) => {
|
onSubmit={(information) => {
|
||||||
const { skipped = [] } = userResourceProgress ?? {};
|
for (const node of allClickableNodes) {
|
||||||
for (const topicId of skipped) {
|
renderTopicProgress(node?.id, 'skipped');
|
||||||
renderTopicProgress(topicId, 'pending');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
generatePersonalizedRoadmap(information);
|
generatePersonalizedRoadmap(information);
|
||||||
|
@@ -32,13 +32,14 @@ export function PersonalizedRoadmapForm(props: PersonalizedRoadmapFormProps) {
|
|||||||
placeholder="I already know about HTML, CSS, and JavaScript..."
|
placeholder="I already know about HTML, CSS, and JavaScript..."
|
||||||
value={info}
|
value={info}
|
||||||
onChange={(e) => setInfo(e.target.value)}
|
onChange={(e) => setInfo(e.target.value)}
|
||||||
|
autoFocus
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="mt-2 grid grid-cols-2 gap-2">
|
<div className="mt-2 grid grid-cols-2 gap-2">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="flex items-center gap-2 rounded-xl border border-gray-200 p-2 px-4 text-gray-600 hover:bg-gray-100 focus:outline-none"
|
className="flex items-center justify-center gap-2 rounded-xl border border-gray-200 p-2 px-4 text-gray-600 hover:bg-gray-100 focus:outline-none"
|
||||||
onClick={onClearProgress}
|
onClick={onClearProgress}
|
||||||
>
|
>
|
||||||
<XIcon className="h-4 w-4" />
|
<XIcon className="h-4 w-4" />
|
||||||
@@ -46,7 +47,7 @@ export function PersonalizedRoadmapForm(props: PersonalizedRoadmapFormProps) {
|
|||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
className="flex items-center gap-2 rounded-xl bg-black p-2 px-4 text-white hover:opacity-90 focus:outline-none"
|
className="flex items-center justify-center gap-2 rounded-xl bg-black p-2 px-4 text-white hover:opacity-90 focus:outline-none"
|
||||||
>
|
>
|
||||||
<PersonStandingIcon className="h-4 w-4" />
|
<PersonStandingIcon className="h-4 w-4" />
|
||||||
Personalize
|
Personalize
|
||||||
|
Reference in New Issue
Block a user