diff options
| author | Wolfboy248 <121288977+Wolfboy248@users.noreply.github.com> | 2024-09-04 10:19:24 +0200 |
|---|---|---|
| committer | Wolfboy248 <121288977+Wolfboy248@users.noreply.github.com> | 2024-09-04 10:19:24 +0200 |
| commit | 441e6e4a8e107172d2743afb58071a4edfc853b6 (patch) | |
| tree | c9c82df4f309f6b2bc552ccb585411443bdf2288 /frontend/src | |
| parent | refactor: dont ignore config file, small fix in profile (diff) | |
| download | lphub-441e6e4a8e107172d2743afb58071a4edfc853b6.tar.gz lphub-441e6e4a8e107172d2743afb58071a4edfc853b6.tar.bz2 lphub-441e6e4a8e107172d2743afb58071a4edfc853b6.zip | |
[#189 + #193] Games page fix
Diffstat (limited to 'frontend/src')
| -rw-r--r-- | frontend/src/components/GameCategory.tsx | 24 | ||||
| -rw-r--r-- | frontend/src/components/GameEntry.tsx | 32 |
2 files changed, 33 insertions, 23 deletions
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 @@ | |||
| 1 | import React from 'react'; | ||
| 2 | import { Link } from "react-router-dom"; | ||
| 3 | |||
| 4 | import { Game, GameCategoryPortals } from '../types/Game'; | ||
| 5 | import "../css/Games.css" | ||
| 6 | |||
| 7 | interface GameCategoryProps { | ||
| 8 | game: Game; | ||
| 9 | cat: GameCategoryPortals; | ||
| 10 | } | ||
| 11 | |||
| 12 | const 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 | |||
| 24 | export 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 @@ | |||
| 1 | import React from 'react'; | 1 | import React from 'react'; |
| 2 | import { Link } from "react-router-dom"; | 2 | import { Link } from "react-router-dom"; |
| 3 | 3 | ||
| 4 | import { Game } from '../types/Game'; | 4 | import { Game, GameCategoryPortals } from '../types/Game'; |
| 5 | import "../css/Games.css" | 5 | import "../css/Games.css" |
| 6 | 6 | ||
| 7 | import GameCategory from './GameCategory'; | ||
| 8 | |||
| 7 | interface GameEntryProps { | 9 | interface GameEntryProps { |
| 8 | game: Game; | 10 | game: Game; |
| 9 | } | 11 | } |
| 10 | 12 | ||
| 11 | const GameEntry: React.FC<GameEntryProps> = ({ game }) => { | 13 | const 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 | ); |