From a638c96a636a4ebb95b6ca410a1ee2757fc31a46 Mon Sep 17 00:00:00 2001 From: Marces Zastrow Date: Thu, 9 Jan 2025 08:40:55 +0100 Subject: [PATCH] + Changed some stuff --- backend/database.db | Bin 40960 -> 40960 bytes backend/server.js | 17 +++++++ frontend/package.json | 1 + frontend/src/pages/games.jsx | 96 ++++++++++++++++++++++++++++++++--- frontend/src/pages/home.css | 1 - frontend/yarn.lock | 7 +++ 6 files changed, 113 insertions(+), 9 deletions(-) diff --git a/backend/database.db b/backend/database.db index 0d76e02bb4a32769d07f7446ad14fd76106b0291..aa3443156330532129b441ba6d68d41bc4879001 100644 GIT binary patch delta 1361 zcmc(eF-u%Q5XbjDNx*~TG-`1qfgwezU?To&Sx9 { }); }); +// Update Player Character Description +app.put('/games/:gameId/:userId/character', (req, res) => { + const gameId = req.params.gameId; + const userId = req.params.userId; + const { description } = req.body; + + const stmt = db.prepare('UPDATE PlayerCharacter SET description = ? WHERE GameID = ? AND PlayerID = ?'); + stmt.run([description, gameId, userId], function (err) { + if (err) { + console.error('Database error:', err); // Debug output + return res.status(500).json({ error: 'Internal server error' }); + } + res.json({ message: 'Description updated successfully!' }); + }); + stmt.finalize(); +}); + // Fetch Player Items app.get('/games/:charId/items', (req, res) => { const gameId = req.params.gameId; diff --git a/frontend/package.json b/frontend/package.json index 1446ebd..2ebf151 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -12,6 +12,7 @@ "dependencies": { "@emotion/react": "^11.14.0", "@emotion/styled": "^11.14.0", + "@mui/icons-material": "^6.3.1", "@mui/material": "^6.3.1", "axios": "^1.7.9", "react": "^18.3.1", diff --git a/frontend/src/pages/games.jsx b/frontend/src/pages/games.jsx index 591896d..0ab738f 100644 --- a/frontend/src/pages/games.jsx +++ b/frontend/src/pages/games.jsx @@ -2,13 +2,16 @@ import { useState, useEffect, useContext } from 'react'; import { Link, useParams } from 'react-router-dom'; import axios from 'axios'; import { UserContext } from '../context/UserContext'; -import { Box, Typography, Grid2, Card, CardContent, CardMedia, Button } from '@mui/material'; +import { Box, Typography, Grid2, Card, CardContent, CardMedia, Button, IconButton, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, TextField } from '@mui/material'; +import EditIcon from '@mui/icons-material/Edit'; import defaultCharacterImage from '../assets/default-character.png'; const GamesPage = () => { const { userId } = useContext(UserContext); const { gameId } = useParams(); const [character, setCharacter] = useState(null); + const [isEditOpen, setIsEditOpen] = useState(false); + const [newDescription, setNewDescription] = useState(''); useEffect(() => { const fetchCharacter = async () => { @@ -27,11 +30,35 @@ const GamesPage = () => { } }, [userId, gameId]); + const handleEditOpen = () => { + setNewDescription(character.description); + setIsEditOpen(true); + }; + + const handleEditClose = () => { + setIsEditOpen(false); + }; + + const handleSaveDescription = async () => { + try { + const response = await axios.put(`http://localhost:5000/games/${gameId}/${userId}/character`, { description: newDescription }); + setCharacter({ ...character, description: newDescription }); + setIsEditOpen(false); + } catch (error) { + console.error('Error updating description:', error); + } + }; + if (!character) { return ( No Character Found - @@ -39,7 +66,8 @@ const GamesPage = () => { } return ( - + + {/* Character Image and Details */} @@ -53,6 +81,7 @@ const GamesPage = () => { sx={{ borderRadius: '3px' }} /> + {character.CharName} Age: {character.Age} Race: {character.Race} Sex: {character.Sex} @@ -64,8 +93,7 @@ const GamesPage = () => { {/* CharName, Health and Mana Bars */} - {character.CharName} - + Health @@ -88,8 +116,13 @@ const GamesPage = () => { {/* Character Info Section */} - Description - + + Description + + + + + {character.description} @@ -112,8 +145,55 @@ const GamesPage = () => { + + {/* Edit Description Dialog */} + + Edit Description + + + --------------------------------------------------------------------- + + setNewDescription(e.target.value)} + sx={{ + '& .MuiInputBase-root': { + color: '#fff' + }, + '& .MuiInputLabel-root': { + color: '#ccc' + } + }} + /> + + + + + + ); }; -export default GamesPage; \ No newline at end of file +export default GamesPage; \ No newline at end of file diff --git a/frontend/src/pages/home.css b/frontend/src/pages/home.css index 4507f50..43f16b4 100644 --- a/frontend/src/pages/home.css +++ b/frontend/src/pages/home.css @@ -10,7 +10,6 @@ .button-group { display: flex; - align-self: center; flex-direction: row; margin-bottom: 10px; diff --git a/frontend/yarn.lock b/frontend/yarn.lock index 39c1083..b0dee33 100644 --- a/frontend/yarn.lock +++ b/frontend/yarn.lock @@ -522,6 +522,13 @@ resolved "https://registry.yarnpkg.com/@mui/core-downloads-tracker/-/core-downloads-tracker-6.3.1.tgz#e954cd6be58d92f3acc255089413357b6c4e08c6" integrity sha512-2OmnEyoHpj5//dJJpMuxOeLItCCHdf99pjMFfUFdBteCunAK9jW+PwEo4mtdGcLs7P+IgZ+85ypd52eY4AigoQ== +"@mui/icons-material@^6.3.1": + version "6.3.1" + resolved "https://registry.yarnpkg.com/@mui/icons-material/-/icons-material-6.3.1.tgz#f28b5ecc3a4d8e8be389f9e9e5738759c7a98240" + integrity sha512-nJmWj1PBlwS3t1PnoqcixIsftE+7xrW3Su7f0yrjPw4tVjYrgkhU0hrRp+OlURfZ3ptdSkoBkalee9Bhf1Erfw== + dependencies: + "@babel/runtime" "^7.26.0" + "@mui/material@^6.3.1": version "6.3.1" resolved "https://registry.yarnpkg.com/@mui/material/-/material-6.3.1.tgz#75c51a4f4fefa9879fb197e8fae11dc6891a9d0b"