From 212b6a58d900f43aeb6a4750ad54d5e27f64c998 Mon Sep 17 00:00:00 2001 From: Marces Zastrow Date: Fri, 28 Feb 2025 16:44:29 +0100 Subject: [PATCH] stuffsa ddsabps fjz glkjfsfhbv hg 23445504 bytes frontend/src/pages/gameMasterPage.jsx | 435 ++++++++++++-------------- 2 files changed, 204 insertions(+), 231 deletions(-) diff --git a/backend/database.db b/backend/database.db index 8705d7e9ede46f49046f3171e3cdcf90b3d63e46..30b8b85212cc73b083e273e517d5a6712f62146e 100644 GIT binary patch delta 1557 zcmWmEXIl;c0EOY}RY@vI6b+*!D-EGRQj%54Ohwb)dy^T$YiIAh_bl0a@4ffldp+mF z{rrP-($ljn(=pk}kUhmY%#gh~DZyy48JT0u$T1p_2PQCu8S=s$`Cx(ku!I$?Q2;h5 z2wN0_9SWle?BRf-CMHp%$9CZ+Zx~PZxXn=-@L=>XY2r+1kCTNOgXpR<$ zMN7mX9tmiL)<{GWl97T`q@fMkq8-|!13ID;I-?7^q8qxS2YR9xdZQ2eq96KW00v?Z z24e_@Vi?jf93wCiqc9p{kb$unhw;e71Wd#v7%>@BFcs4<9WyW!S(t^{n1i{Phxu55 zg;<2eSc0WkhUHj+l~{$uMh^BN7yEGl z2XP38aRf(k499T-Cvgg=aRz5`4(D+J7jX%faRpa#4cBo4H*pKMaR+yC5BKo^5Ag_( z@dQut4A1cbFYyYm@dj`44)5^+AMpvF@daP;4d3wtKk*B{@dtnLFO%&Xq2y6a6jQ}a z$*Y(v`4kH!zhbFaDb`8>#YQQp*eZn-JEgEvM6p*Kl%h&8#ZhrmoD~jAB2~w&nHI!hb zrV^smQbLt5rM42T)KMaox=KBzzS2Nxs6;AJO0?2QiBTFWO_ZieGo`uGLWxycDsf7@ blAyFwS}Tc4l9H^XD5*-CA(xLagn9o5!Kp2E delta 1557 zcmWmEXIl;c0EOY}EhB}Hq9GztqM;~CQ$j>4r6RKT-XlWxYwx``*(BL}@4ffldp+mF z{rrP-($i;Iq+_zZA$y8Lm?1kWHQ8t|&&V-m<`@kyfhqDJFY+Nj%uoR4us}f+LSa~< z2#TT@tWX@*ut5owge~k~4+oTjBTAzToKP0!;EeKcK?PKVE8I{C?x>6^@PH@0;Ek&A zfiJ3|I{e^|8mNf?1fmv#5R4FnA`IcEjR@31BLUsb&=ApRgvN+L6T~78@o0(! zB%&FTkc<>GM+>B)C0Zd3tjulvmRalKRSc`R7j}6#}P1uYqY{6D+!*=YzPVB;N>_Im6A_x1Bi~Tr& zgE)l4ID(@%hT}MalQ@ObID@k|hx53Ai@1c#xPq&=hU>V2o4AGBxP!a6hx>Sdhj@g? zc!H;RhUa*Jmw1KOc!Rfihxhn^kNAYo_=2zahVS@+pZJB}_=CUrH=gYqp_nM9N**Pz zl26I6m?;GmbHzd_s1#BPE0#(TrKnO&u~LdF){2c%LMf@(Dt3y!;-HjL9F@{a8O2E{ ztCUlmmGX*xV@m8uTK8mkWO{uQ~1S++Z zASGA{Q9_k4C0wbkL@0HXNTse)PpPj&DGii{O0?2QX{^L3O_W$APKj5VDhW!W(o9KG bl9d#txza*ORaz>olr*KaA(xLagn9l4m!B { }; // Add new handler for form changes - const handleFormChange = (key, value) => { - setFormData(prev => ({ + const handleFormChange = (newFormData) => { + setFormData(newFormData); + }; + + // Optimiere Select-Komponenten mit React.memo +const SelectField = React.memo(({ name, value, label, options, onChange, sx }) => ( + + {label} + + +)); + +// Add this before the EditModal component +const nonEditableFields = ['ItemID', 'NpcID', 'CharID', 'GameID', 'Img', 'OwnerName']; + +// Add the RenderField component +const RenderField = React.memo(({ field, formData, handleFormChange, commonStyles }) => { + // Convert field name to label + const getLabel = (fieldName) => { + const labels = { + ItemName: 'Name', + CharName: 'Name', + Name: 'Name', + Type: 'Typ', + Art: 'Art', + Rarity: 'Seltenheit', + MaxDurability: 'Max. Haltbarkeit', + CurrentDurability: 'Aktuelle Haltbarkeit', + GoldValue: 'Goldwert', + Abilities: 'Fähigkeiten', + AP: 'Angriffspunkte', + Race: 'Rasse', + Sex: 'Geschlecht', + Age: 'Alter', + Job: 'Beruf', + Description: 'Beschreibung', + MaxHealth: 'Max. Gesundheit', + CurrentHealth: 'Aktuelle Gesundheit', + MaxMana: 'Max. Mana', + CurrentMana: 'Aktuelles Mana', + Strength: 'Stärke', + Dexterity: 'Geschicklichkeit', + Agility: 'Beweglichkeit', + Endurance: 'Ausdauer', + Level: 'Level', + Allied: 'Status', + Gold: 'Gold' + }; + return labels[fieldName] || fieldName; + }; + + // Special fields that should use Select instead of TextField + const selectFields = { + Allied: [ + { value: 0, label: 'Verbündet' }, + { value: 1, label: 'Neutral' }, + { value: 2, label: 'Feindlich' } + ], + Rarity: [ + { value: 'common', label: 'Gewöhnlich' }, + { value: 'uncommon', label: 'Ungewöhnlich' }, + { value: 'rare', label: 'Selten' }, + { value: 'epic', label: 'Episch' }, + { value: 'legendary', label: 'Legendär' } + ] + }; + + if (selectFields[field]) { + return ( + + {getLabel(field)} + + + ); + } + + return ( + handleFormChange(field, e.target.value)} + sx={{ mb: 2, ...commonStyles.input }} + type={typeof formData[field] === 'number' ? 'number' : 'text'} + multiline={field === 'Description' || field === 'Abilities'} + rows={field === 'Description' || field === 'Abilities' ? 4 : 1} + /> + ); +}); + +// First, create a memoized EditModal component outside the main component +const EditModal = React.memo(({ + editModalOpen, + handleModalClose, + formData, + editType, + handleUpdate, + handleFormChange, + commonStyles +}) => { + const dialogContentRef = React.useRef(null); + + // Store form state locally + const [localFormData, setLocalFormData] = React.useState(formData); + + // Update local form data when parent formData changes + React.useEffect(() => { + setLocalFormData(formData); + }, [formData]); + + // Local form change handler + const handleLocalFormChange = (key, value) => { + setLocalFormData(prev => ({ ...prev, [key]: value })); }; - // Update the EditModal component - const EditModal = () => { - const nonEditableFields = [ - 'GameID', 'CharID', 'ItemID', 'NPCID', 'Img', 'img', - 'GameId', 'NpcID', 'itemID', 'PlayerID', 'OwnerName' - ]; - - const renderField = (key) => { - if (key === 'Allied') { - return ( - - Status - - - ); - } - - if (key === 'Sex') { - return ( - - Sex - - - ); - } - - if (key === 'Rarity') { - return ( - - Rarity - - - ); - } - - if (key === 'Type') { - return ( - - Type - - - ); - } - - if (key === 'Art') { - return ( - - Art - - - ); - } - - if (key === 'OwnerID') { - return ( - - Owner - - - ); - } - - return ( - handleFormChange(key, e.target.value)} - sx={{ ...commonStyles.input, mb: 2 }} - /> - ); - }; - - return ( - - - {editType === 'item' - ? 'Gegenstand Bearbeiten' - : editType === 'npc' - ? 'NSC Bearbeiten' - : 'Charakter Bearbeiten'} - - - {formData && ( - - {Object.keys(formData) - .filter(key => !nonEditableFields.includes(key)) - .map(key => renderField(key))} - - )} - - - - - - - ); + // Handle final update + const handleFinalUpdate = () => { + handleFormChange(localFormData); // Update parent state + handleUpdate(); // Save changes }; + return ( + + + {editType === 'item' ? 'Gegenstand Bearbeiten' : + editType === 'npc' ? 'NSC Bearbeiten' : + 'Charakter Bearbeiten'} + + + {localFormData && ( + + {Object.keys(localFormData) + .filter(key => !nonEditableFields.includes(key)) + .map(key => ( + + ))} + + )} + + + + + + + ); +}); + const Section = ({ title, items, createPath, createText }) => ( { createPath="/create-item" createText="Gegenstand Erstellen" /> - + ); };