From 9c6272db25ee44069e9d049a678d8ff0d362db64 Mon Sep 17 00:00:00 2001 From: MikanD Date: Sun, 1 Jun 2025 16:48:44 +0300 Subject: [PATCH] Profession page init [AI] --- src/App.tsx | 4 +- src/pages/ProfessionPage.tsx | 78 ++++++++++++++++++++++++++++++++++ src/pages/SurveyResultPage.tsx | 2 - src/types/survey.ts | 10 +++++ 4 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 src/pages/ProfessionPage.tsx diff --git a/src/App.tsx b/src/App.tsx index 5c77a16..f82322f 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -4,6 +4,7 @@ import {MainPage} from "./pages/MainPage.tsx"; import {SurveyPage} from "./pages/SurveyPage.tsx"; import {DashboardPage} from "./pages/DashboardPage.tsx"; import { SurveyResultPage } from './pages/SurveyResultPage.tsx'; +import { ProfessionPage } from './pages/ProfessionPage.tsx'; @@ -17,9 +18,10 @@ export default function App() { }/> }/> + }/> }/> }/> - }/> + {/* }/> */} ); diff --git a/src/pages/ProfessionPage.tsx b/src/pages/ProfessionPage.tsx new file mode 100644 index 0000000..776f375 --- /dev/null +++ b/src/pages/ProfessionPage.tsx @@ -0,0 +1,78 @@ +import { useParams } from 'react-router-dom'; +import { useData, useDataPage } from '../API/common'; +import { Institution, Profession, Specialty } from '../types/survey'; +import ReactMarkdown from 'react-markdown'; +import { LoadingData } from '../components/LoadingData'; +import { useEffect, useMemo, useState } from 'react'; +import { LoadingList } from '../components/LoadingList'; + + + +export function ProfessionPage() { + const { professionId } = useParams<{ professionId: string }>(); + const profession = useData('surveys', 'professions', professionId || 0); + const specialties = useDataPage('surveys', 'specialties', { profession: professionId || 0 }, !!profession); + + const [institutionCache, setInstitutionCache] = useState>(new Map()); // Кеширование учебных заведений + const institutionsToLoad = useMemo(() => { + if (!specialties.items) return []; + return specialties.items + .map(specialty => specialty.institution) + .filter(id => !institutionCache.has(id)); + }, [specialties.items, institutionCache]); + + useEffect(() => { + if (institutionsToLoad.length > 0) { + Promise.all( + institutionsToLoad.map(id => + useData('surveys', 'institutions', id, true) + ) + ).then(newInstitutions => { + setInstitutionCache(prev => { + const newCache = new Map(prev); + newInstitutions.forEach(institution => institution && newCache.set(institution.id, institution)); + return newCache; + }); + }); + } + }, [institutionsToLoad]); + + return ( +
+ +

{profession?.name}

+
+ {profession?.description || ''} +
+
+

Где можно обучиться

+ ( + + )} + /> +
+
+
+ ); +} + +function SpecialtyBlock({ + specialty, + institution, +}: { + specialty: Specialty; + institution: Institution | undefined; +}) { + return ( +
+

{specialty.name}

+

Учебное заведение: {institution?.name || 'Загрузка...'}

+
+ ); +} \ No newline at end of file diff --git a/src/pages/SurveyResultPage.tsx b/src/pages/SurveyResultPage.tsx index 6cee410..d397764 100644 --- a/src/pages/SurveyResultPage.tsx +++ b/src/pages/SurveyResultPage.tsx @@ -17,8 +17,6 @@ export function SurveyResultPage() { !!scoreVariable ); - - return (
diff --git a/src/types/survey.ts b/src/types/survey.ts index c7c549c..e270f5e 100644 --- a/src/types/survey.ts +++ b/src/types/survey.ts @@ -44,4 +44,14 @@ export interface ScoreVariable { export interface Profession extends UniqueItem { name: string; description: string; +} + +export interface Specialty extends UniqueItem { + name: string; + institution: number; + profession: number; +} + +export interface Institution extends UniqueItem { + name: string; } \ No newline at end of file