diff --git a/.gitignore b/.gitignore index e63b1ee..f4214eb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ back/target/ front/dist/ back/public/ +back/data/ +back/Cargo.lock -back/Cargo.lock \ No newline at end of file diff --git a/back/Cargo.toml b/back/Cargo.toml index 8b48126..6be9ee0 100644 --- a/back/Cargo.toml +++ b/back/Cargo.toml @@ -6,4 +6,7 @@ edition = "2021" [dependencies] actix-files = "0.6.6" actix-web = "4" +sqlite = "0.36.1" +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0.133" diff --git a/back/src/create_db.rs b/back/src/create_db.rs new file mode 100644 index 0000000..21cb84a --- /dev/null +++ b/back/src/create_db.rs @@ -0,0 +1,23 @@ +use sqlite::{Connection, OpenFlags}; + +pub fn init() -> sqlite::Result<()> { + let conn = Connection::open_with_flags( + "./data/data.db", + OpenFlags::new() + .with_create() + .with_read_write() + )?; + + conn.execute( + "CREATE TABLE IF NOT EXISTS articles ( + id INTEGER PRIMARY KEY, + title TEXT NOT NULL, + auteur TEXT, + edited_at DATE_FORMAT('now', '%YYYY-%mm-%dd'), + published_at DATE_FORMAT('now', '%YYYY-%mm-%dd'), + content TEXT NOT NULL + )", + )?; + + Ok(()) +} diff --git a/back/src/main.rs b/back/src/main.rs index d4d0ee1..141544d 100644 --- a/back/src/main.rs +++ b/back/src/main.rs @@ -1,13 +1,129 @@ -use actix_web::{App, HttpServer}; +mod create_db; +use create_db::init; + +use actix_web::{App, web, HttpServer, get, Responder, HttpResponse, http::header::ContentType}; use actix_files::Files; +use serde_json::json; +use sqlite::{Connection, State}; +use serde::{Serialize, Deserialize}; + +#[derive(serde::Serialize)] +struct Article { + id: i64, + title: String, + auteur: String, + edited_at: String, + published_at: String, + content: String, +} + +#[get("/api/hello")] +async fn hello() -> impl Responder { + HttpResponse::Ok().body("Hello world!") +} + +#[get("/api/articles")] +async fn get_articles() -> impl Responder { + let conn = Connection::open("./data/data.db").unwrap(); + let mut stmt = conn.prepare("SELECT * FROM articles").unwrap(); + let mut articles = Vec::new(); + + while let State::Row = stmt.next().unwrap() { + let id = stmt.read::(0).unwrap(); + let title = stmt.read::(1).unwrap(); + let content = stmt.read::(5).unwrap(); + articles.push(Article { + id, + title, + auteur: "".to_string(), + edited_at: "".to_string(), + published_at: "".to_string(), + content + }); + } + + HttpResponse::Ok().json(articles) +} + + +#[get("/api/articles/{id}")] +async fn get_article(path: web::Path) -> impl Responder { + let id = path.into_inner(); + + // Open the database connection + let conn = match Connection::open("./data/data.db") { + Ok(conn) => conn, + Err(err) => { + eprintln!("Failed to connect to database: {}", err); + return HttpResponse::InternalServerError().body("Failed to connect to database"); + } + }; + + // Fetch the article from the database + match fetch_article_by_id(&conn, id) { + Ok(Some(article)) => HttpResponse::Ok().json(article), + Ok(None) => HttpResponse::NotFound().body(format!("Article with ID {} not found", id)), + Err(err) => { + eprintln!("Database query error: {}", err); + HttpResponse::InternalServerError().body("Database query failed") + } + } +} + +/// Fetches an article by its ID from the database. +fn fetch_article_by_id(conn: &Connection, id: i64) -> Result, sqlite::Error> { + let mut stmt = conn.prepare( + "SELECT id, title, auteur, edited_at, published_at, content + FROM articles WHERE id = ?1" + )?; + stmt.bind((1, id))?; + + let mut article = None; + while let State::Row = stmt.next()? { + article = Some(Article { + id: stmt.read::(0)?, + title: stmt.read::(1)?, + auteur: stmt.read::(2)?, + edited_at: stmt.read::(3)?, + published_at: stmt.read::(4)?, + content: stmt.read::(5)?, + }); + } + + Ok(article) +} + +#[get("/api")] +async fn api() -> impl Responder { + let value = json!({ + "code": 200, + "success": true, + "payload": { + "features": [ + "serde", + "json" + ], + "homepage": null + } + }); + HttpResponse::Ok() + .content_type(ContentType::json()) + .body(value.to_string()) +} #[actix_web::main] -async fn main() -> std::io::Result<()> { +async fn main() -> Result<(), std::io::Error> { + let _ = init(); + HttpServer::new(|| { App::new() - .service(Files::new("/", "./public").index_file("index.html")) + .service(hello) + .service(get_articles) + .service(api) + .service(get_article) + .service(Files::new("/", "public").index_file("index.html")) }) - .bind(("0.0.0.0", 8080))? + .bind(("0.0.0.0", 2486))? .run() .await } diff --git a/docker-compose.yml b/docker-compose.yml index 1e8480c..9bcaab9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,5 +6,7 @@ services: container_name: web restart: always ports: - - 8080:8080 + - 8080:2486 + volumes: + - ./back/data:/app/data diff --git a/dockerfile b/dockerfile index d8e8f78..f092a14 100644 --- a/dockerfile +++ b/dockerfile @@ -10,9 +10,9 @@ RUN cargo build --release FROM debian:bookworm-slim WORKDIR /app -RUN apt-get update & apt-get install -y extra-runtime-dependencies & rm -rf /var/lib/apt/lists/* +RUN apt update && apt install -y libsqlite3-0 COPY --from=front /app/dist /app/public COPY --from=back /app/target/release/back /app/back -EXPOSE 8080 +EXPOSE 2486 CMD ["/app/back"] diff --git a/front/index.html b/front/index.html index e4b78ea..48914fe 100644 --- a/front/index.html +++ b/front/index.html @@ -4,7 +4,8 @@ - Vite + React + TS + EcoMarin +
diff --git a/front/package.json b/front/package.json index 8bd44d7..7e85ec8 100644 --- a/front/package.json +++ b/front/package.json @@ -10,9 +10,15 @@ "preview": "vite preview" }, "dependencies": { + "@react-three/drei": "^9.120.0", + "@react-three/fiber": "^8.17.10", + "@types/three": "^0.170.0", "react": "^18.3.1", "react-dom": "^18.3.1", - "react-router": "^7.0.2" + "react-router": "^7.0.2", + "three": "^0.171.0", + "three-stdlib": "^2.34.0", + "react-router-dom": "^6.2.1" }, "devDependencies": { "@eslint/js": "^9.15.0", @@ -25,6 +31,7 @@ "globals": "^15.12.0", "typescript": "~5.6.2", "typescript-eslint": "^8.15.0", - "vite": "^6.0.1" + "vite": "^6.0.1", + "react-router-dom": "^6.2.1" } } diff --git a/front/public/models/man.glb b/front/public/models/man.glb new file mode 100644 index 0000000..abd24f6 Binary files /dev/null and b/front/public/models/man.glb differ diff --git a/front/public/pictures/sea.gif b/front/public/pictures/sea.gif new file mode 100644 index 0000000..78a4617 Binary files /dev/null and b/front/public/pictures/sea.gif differ diff --git a/front/src/components/3d/Axes.tsx b/front/src/components/3d/Axes.tsx new file mode 100644 index 0000000..195e266 --- /dev/null +++ b/front/src/components/3d/Axes.tsx @@ -0,0 +1,31 @@ +import React from 'react' +import { LineBasicMaterial, Line, Group } from 'three' +import { useFrame } from '@react-three/fiber' +import * as THREE from 'three' + +export default function Axes() { + const axes = new Group() + + const x = new Line( + new THREE.BufferGeometry().setFromPoints([new THREE.Vector3(0, 0, 0), + new THREE.Vector3(100, 0, 0)]), + new LineBasicMaterial({ color: 0xff0000 }) // red + ) + const y = new Line( + new THREE.BufferGeometry().setFromPoints([new THREE.Vector3(0, 0, 0), + new THREE.Vector3(0, 100, 0)]), + new LineBasicMaterial({ color: 0x00ff00 }) // green + ) + const z = new Line( + new THREE.BufferGeometry().setFromPoints([new THREE.Vector3(0, 0, 0), + new THREE.Vector3(0, 0, 100)]), + new LineBasicMaterial({ color: 0x0000ff }) // blue + ) + + axes.add(x) + axes.add(y) + axes.add(z) + + + return +} \ No newline at end of file diff --git a/front/src/components/3d/Character.tsx b/front/src/components/3d/Character.tsx new file mode 100644 index 0000000..f6d7d66 --- /dev/null +++ b/front/src/components/3d/Character.tsx @@ -0,0 +1,25 @@ +import { Group, Mesh, MeshStandardMaterial, BufferGeometry } from 'three' +import { useGLTF } from '@react-three/drei' + +export default function Character() { + // import glb file + + // load the glb file in "/models/BASEmodel.glb" + const { nodes, materials, scene } = useGLTF('/models/man.glb') + + // rotate the character + scene.rotation.x = -Math.PI / 2 + scene.rotation.y = 0 + + // enfoncer le personnage dans le sol + scene.position.y = -1 + + return ( + + + + + ) + + +} \ No newline at end of file diff --git a/front/src/components/3d/Floor.tsx b/front/src/components/3d/Floor.tsx new file mode 100644 index 0000000..dbb054b --- /dev/null +++ b/front/src/components/3d/Floor.tsx @@ -0,0 +1,20 @@ + +import React from 'react' +import { Group } from 'three' +import * as THREE from 'three' + + +export default function Floor() { + const floor = new Group() + + const floorGeometry = new THREE.PlaneGeometry(100, 100, 100, 100) + const floorMaterial = new THREE.MeshStandardMaterial({ color: 0x00ff00, side: THREE.DoubleSide }) + const floorMesh = new THREE.Mesh(floorGeometry, floorMaterial) + + floorMesh.rotation.x = -Math.PI / 2 + floorMesh.position.y = -2 + + floor.add(floorMesh) + + return +} \ No newline at end of file diff --git a/front/src/components/3d/Marker.tsx b/front/src/components/3d/Marker.tsx new file mode 100644 index 0000000..893f4f1 --- /dev/null +++ b/front/src/components/3d/Marker.tsx @@ -0,0 +1,23 @@ +import React from 'react' +import { Group } from 'three' +import * as THREE from 'three' + +interface MarkerProps { + position: [number, number, number], + color: string, + onClick?: () => void +} + +export default function Marker({ position, color, onClick }: MarkerProps) { + + const [positionState, setPositionState] = React.useState(position) + + // Return the marker object + // return + return ( + setPositionState([positionState[0], positionState[1], positionState[2] + 0.1])} onPointerOut={(e) => setPositionState(position)}> + + + + ) +} diff --git a/front/src/components/3d/Ocean.tsx b/front/src/components/3d/Ocean.tsx new file mode 100644 index 0000000..6b9d8cf --- /dev/null +++ b/front/src/components/3d/Ocean.tsx @@ -0,0 +1,53 @@ +// src/components/Ocean.tsx +import React, { useEffect, useRef } from 'react'; +import * as THREE from 'three'; +import { Water, WaterOptions } from 'three/examples/jsm/objects/Water.js'; +import { WaterMesh, WaterMeshOptions } from 'three/examples/jsm/objects/Water2Mesh.js'; + +const Ocean: React.FC = () => { + + const waterGeometry = new THREE.PlaneGeometry(10000, 10000); + const waterOption:WaterOptions = { + textureWidth: 512, + textureHeight: 512, + waterNormals: new THREE.TextureLoader().load('https://threejs.org/examples/textures/waternormals.jpg', function (texture) { + texture.wrapS = texture.wrapT = THREE.RepeatWrapping; + }), + alpha: 0.9, + sunDirection: new THREE.Vector3(), + sunColor: 0xffffff, + waterColor: '#001e0f', + distortionScale: 3.7, + fog: true, + + + }; + const water = new Water(waterGeometry, waterOption); + water.rotation.x = -Math.PI / 2; + water.position.y = -1; + + + const waterRef = useRef(null); + useEffect(() => { + if (waterRef.current) { + waterRef.current.add(water); + } + }, [waterRef]); + + + useEffect(() => { + const animate = () => { + requestAnimationFrame(animate); + water.material.uniforms['time'].value += 0.1 / 60.0; + }; + animate(); + }, []); + + return ( + + + + ); +}; + +export default Ocean; diff --git a/front/src/components/ArticleCard.tsx b/front/src/components/ArticleCard.tsx new file mode 100644 index 0000000..8167cc6 --- /dev/null +++ b/front/src/components/ArticleCard.tsx @@ -0,0 +1,49 @@ +import { ArticlePreview } from '../types' +import ButtonLink from './ButtonLink' + +export default function ArticleCard({ articlePreview }: { articlePreview: ArticlePreview }) { + return ( +
+ Article preview +
+

{articlePreview.title}

+

{articlePreview.preview}

+
+
+
+ ) +} \ No newline at end of file diff --git a/front/src/components/ArticlesSection.tsx b/front/src/components/ArticlesSection.tsx new file mode 100644 index 0000000..d337fed --- /dev/null +++ b/front/src/components/ArticlesSection.tsx @@ -0,0 +1,83 @@ +import { useEffect, useState } from "react"; +import ArticleCard from "./ArticleCard"; +import { ArticlePreview } from "../types"; + +export default function ArticlesSection() { + + const [articlePreviews, setArticlePreviews] = useState([]); + const [loading, setLoading] = useState(true); + const [error, setError] = useState(null); + + + const articles: ArticlePreview[] = [ + { + id: 1, + title: "The Great Barrier Reef", + preview: "The Great Barrier Reef is the largest coral reef system in the world, composed of over 2,900 individual reefs and 900 islands stretching for over 2,300 kilometers (1,400 mi) over an area of approximately 344,400 square kilometers (133,000 sq mi).", + }, + { + id: 2, + title: "The Great Pacific Garbage Patch", + preview: "The Great Pacific Garbage Patch, also known as the Pacific trash vortex, is a gyre of marine debris particles in the north-central Pacific Ocean. It is located roughly from 135°W to 155°W and 35°N to 42°N.", + }, + { + id: 3, + title: "The Amazon Rainforest", + preview: "The Amazon rainforest, alternatively, the Amazon Jungle, also known in English as Amazonia, is a moist broadleaf tropical rainforest in the Amazon biome that covers most of the Amazon basin of South America.", + }, + { + id: 4, + title: "The Arctic", + preview: "The Arctic is a polar region located at the northernmost part of Earth. The Arctic consists of the Arctic Ocean, adjacent seas, and parts of Alaska (United States), Northern Canada (Canada), Finland, Greenland (Kingdom of Denmark), Iceland, Norway, Russia, and Sweden.", + }, + { + id: 5, + title: "The Antarctic", + preview: "The Antarctic, is a polar region containing the geographic South Pole and is situated in the Antarctic region of the Southern Hemisphere, almost entirely south of the Antarctic Circle, and is surrounded by the Southern Ocean.", + + } + ]; + + + useEffect(() => { + fetch('/api/articles') + // .then(response => response.json()) + .then(_ => articles) + .then((data: ArticlePreview[]) => setArticlePreviews(data)) + .catch(_ => setError('Failed to fetch articles')) + .finally(() => setLoading(false)); + }, []); + + return ( +
+

Articles

+
+ + {articlePreviews.map(articlePreview => ( + + ))} +
+ {!loading && !error && articlePreviews.length === 0 &&

No articles found

} + {loading &&

Loading...

} + {error &&

{error}

} +
+ ) +} diff --git a/front/src/components/Button.tsx b/front/src/components/Button.tsx new file mode 100644 index 0000000..3f548fd --- /dev/null +++ b/front/src/components/Button.tsx @@ -0,0 +1,36 @@ +import { ReactNode, MouseEventHandler } from 'react'; + +interface ButtonProps { + color: 'primary' | 'secondary'; + children: ReactNode; + url?: string; +} + +export default function Button({ color, children, url }: ButtonProps) { + return ( + {children} + ) +} + diff --git a/front/src/components/ButtonLink.tsx b/front/src/components/ButtonLink.tsx new file mode 100644 index 0000000..a8a4757 --- /dev/null +++ b/front/src/components/ButtonLink.tsx @@ -0,0 +1,34 @@ +interface ButtonLinkProps { + url: string; + color: 'primary' | 'secondary'; + text: string; +} + +export default function Button({ url, color, text }: ButtonLinkProps) { + return ( + {text} + ) +} + diff --git a/front/src/components/ClickableLink.tsx b/front/src/components/ClickableLink.tsx new file mode 100644 index 0000000..ee9f54c --- /dev/null +++ b/front/src/components/ClickableLink.tsx @@ -0,0 +1,31 @@ +interface ClickableLinkProps { + url:string; + text:string; +} + +export default function ClickableLink({url, text}: ClickableLinkProps) { + return (
+ +
) +} \ No newline at end of file diff --git a/front/src/components/Footer.tsx b/front/src/components/Footer.tsx new file mode 100644 index 0000000..f4b2bee --- /dev/null +++ b/front/src/components/Footer.tsx @@ -0,0 +1,21 @@ +import LogoButton from "./LogoButton" + +interface FooterProps { + bgcolor:string +} + +export default function Footer ({bgcolor}:FooterProps) { + return ( +
+

ENSIBS

RedCRAB

+

Made with ❤️ by RedCRAB

+
+ +
+
+ ) +} \ No newline at end of file diff --git a/front/src/components/FstSection.tsx b/front/src/components/FstSection.tsx new file mode 100644 index 0000000..67bec8f --- /dev/null +++ b/front/src/components/FstSection.tsx @@ -0,0 +1,40 @@ +import Button from "./Button"; +import ButtonLink from "./ButtonLink"; +import NavBar from "./NavBar"; + +export default function FstSection () { + return ( +
+ +
+
+

Help us to save our oceans


+
+
+
+ ) +} \ No newline at end of file diff --git a/front/src/components/LogoButton.tsx b/front/src/components/LogoButton.tsx new file mode 100644 index 0000000..bc41d3c --- /dev/null +++ b/front/src/components/LogoButton.tsx @@ -0,0 +1,13 @@ +import * as React from 'react'; + +interface LogoButtonProps { + url:string; + logo:string; + style?: React.CSSProperties; +} + +export default function LogoButton ({url, logo, style}: LogoButtonProps) { + return ( + + ) +} \ No newline at end of file diff --git a/front/src/components/Modal.tsx b/front/src/components/Modal.tsx new file mode 100644 index 0000000..083699f --- /dev/null +++ b/front/src/components/Modal.tsx @@ -0,0 +1,78 @@ +import React, { useState } from "react"; + +interface ModalProps { + state: "none" | "flex", + setState: (state: "none" | "flex") => void + question : { + question: string, + reponse_idx: number, + choix: string[] + }, + valides?: [boolean[], React.Dispatch>], + markerIndex?: number +} + +export default function Modal({ state, setState, question, valides, markerIndex }: ModalProps) { + const [isSuccess, setIsSuccess] = useState(false); + const [isSubmitted, setIsSubmitted] = useState(false); + console.log(state, setState, question) + return ( +
+
+ { + isSuccess ?

CONGRATULATIONS

: isSubmitted && !isSuccess &&

WRONG : CORRECT ANSWER IS {question.choix[question.reponse_idx]}

+ } +

{question.question}

+
+ { + question.choix.map((choix, index) => ( + + )) + } +
+ +
+
+
+ + )} \ No newline at end of file diff --git a/front/src/components/NavBar.tsx b/front/src/components/NavBar.tsx new file mode 100644 index 0000000..b5ebe21 --- /dev/null +++ b/front/src/components/NavBar.tsx @@ -0,0 +1,19 @@ +import LogoButton from '../components/LogoButton.tsx' +import ClickableLink from './ClickableLink.tsx'; +import RoundButton from './RoundButton.tsx'; + +export default function NavBar(){ + return ( + ); +} \ No newline at end of file diff --git a/front/src/components/RoundButton.tsx b/front/src/components/RoundButton.tsx new file mode 100644 index 0000000..6f08e45 --- /dev/null +++ b/front/src/components/RoundButton.tsx @@ -0,0 +1,35 @@ +interface RoundButtonProps { + url:string; + bgcolor:string; + text:string; +} + +export default function RoundButton({url, bgcolor, text}: RoundButtonProps) { + return (
+ +
) +} \ No newline at end of file diff --git a/front/src/index.css b/front/src/index.css new file mode 100644 index 0000000..328146f --- /dev/null +++ b/front/src/index.css @@ -0,0 +1,19 @@ +/* Define theme colors */ +:root { + --color-verydarkblue: #00204a; + --color-darkblue: #005792; + --color-lightblue: #00bbf0; + --color-yellow: #fdb44b; + --color-white: #ffffff; + --color-black: #000000; + --color-gray: #f5f5f5; + --color-red: #ff0000; +} + +body { + margin: 0; +} + +footer { + text-align: center; +} \ No newline at end of file diff --git a/front/src/main.tsx b/front/src/main.tsx index a7c672a..a9d0f99 100644 --- a/front/src/main.tsx +++ b/front/src/main.tsx @@ -4,13 +4,21 @@ import MainPage from "./pages/MainPage.tsx"; import GamePage from "./pages/GamePage.tsx"; import ChaosPage from "./pages/ChaosPage.tsx"; +import ArticlePage from "./pages/ArticlePage.tsx"; +import './index.css' createRoot(document.getElementById('root')!).render( + // Main page } /> + // Game page } /> } /> + // Article page (dynamic route) + } /> + // Not found + Not Found
} /> - , + ) diff --git a/front/src/pages/ArticlePage.tsx b/front/src/pages/ArticlePage.tsx new file mode 100644 index 0000000..3ab05f8 --- /dev/null +++ b/front/src/pages/ArticlePage.tsx @@ -0,0 +1,78 @@ +import React, { useEffect, useState } from 'react'; +import { useParams } from 'react-router-dom'; +import NavBar from '../components/NavBar'; +import Footer from '../components/Footer'; + +interface Article { + id: string; + title: string; + content: string; + author: string; + publishedAt: string; + editedAt: string; +} + +const ArticlePage: React.FC = () => { + const { id } = useParams<{ id: string }>(); + const [article, setArticle] = useState
(null); + const [loading, setLoading] = useState(true); + const [error, setError] = useState(null); + + useEffect(() => { + fetch(`/api/article/${id}`) + .then(response => response.json()) + .then(data => setArticle(data)) + .catch(_ => setError('Failed to fetch article')) + .finally(() => setLoading(false)); + }, [id]); + + if (loading) { + return
Loading...
; + } + + if (error) { + return
{error}
; + } + + if (!article) { + return
Article not found
; + } + + return ( +
+ +
+ Article preview +
+

{article.title}

+

écrit par {article.author} le {new Date(article.publishedAt).toLocaleDateString()} (Dernière modification le : {new Date(article.editedAt || article.publishedAt).toLocaleDateString()})

+
+

{article.content}

+
+
+
+
+ ); +}; + +export default ArticlePage; \ No newline at end of file diff --git a/front/src/pages/GamePage.tsx b/front/src/pages/GamePage.tsx index f984288..94e2221 100644 --- a/front/src/pages/GamePage.tsx +++ b/front/src/pages/GamePage.tsx @@ -1,9 +1,154 @@ +import { Canvas } from "@react-three/fiber"; +import { OrbitControls, PerspectiveCamera, Sky } from "@react-three/drei"; +import * as THREE from "three"; +import React, { useEffect, useRef, useState } from "react"; +import Ocean from "../components/3d/Ocean"; +import Axes from "../components/3d/Axes"; +import Character from "../components/3d/Character"; +import Floor from "../components/3d/Floor"; +import Marker from "../components/3d/Marker"; +import Modal from "../components/Modal"; +import { randInt } from "three/src/math/MathUtils.js"; + + + + + + + + + + export default function GamePage() { + const [stateModal, setStateModal] = useState("none" as "none" | "flex"); + const [questionIndex, setQuestionIndex] = useState(0); + + const QuestionList = [ + // Ensemble de questions sur la polution des océans + // {question:string, reponse_idx:int, choix:[string, string, string, string]} + { + question: "Quel est le plus grand océan du monde ?", + reponse_idx: 1, + choix: ["Océan Atlantique", "Océan Pacifique", "Océan Indien", "Océan Arctique"] + }, + { + question: "Comment s'appelle les continents de plastique dans les océans ?", + reponse_idx: 2, + choix: ["Plastico", "Plastiland", "Plastiques", "Plastiques"] + }, + { + question: "Quel est le nom de la grande masse d'eau salée qui recouvre la majorité de la surface de la Terre ?", + reponse_idx: 3, + choix: ["Mer", "Lac", "Océan", "Rivière"] + }, + { + question: "Quel est l'océan le plus froid ?", + reponse_idx: 0, + choix: ["Océan Arctique", "Océan Antarctique", "Océan Pacifique", "Océan Atlantique"] + }, + { + question: "Quel est l'océan le plus chaud ?", + reponse_idx: 1, + choix: ["Océan Arctique", "Océan Antarctique", "Océan Pacifique", "Océan Atlantique"] + }, + { + question: "Quel est l'océan le plus profond ?", + reponse_idx: 1, + choix: ["Océan Arctique", "Océan Antarctique", "Océan Pacifique", "Océan Atlantique"] + }, + { + question: "Quel est l'océan le plus grand ?", + reponse_idx: 2, + choix: ["Océan Arctique", "Océan Antarctique", "Océan Pacifique", "Océan Atlantique"] + } + ] + + + const [valides, setValides] = useState([false, false, false, false, false, false]); + const [markerIndex, setMarkerIndex] = useState(0); + + const askQuestion = (markerIndex: number) => { + setQuestionIndex(randInt(0, QuestionList.length - 1)); + setStateModal("flex"); + setMarkerIndex(markerIndex); + } + + const MakerList = [ + { position: [0, -0.1, 0], onClick: () => askQuestion(0) }, // body + { position: [-0.5, -0.1, 2.5], onClick: () => askQuestion(1) }, // left foot + { position: [0.5, -0.1, 2.5], onClick: () => askQuestion(2) }, // right foot + { position: [-1, -0.1, 1], onClick: () => askQuestion(3) }, // left hand + { position: [1, -0.1, 1], onClick: () => askQuestion(4) }, // right hand + { position: [0, -0.1, -1], onClick: () => askQuestion(5) }, // head + ] + + // Win condition + useEffect(() => { + if (valides.every(valide => valide)) { + + } + }, [valides]) + + + console.log(stateModal, setStateModal); return ( -
-

Game Page

+
+ { !valides.every(valide => valide) === true ? +

Hint : Répondez correctement aux questions pour sauver le personnage

+ :

Good Game : Bravo, vous avez sauvé le personnage

+ } + + + + + {/* */} + + + {/* */} + {MakerList.map((marker, index) => ( + + ))} + + +
) -} - +} \ No newline at end of file diff --git a/front/src/pages/MainPage.tsx b/front/src/pages/MainPage.tsx index 248feb2..78b1c56 100644 --- a/front/src/pages/MainPage.tsx +++ b/front/src/pages/MainPage.tsx @@ -1,10 +1,15 @@ - - +import ArticlesSection from '../components/ArticlesSection.tsx' +import Footer from '../components/Footer.tsx' +import FstSection from '../components/FstSection.tsx' export default function MainPage() { return ( -
-

Main Page

+ <> +
+ + +
+ ) } \ No newline at end of file diff --git a/front/src/types.ts b/front/src/types.ts new file mode 100644 index 0000000..b86ff18 --- /dev/null +++ b/front/src/types.ts @@ -0,0 +1,13 @@ +interface Article { + id: number; + title: string; + content: string; +} + +interface ArticlePreview { + id: number; + title: string; + preview: string; +} + +export type { Article, ArticlePreview }; \ No newline at end of file diff --git a/front/vite.config.ts b/front/vite.config.ts index 8b0f57b..795d340 100644 --- a/front/vite.config.ts +++ b/front/vite.config.ts @@ -4,4 +4,28 @@ import react from '@vitejs/plugin-react' // https://vite.dev/config/ export default defineConfig({ plugins: [react()], + server: { + proxy: { + '/api': { + target: 'http://127.0.0.1:2486', + changeOrigin: true, + secure: false, + ws: true, + /* + configure: (proxy, _options) => { + proxy.on('error', (err, _req, _res) => { + console.log('proxy error', err); + }); + proxy.on('proxyReq', (proxyReq, req, _res) => { + console.log('Sending Request to the Target:', req.method, req.url); + }); + proxy.on('proxyRes', (proxyRes, req, _res) => { + console.log('Received Response from the Target:', proxyRes.statusCode, req.url); + }); + }, + */ + //rewrite: path => path.replace(/^\/api/, '') + } + } + }, }) diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..e73376c --- /dev/null +++ b/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "projet-nuitinfo-2024", + "lockfileVersion": 3, + "requires": true, + "packages": {} +}