+
);
}
else{
return (
-
+
{game_consoles}
-
+
);
}
}
diff --git a/src/page_elements/GameCard.js b/src/page_elements/GameCard.js
index edbde52..6328b54 100644
--- a/src/page_elements/GameCard.js
+++ b/src/page_elements/GameCard.js
@@ -1,47 +1,24 @@
import * as React from 'react';
import Card from '@mui/material/Card';
import CardContent from '@mui/material/CardContent';
-import CardMedia from '@mui/material/CardMedia';
import Typography from '@mui/material/Typography';
import { CardActionArea } from '@mui/material';
-import placeholder from '../images/placeholder.jpg';
import { useNavigate } from 'react-router-dom';
export default function GameCard(props) {
const game_name = props.name;
const game_id = props.id;
- const liste = true;
const navigate = useNavigate();
- if (liste) {
return (
-
navigate("/console/"+props.console_id+"/"+game_id)}>
+ navigate("/console/"+props.console_id+"/"+game_id)}>
-
+
{game_name}
);
- } else {
- return (
-
-
-
-
-
- {game_name}
-
-
-
-
- );
- }
}
diff --git a/src/page_elements/GameList.js b/src/page_elements/GameList.js
index 4c4e6d8..ac5cb3b 100644
--- a/src/page_elements/GameList.js
+++ b/src/page_elements/GameList.js
@@ -3,30 +3,47 @@ import '@fontsource/roboto/400.css';
import '@fontsource/roboto/500.css';
import '@fontsource/roboto/700.css';
import * as React from 'react';
-import { CircularProgress, Popover } from '@mui/material';
+import { CircularProgress, Button,Typography,Box } from '@mui/material';
+import Pagination from '@mui/material/Pagination';
+import Stack from '@mui/material/Stack';
import axios from 'axios';
import GameCard from './GameCard';
+import {TextField} from '@mui/material';
import { useParams } from 'react-router-dom';
+import { useSearchParams, useNavigate } from "react-router-dom";
-async function loadgamesfromlocalstorage(rom_name,console_id){
+var itemPerPage = 50;
+
+async function loadgamesfromlocalstorage(rom_name,console_id,filter){
let console_rom = JSON.parse(localStorage.getItem(rom_name));
let game_components = []
+ console_rom = console_rom.filter(roms => roms["name"].toLowerCase().includes(filter.toLowerCase()))
+ console_rom.sort((a,b) => a["name"].localeCompare(b["name"]))
for (const roms of console_rom) {
const card =
game_components.push(card);
}
return game_components;
-
-}
+}
function GameList(props) {
const [game_consoles, setGameConsoles] = React.useState([]);
const [has_loaded, setHasLoaded] = React.useState(false);
- const game_components = []
- const params = useParams()
- let console_id = params.consoleId;
+ const [search_filter, setSearchFilter] = React.useState("");
+ const [current_page, setCurrentPage] = React.useState(0);
+ let [searchParams, setSearchParams] = useSearchParams();
+ const navigate = useNavigate();
+ console.log(searchParams);
+ let filter = "";
+ if (searchParams.get("q") !== null){
+ filter = searchParams.get("q");
+ }
+ console.log(filter);
+ const game_components = [];
+ const params = useParams();
+ let console_id = params.consoleId;
let rom_name = "rom" + props.id;
let console_rom = JSON.parse(localStorage.getItem(rom_name));
@@ -37,6 +54,8 @@ function GameList(props) {
axios.get('https://videogamedb.simailadjalim.fr/consoles/'+ console_id + '/roms')
.then((result) => {
localStorage.setItem(rom_name,JSON.stringify(result.data));
+ result.data = result.data.filter(roms => roms["name"].includes(filter));
+ result.data.sort((a,b) => a["name"].localeCompare(b["name"]))
for (const roms of result.data) {
const card =
game_components.push(card);
@@ -46,24 +65,65 @@ function GameList(props) {
})
}else{
console.log("loading roms from cache");
- loadgamesfromlocalstorage(rom_name,props.id).then(game_components =>{
+ loadgamesfromlocalstorage(rom_name,props.id,filter).then(game_components =>{
setGameConsoles(game_components);
setHasLoaded(true);
});
}
}
- if (!has_loaded){
- return <>
+
+
+ const handleKeyDown = (event) => {
+ if (event.key === 'Enter') {
+ // 👇 Get input value
+ setSearchParams({"q" : search_filter});
+ navigate(0);
+ }
+ };
+
+ function NavigationButtons(){
+ let len = (game_consoles.length - (game_consoles.length % itemPerPage)) / itemPerPage;
+ console.log(len);
+
+ return (
+
+ setCurrentPage(value)} />
+ )
+ }
+
+
+ if (!has_loaded){
+ return
- >
+
}
else{
+ let shown = game_consoles.slice(current_page*itemPerPage,current_page*itemPerPage+itemPerPage)
return (
-
-
Jeux
- {game_consoles}
-
+
+ setSearchFilter(e.target.value)} />
+
+
+ Jeux de cette console
+
+
+ {shown}
+
+
+
);
}
}
diff --git a/src/page_elements/GamePlayer.js b/src/page_elements/GamePlayer.js
index 8ba73be..0761dba 100644
--- a/src/page_elements/GamePlayer.js
+++ b/src/page_elements/GamePlayer.js
@@ -4,42 +4,51 @@ import Button from '@mui/material/Button';
import { Box } from '@mui/material';
-
-
export default function GamePlayer(props) {
- const [game, setGame] = React.useState(null);
- var game_id = props.id;
- var console_core = JSON.parse(localStorage.getItem("console"+props.consoleId)).core;
- console.log(console_core);
- axios.get('https://videogamedb.simailadjalim.fr/roms/' + game_id).then((result) => {
- setGame(result.data["name"]);
- })
- function handleDownload(){
- const fileUrl = 'https://videogamedb.simailadjalim.fr/roms/' + props.id + '?romfile=true';
- const link = document.createElement('a');
- link.href = fileUrl;
- document.body.appendChild(link);
- link.click();
- // Clean up the temporary URL and remove the element
- document.body.removeChild(link);
- };
- return (
-
-
GamePlayer
- {game}
-
-
+ const [game, setGame] = React.useState(null);
+ const [console_core,setConsoleCore] = React.useState(null);
+ var game_id = props.id;
+ var current_console = JSON.parse(localStorage.getItem("console"+props.consoleId));
-
-
-
- );
+ if (console_core == null) {
+ if (current_console === null){
+ axios.get('https://videogamedb.simailadjalim.fr/consoles/' + props.consoleId).then((result) => {
+ localStorage.setItem("console"+props.consoleId,JSON.stringify(result.data));
+ setConsoleCore(result.data["core"]);
+ })
+ }else{
+ setConsoleCore(current_console.core);
+ }
+ }
+ axios.get('https://videogamedb.simailadjalim.fr/roms/' + game_id).then((result) => {
+ setGame(result.data["name"]);
+ })
+ function handleDownload(){
+ const fileUrl = 'https://videogamedb.simailadjalim.fr/roms/' + props.id + '?romfile=true';
+ const link = document.createElement('a');
+ link.href = fileUrl;
+ document.body.appendChild(link);
+ link.click();
+ // Clean up the temporary URL and remove the element
+ document.body.removeChild(link);
+ };
+ return (
+
+
GamePlayer
+ {game}
+
+
+
+
+
+
+ );
}
diff --git a/src/page_elements/Topbar.js b/src/page_elements/Topbar.js
index b37c168..44a84ac 100644
--- a/src/page_elements/Topbar.js
+++ b/src/page_elements/Topbar.js
@@ -8,6 +8,9 @@ import Typography from '@mui/material/Typography';
import InputBase from '@mui/material/InputBase';
import MenuIcon from '@mui/icons-material/Menu';
import SearchIcon from '@mui/icons-material/Search';
+import { useNavigate } from 'react-router-dom';
+
+
const Search = styled('div')(({ theme }) => ({
position: 'relative',
@@ -52,10 +55,11 @@ const StyledInputBase = styled(InputBase)(({ theme }) => ({
}));
export default function Topbar() {
+ const navigate = useNavigate();
return (
-
+
-
+
navigate("/") }
sx={{ flexGrow: 1, display: { xs: 'none', sm: 'block' } }}
>
Gros site de retrogaming bien legal la
diff --git a/src/pages/ConsolePage.jsx b/src/pages/ConsolePage.jsx
index 969d302..4f5db5e 100644
--- a/src/pages/ConsolePage.jsx
+++ b/src/pages/ConsolePage.jsx
@@ -1,11 +1,12 @@
import GameList from "../page_elements/GameList";
import {useParams} from 'react-router-dom';
-
+import Topbar from '../page_elements/Topbar';
export default function ConsolePage(){
const params = useParams();
return <>
+
>
}
diff --git a/src/pages/GamePage.jsx b/src/pages/GamePage.jsx
index ece4ebd..d87fc85 100644
--- a/src/pages/GamePage.jsx
+++ b/src/pages/GamePage.jsx
@@ -1,11 +1,15 @@
import GamePlayer from "../page_elements/GamePlayer";
import { useParams } from "react-router-dom";
+import Topbar from '../page_elements/Topbar';
+
export default function GamePage() {
const params = useParams();
let gameId = params.gameId;
let consoleId = params.consoleId;
-
- return ;
+ return <>
+
+ ;
+ >
}
diff --git a/src/pages/HomePage.jsx b/src/pages/HomePage.jsx
index 855f0e1..9eaca00 100644
--- a/src/pages/HomePage.jsx
+++ b/src/pages/HomePage.jsx
@@ -1,13 +1,15 @@
import ConsoleList from "../page_elements/ConsoleList";
import Typography from '@mui/material/Typography';
+import Topbar from '../page_elements/Topbar';
+
export function HomePage(){
return <>
+
Bienvenue sur le site dont tu ne dois pas partager l'existance.