diff --git a/back/src/create_db.rs b/back/src/create_db.rs index 21cb84a..67eb2af 100644 --- a/back/src/create_db.rs +++ b/back/src/create_db.rs @@ -12,9 +12,7 @@ pub fn init() -> sqlite::Result<()> { "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'), + subTitle TEXT, content TEXT NOT NULL )", )?; diff --git a/back/src/main.rs b/back/src/main.rs index 23d9fc0..c7312e9 100644 --- a/back/src/main.rs +++ b/back/src/main.rs @@ -1,7 +1,7 @@ mod create_db; use create_db::init; -use actix_web::{App, web, HttpServer, get, Responder, HttpResponse, http::header::ContentType}; +use actix_web::{App, HttpServer, get, Responder, HttpResponse, http::header::ContentType}; use actix_files::Files; use serde_json::json; use sqlite::{Connection, State}; @@ -11,9 +11,9 @@ use serde::{Serialize, Deserialize}; struct Article { id: i64, title: String, - auteur: String, - edited_at: String, - published_at: String, + auteur: Option, + edited_at: Option, + published_at: Option, content: String, } @@ -31,13 +31,13 @@ async fn get_articles() -> impl Responder { 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(); + let content = stmt.read::(3).unwrap(); articles.push(Article { id, title, - auteur: "".to_string(), - edited_at: "".to_string(), - published_at: "".to_string(), + auteur: None, + edited_at: None, + published_at: None, content }); } @@ -45,54 +45,6 @@ async fn get_articles() -> impl Responder { 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!({ @@ -120,7 +72,6 @@ async fn main() -> Result<(), std::io::Error> { .service(hello) .service(get_articles) .service(api) - .service(get_article) .service(Files::new("/", "public").index_file("index.html")) .service(Files::new("/game", "public").index_file("index.html")) .service(Files::new("/chaos", "public").index_file("index.html")) diff --git a/front/index.html b/front/index.html index 48914fe..e4b78ea 100644 --- a/front/index.html +++ b/front/index.html @@ -4,8 +4,7 @@ - EcoMarin - + Vite + React + TS
diff --git a/front/package.json b/front/package.json index 7e85ec8..e1132b0 100644 --- a/front/package.json +++ b/front/package.json @@ -10,14 +10,9 @@ "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", - "three": "^0.171.0", - "three-stdlib": "^2.34.0", "react-router-dom": "^6.2.1" }, "devDependencies": { diff --git a/front/public/models/man.glb b/front/public/models/man.glb deleted file mode 100644 index abd24f6..0000000 Binary files a/front/public/models/man.glb and /dev/null differ diff --git a/front/src/components/3d/Axes.tsx b/front/src/components/3d/Axes.tsx deleted file mode 100644 index 29e489a..0000000 --- a/front/src/components/3d/Axes.tsx +++ /dev/null @@ -1,29 +0,0 @@ -import { LineBasicMaterial, Line, Group } from 'three' -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 deleted file mode 100644 index 272f3c3..0000000 --- a/front/src/components/3d/Character.tsx +++ /dev/null @@ -1,24 +0,0 @@ -import { useGLTF } from '@react-three/drei' - -export default function Character() { - // import glb file - - // load the glb file in "/models/BASEmodel.glb" - const { 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 deleted file mode 100644 index 7a24e3f..0000000 --- a/front/src/components/3d/Floor.tsx +++ /dev/null @@ -1,18 +0,0 @@ -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 deleted file mode 100644 index 61419d9..0000000 --- a/front/src/components/3d/Marker.tsx +++ /dev/null @@ -1,22 +0,0 @@ -import React from 'react' -import * as THREE from 'three' - -interface MarkerProps { - position: number[], - color: string, - onClick?: () => void -} - -export default function Marker({ position, color, onClick }: MarkerProps) { - - const [positionState, setPositionState] = React.useState(new THREE.Vector3(...position)) - - // Return the marker object - // return - return ( - setPositionState(positionState.clone().setZ(positionState.z + 0.1))} onPointerOut={() => setPositionState(new THREE.Vector3(...position))}> - - - - ) -} diff --git a/front/src/components/3d/Ocean.tsx b/front/src/components/3d/Ocean.tsx deleted file mode 100644 index 0808e50..0000000 --- a/front/src/components/3d/Ocean.tsx +++ /dev/null @@ -1,52 +0,0 @@ -// 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'; - -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 index 8167cc6..6a02bb3 100644 --- a/front/src/components/ArticleCard.tsx +++ b/front/src/components/ArticleCard.tsx @@ -13,7 +13,7 @@ export default function ArticleCard({ articlePreview }: { articlePreview: Articl margin: '20px', padding: '1.25em', paddingBottom: '1em', - flex: '0 1 30%', + flex: '27%', textAlign: 'left', }}> Article preview(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(response => response.json()) .then((data: ArticlePreview[]) => setArticlePreviews(data)) .catch(_ => setError('Failed to fetch articles')) .finally(() => setLoading(false)); }, []); return ( -
Articles -
- - {articlePreviews.map(articlePreview => ( - - ))} -
+ {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 index db4b4ad..654bda5 100644 --- a/front/src/components/Button.tsx +++ b/front/src/components/Button.tsx @@ -1,14 +1,14 @@ -import { ReactNode } from 'react'; +import { ReactNode, MouseEventHandler } from 'react'; interface ButtonProps { + onClick: MouseEventHandler; color: 'primary' | 'secondary'; children: ReactNode; - url?: string; } -export default function Button({ color, children, url }: ButtonProps) { +export default function Button({ onClick, color, children }: ButtonProps) { return ( - {children} + }} onClick={onClick} className="ni-button" role="button">{children} ) } diff --git a/front/src/components/ClickableLink.tsx b/front/src/components/ClickableLink.tsx index ee9f54c..0096871 100644 --- a/front/src/components/ClickableLink.tsx +++ b/front/src/components/ClickableLink.tsx @@ -9,7 +9,7 @@ export default function ClickableLink({url, text}: ClickableLinkProps) { backgroundColor: "transparent", borderRadius: '8px', borderWidth: '0', - color:"white", + color:"purple", cursor: 'pointer', display: 'inline-block', fontFamily: '"Haas Grot Text R Web", "Helvetica Neue", Helvetica, Arial, sans-serif', diff --git a/front/src/components/Footer.tsx b/front/src/components/Footer.tsx index f4b2bee..468812c 100644 --- a/front/src/components/Footer.tsx +++ b/front/src/components/Footer.tsx @@ -7,14 +7,12 @@ interface FooterProps { export default function Footer ({bgcolor}:FooterProps) { return (
-

ENSIBS

RedCRAB

-

Made with ❤️ by RedCRAB

-
+
ENSIBS
RedCRAB
+
+ style={{ width: "50%", height: "auto" }}/>
) diff --git a/front/src/components/FstSection.tsx b/front/src/components/FstSection.tsx index 7cf827b..a978737 100644 --- a/front/src/components/FstSection.tsx +++ b/front/src/components/FstSection.tsx @@ -1,13 +1,19 @@ - +import Button from "./Button"; import NavBar from "./NavBar"; -import { Link } from "react-router"; -export default function FstSection () { +interface FstSectionProps { + centertxt: string; + txtbt1:string; + txtbt2:string; + image:string; +} + +export default function FstSection ({centertxt, txtbt1, txtbt2, image}: FstSectionProps) { return (
-

Help us to save our oceans


+

{centertxt}


- {/*
) diff --git a/front/src/components/Modal.tsx b/front/src/components/Modal.tsx deleted file mode 100644 index 083699f..0000000 --- a/front/src/components/Modal.tsx +++ /dev/null @@ -1,78 +0,0 @@ -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 index d6f6c87..4f1c35d 100644 --- a/front/src/components/NavBar.tsx +++ b/front/src/components/NavBar.tsx @@ -1,20 +1,17 @@ -import { Link } from 'react-router'; +import LogoButton from '../components/LogoButton.tsx' +import ClickableLink from './ClickableLink.tsx'; import RoundButton from './RoundButton.tsx'; export default function NavBar(){ return ( -