aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolfboy248 <121288977+Wolfboy248@users.noreply.github.com>2024-09-04 10:19:24 +0200
committerWolfboy248 <121288977+Wolfboy248@users.noreply.github.com>2024-09-04 10:19:24 +0200
commit441e6e4a8e107172d2743afb58071a4edfc853b6 (patch)
treec9c82df4f309f6b2bc552ccb585411443bdf2288
parentrefactor: dont ignore config file, small fix in profile (diff)
downloadlphub-441e6e4a8e107172d2743afb58071a4edfc853b6.tar.gz
lphub-441e6e4a8e107172d2743afb58071a4edfc853b6.tar.bz2
lphub-441e6e4a8e107172d2743afb58071a4edfc853b6.zip
[#189 + #193] Games page fix
-rw-r--r--frontend/package-lock.json4
-rw-r--r--frontend/src/components/GameCategory.tsx24
-rw-r--r--frontend/src/components/GameEntry.tsx32
3 files changed, 35 insertions, 25 deletions
diff --git a/frontend/package-lock.json b/frontend/package-lock.json
index 209df7f..8b901ad 100644
--- a/frontend/package-lock.json
+++ b/frontend/package-lock.json
@@ -1,11 +1,11 @@
1{ 1{
2 "name": "frontend2", 2 "name": "frontend",
3 "version": "0.1.0", 3 "version": "0.1.0",
4 "lockfileVersion": 3, 4 "lockfileVersion": 3,
5 "requires": true, 5 "requires": true,
6 "packages": { 6 "packages": {
7 "": { 7 "": {
8 "name": "frontend2", 8 "name": "frontend",
9 "version": "0.1.0", 9 "version": "0.1.0",
10 "dependencies": { 10 "dependencies": {
11 "@testing-library/jest-dom": "^5.17.0", 11 "@testing-library/jest-dom": "^5.17.0",
diff --git a/frontend/src/components/GameCategory.tsx b/frontend/src/components/GameCategory.tsx
new file mode 100644
index 0000000..3291e09
--- /dev/null
+++ b/frontend/src/components/GameCategory.tsx
@@ -0,0 +1,24 @@
1import React from 'react';
2import { Link } from "react-router-dom";
3
4import { Game, GameCategoryPortals } from '../types/Game';
5import "../css/Games.css"
6
7interface GameCategoryProps {
8 game: Game;
9 cat: GameCategoryPortals;
10}
11
12const GameCategory: React.FC<GameCategoryProps> = ({cat, game}) => {
13 return (
14 <Link className="games-page-item-body-item" to={"/games/" + game.id + "?cat=" + cat.category.id}>
15 <div>
16 <span className='games-page-item-body-item-title'>{cat.category.name}</span>
17 <br />
18 <span className='games-page-item-body-item-num'>{cat.portal_count}</span>
19 </div>
20 </Link>
21 )
22}
23
24export default GameCategory;
diff --git a/frontend/src/components/GameEntry.tsx b/frontend/src/components/GameEntry.tsx
index 8e58ce9..ced40ee 100644
--- a/frontend/src/components/GameEntry.tsx
+++ b/frontend/src/components/GameEntry.tsx
@@ -1,38 +1,21 @@
1import React from 'react'; 1import React from 'react';
2import { Link } from "react-router-dom"; 2import { Link } from "react-router-dom";
3 3
4import { Game } from '../types/Game'; 4import { Game, GameCategoryPortals } from '../types/Game';
5import "../css/Games.css" 5import "../css/Games.css"
6 6
7import GameCategory from './GameCategory';
8
7interface GameEntryProps { 9interface GameEntryProps {
8 game: Game; 10 game: Game;
9} 11}
10 12
11const GameEntry: React.FC<GameEntryProps> = ({ game }) => { 13const GameEntry: React.FC<GameEntryProps> = ({ game }) => {
14 const [catInfo, setCatInfo] = React.useState<GameCategoryPortals[]>([]);
12 15
13 React.useEffect(() => { 16 React.useEffect(() => {
14 game.category_portals.forEach(catInfo => { 17 setCatInfo(game.category_portals);
15 const itemBody = document.createElement("div"); 18 }, [game.category_portals]);
16 const itemTitle = document.createElement("span");
17 const spacing = document.createElement("br");
18 const itemNum = document.createElement("span");
19
20 itemTitle.innerText = catInfo.category.name;
21 itemNum.innerText = catInfo.portal_count as any as string;
22 itemTitle.classList.add("games-page-item-body-item-title");
23 itemNum.classList.add("games-page-item-body-item-num");
24 itemBody.appendChild(itemTitle);
25 itemBody.appendChild(spacing);
26 itemBody.appendChild(itemNum);
27 itemBody.className = "games-page-item-body-item";
28
29 // itemBody.innerHTML = `
30 // <span className='games-page-item-body-item-title'>${catInfo.category.name}</span><br />
31 // <span className='games-page-item-body-item-num'>${catInfo.portal_count}</span>`
32
33 document.getElementById(`${game.id}`)!.appendChild(itemBody);
34 });
35 }, []);
36 19
37 return ( 20 return (
38 <Link to={"/games/" + game.id}><div className='games-page-item'> 21 <Link to={"/games/" + game.id}><div className='games-page-item'>
@@ -41,6 +24,9 @@ const GameEntry: React.FC<GameEntryProps> = ({ game }) => {
41 <span><b>{game.name}</b></span> 24 <span><b>{game.name}</b></span>
42 </div> 25 </div>
43 <div id={game.id as any as string} className='games-page-item-body'> 26 <div id={game.id as any as string} className='games-page-item-body'>
27 {catInfo.map((cat, index) => {
28 return <GameCategory cat={cat} game={game} key={index}></GameCategory>
29 })}
44 </div> 30 </div>
45 </div></Link> 31 </div></Link>
46 ); 32 );