diff --git a/src/modules/main/modules/sheetHeader/components/SheetHeader.tsx b/src/modules/main/modules/sheetHeader/components/SheetHeader.tsx index c76b53f..935c6b1 100644 --- a/src/modules/main/modules/sheetHeader/components/SheetHeader.tsx +++ b/src/modules/main/modules/sheetHeader/components/SheetHeader.tsx @@ -1,128 +1,145 @@ import type {CharacterData} from "../../../../../types/CharacterJson.ts"; import { - type AttributeWithValue, - loadAttributesWithValues, - loadProfession, - loadRace, - loadRaceVariant + type AttributeWithValue, + loadAttributesWithValues, + loadProfession, + loadRace, + loadRaceVariant } from "../../../../../utils/loaders"; import {useEffect, useState} from 'react'; export default function SheetHeader({jsonData}: { jsonData: CharacterData }) { - const [raceName, setRaceName] = useState(jsonData.r); - const [raceVariantName, setRaceVariantName] = useState(jsonData.rv || ''); - const [professionName, setProfessionName] = useState(jsonData.p); - const [attributes, setAttributes] = useState([]); + const [raceName, setRaceName] = useState(jsonData.r); + const [raceVariantName, setRaceVariantName] = useState(jsonData.rv || ''); + const [professionName, setProfessionName] = useState(jsonData.p); + const [attributes, setAttributes] = useState([]); - useEffect(() => { - let isMounted = true; + useEffect(() => { + let isMounted = true; - const loadData = async () => { - try { - // Load race and profession using the new loader functions - const [race, raceVariant, profession] = await Promise.all([ - loadRace(jsonData.r), - loadRaceVariant(jsonData.rv || ''), - loadProfession(jsonData.p) - ]); + const loadData = async () => { + try { + // Load race and profession using the new loader functions + const [race, raceVariant, profession] = await Promise.all([ + loadRace(jsonData.r), + loadRaceVariant(jsonData.rv || ''), + loadProfession(jsonData.p) + ]); - // Process attributes using the new loadAttributesWithValues function - const loadedAttributes = await loadAttributesWithValues(jsonData.attr.values); + // Process attributes using the new loadAttributesWithValues function + const loadedAttributes = await loadAttributesWithValues(jsonData.attr.values); - if (isMounted) { - setRaceName(race?.name || jsonData.r); - setRaceVariantName(raceVariant?.name|| ''); - // For profession, handle gendered name - if (profession?.name) { - setProfessionName(profession.name.m || profession.name.f || jsonData.p); - } else { - setProfessionName(jsonData.p); - } - // Set the attributes with their values, names, and short forms - setAttributes(loadedAttributes); - } - } catch (error) { - console.error('Error loading data:', error); - if (isMounted) { - setRaceName(jsonData.r); - setProfessionName(jsonData.p); - } - } - }; + if (isMounted) { + setRaceName(race?.name || jsonData.r); + setRaceVariantName(raceVariant?.name || ''); + // For profession, handle gendered name + if (profession?.name) { + setProfessionName(profession.name.m || profession.name.f || jsonData.p); + } else { + setProfessionName(jsonData.p); + } + // Set the attributes with their values, names, and short forms + setAttributes(loadedAttributes); + } + } catch (error) { + console.error('Error loading data:', error); + if (isMounted) { + setRaceName(jsonData.r); + setProfessionName(jsonData.p); + } + } + }; - loadData(); + loadData(); - return () => { - isMounted = false; - }; - }, [jsonData.r, jsonData.rv, jsonData.p, jsonData.attr]); + return () => { + isMounted = false; + }; + }, [jsonData.r, jsonData.rv, jsonData.p, jsonData.attr]); - console.log(jsonData) + console.log(jsonData) - return ( - <> -
-
-

- {jsonData.name} -

- Name -
-
-

- {raceName} {raceVariantName ? <>({raceVariantName}) : ''} -

- Spezies -
-
-

- {professionName} -

- Profession -
+ return ( + <> +
+
+

+ {jsonData.name} +

+ Name +
+
+

+ {raceName} {raceVariantName ? <>({raceVariantName}) : ''} +

+ Spezies +
+
+

+ {professionName} +

+ Profession +
+
+ +
+
+ char bild +
+ +
+
+ {attributes.map(attr => ( +
+
{attr.short}
+
{attr.value}
+
+ ))}
-
-
- char bild -
- -
-
- {attributes.map(attr => ( -
-
{attr.short}
-
{attr.value}
-
- ))} -
- -
+
LP + className="absolute left-0 bottom-full mb-1 px-2 bg-gray-800 text-white text-xs rounded opacity-0 group-hover:opacity-100 transition-opacity duration-200 whitespace-nowrap"> Lebenspunkte -
- 15 / 15 -
-
- 16 / 16 -
- - AP/KP +
+ 15 / 15 +
+
+ +
+ + AP - Astralpunkte / Karmapunkte + className="absolute left-0 bottom-full mb-1 px-2 bg-gray-800 text-white text-xs rounded opacity-0 group-hover:opacity-100 transition-opacity duration-200 whitespace-nowrap"> + Astralpunkte -
+
+ 16 / 16 +
+
-
+
+ + KP + + Karmapunkte + + +
+ 16 / 16 +
+
+ +
SP -
-
-
-
-
-
-
+
+
+
+
+
- - ) +
+
+ + ) }