diff --git a/back/Cargo.toml b/back/Cargo.toml index 7df2455..6be9ee0 100644 --- a/back/Cargo.toml +++ b/back/Cargo.toml @@ -9,6 +9,4 @@ actix-web = "4" sqlite = "0.36.1" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0.133" -rss = "2.0.11" -reqwest = "0.12.9" diff --git a/back/src/create_db.rs b/back/src/create_db.rs index f36e5ee..21cb84a 100644 --- a/back/src/create_db.rs +++ b/back/src/create_db.rs @@ -1,6 +1,4 @@ use sqlite::{Connection, OpenFlags}; -use rss::{Channel, Item}; -use reqwest; pub fn init() -> sqlite::Result<()> { let conn = Connection::open_with_flags( @@ -23,18 +21,3 @@ pub fn init() -> sqlite::Result<()> { Ok(()) } - -pub async fn update_articles( channel: &Channel) { - let conn = Connection::open_with_flags( - "./data/data.db", - OpenFlags::new() - .with_create() - .with_read_write() - ); - - let flux_rss = reqwest::get("https://www.lemonde.fr/rss/une.xml") - .await - .unwrap(); - - let channel = Channel::read_from(&flux_rss[..]); -} diff --git a/back/src/main.rs b/back/src/main.rs index 141544d..23d9fc0 100644 --- a/back/src/main.rs +++ b/back/src/main.rs @@ -122,6 +122,8 @@ async fn main() -> Result<(), std::io::Error> { .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")) }) .bind(("0.0.0.0", 2486))? .run() diff --git a/docker-compose.yml b/docker-compose.yml index 1e0df8d..f689f10 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,10 +3,22 @@ services: build: context: . dockerfile: dockerfile - container_name: web + network: host + container_name: nuitdelinfo restart: always - ports: - - 8080:8080 volumes: - ./back/data:/app/data + networks: + - traefik + labels: + - "traefik.enable=true" + - "traefik.http.routers.nuitdelinfo.rule=Host(`nuitdelinfo.leizour.fr`)" + - "traefik.http.routers.nuitdelinfo.entrypoints=websecure" + - "traefik.http.routers.nuitdelinfo.tls=true" + - "traefik.http.routers.nuitdelinfo.tls.certresolver=myresolver" + - "traefik.http.services.nuitdelinfo.loadbalancer.server.port=2486" + +networks: + traefik: + external: true 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 32aba92..7e85ec8 100644 --- a/front/package.json +++ b/front/package.json @@ -17,7 +17,8 @@ "react-dom": "^18.3.1", "react-router": "^7.0.2", "three": "^0.171.0", - "three-stdlib": "^2.34.0" + "three-stdlib": "^2.34.0", + "react-router-dom": "^6.2.1" }, "devDependencies": { "@eslint/js": "^9.15.0", @@ -30,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/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 index 195e266..29e489a 100644 --- a/front/src/components/3d/Axes.tsx +++ b/front/src/components/3d/Axes.tsx @@ -1,6 +1,4 @@ -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() { diff --git a/front/src/components/3d/Character.tsx b/front/src/components/3d/Character.tsx index f6d7d66..272f3c3 100644 --- a/front/src/components/3d/Character.tsx +++ b/front/src/components/3d/Character.tsx @@ -1,11 +1,10 @@ -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') + const { scene } = useGLTF('/models/man.glb') // rotate the character scene.rotation.x = -Math.PI / 2 diff --git a/front/src/components/3d/Floor.tsx b/front/src/components/3d/Floor.tsx index dbb054b..7a24e3f 100644 --- a/front/src/components/3d/Floor.tsx +++ b/front/src/components/3d/Floor.tsx @@ -1,5 +1,3 @@ - -import React from 'react' import { Group } from 'three' import * as THREE from 'three' diff --git a/front/src/components/3d/Marker.tsx b/front/src/components/3d/Marker.tsx index 893f4f1..61419d9 100644 --- a/front/src/components/3d/Marker.tsx +++ b/front/src/components/3d/Marker.tsx @@ -1,23 +1,22 @@ import React from 'react' -import { Group } from 'three' import * as THREE from 'three' interface MarkerProps { - position: [number, number, number], + position: number[], color: string, onClick?: () => void } export default function Marker({ position, color, onClick }: MarkerProps) { - const [positionState, setPositionState] = React.useState(position) + const [positionState, setPositionState] = React.useState(new THREE.Vector3(...position)) // Return the marker object // return return ( - setPositionState([positionState[0], positionState[1], positionState[2] + 0.1])} onPointerOut={(e) => setPositionState(position)}> + 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 index 6b9d8cf..0808e50 100644 --- a/front/src/components/3d/Ocean.tsx +++ b/front/src/components/3d/Ocean.tsx @@ -2,7 +2,6 @@ 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 = () => { 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..db4b4ad --- /dev/null +++ b/front/src/components/Button.tsx @@ -0,0 +1,36 @@ +import { ReactNode } 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..7cf827b --- /dev/null +++ b/front/src/components/FstSection.tsx @@ -0,0 +1,87 @@ + +import NavBar from "./NavBar"; +import { Link } from "react-router"; + +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/NavBar.tsx b/front/src/components/NavBar.tsx new file mode 100644 index 0000000..d6f6c87 --- /dev/null +++ b/front/src/components/NavBar.tsx @@ -0,0 +1,20 @@ +import { Link } from 'react-router'; +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/components/chaos/MonInput.tsx b/front/src/components/chaos/MonInput.tsx new file mode 100644 index 0000000..ae96388 --- /dev/null +++ b/front/src/components/chaos/MonInput.tsx @@ -0,0 +1,16 @@ +//import { useState } from "react"; + +interface MonInputProps { + text: string; + new_focus: () => void; + police: string; +} + +export default function MonInput({text, new_focus, police}: MonInputProps) { + + return ( +
+ +
+ ) +} \ No newline at end of file diff --git a/front/src/components/chaos/monButton.tsx b/front/src/components/chaos/monButton.tsx new file mode 100644 index 0000000..e06033f --- /dev/null +++ b/front/src/components/chaos/monButton.tsx @@ -0,0 +1,26 @@ + +interface MonButtonProps { + letter: string; + changetext: (arg0: string) => void; + sizeFrontw: number; + sizeFronth: number; + rdmFront: () => void; + color: string; +} + + +export default function MonButton({letter,changetext,sizeFrontw,sizeFronth,rdmFront,color}: MonButtonProps) { + + + + function clicked() {rdmFront(); + changetext(letter)} + + + + return ( +
+ +
+ ) +} \ No newline at end of file diff --git a/front/src/components/chaos/style.css b/front/src/components/chaos/style.css new file mode 100644 index 0000000..f0fbe2d --- /dev/null +++ b/front/src/components/chaos/style.css @@ -0,0 +1,12 @@ + +#keys { + display: grid; + grid-template-columns: auto auto 1fr; + + +} + +.key { + font-size: 10px; + border: solid black; +} \ 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 ce00332..a9d0f99 100644 --- a/front/src/main.tsx +++ b/front/src/main.tsx @@ -2,13 +2,23 @@ import { BrowserRouter, Route, Routes } from "react-router"; import { createRoot } from 'react-dom/client' 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/ChaosPage.tsx b/front/src/pages/ChaosPage.tsx new file mode 100644 index 0000000..9efc84b --- /dev/null +++ b/front/src/pages/ChaosPage.tsx @@ -0,0 +1,86 @@ +import MonButton from "../components/chaos/monButton"; +import MonInput from "../components/chaos/MonInput"; +import "../components/chaos/style.css" +import { useState } from "react"; + + +export default function ChaosPage(){ + + const [array_letter,setArray_letter]=useState(["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"," ","!"]); + + const [sizeFrontw,setSizeFrontw] = useState(16) + const [sizeFronth,setSizeFronth] = useState(20) + const [color,setColor] = useState("#ffffff") + + function randomFront(){setSizeFronth(Math.floor(Math.random() * (1000))); + setSizeFrontw(Math.floor(Math.random() * (1000))); + setColor(`#${Math.floor(Math.random() * 16777215).toString(16)}`)} + + function shuffleArray(arr: string[]) { + for (let i = arr.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); // Choisir un index aléatoire + [arr[i], arr[j]] = [arr[j], arr[i]]; // Échanger les éléments + } + return arr; + } + + + // console.log(shuffledArray); // Affiche un tableau mélangé + + + const [entry1,setEntry1] = useState("") + function E1(ent:string) { + setEntry1(entry1+ent); + } + const [connarddefocus,setFocus] = useState(()=>E1) + + const [entry2,setEntry2] = useState("") + function E2(ent:string) { + setEntry2(entry2+ent); + } + + function changeFocus(E: (ent:string)=>void) { + setArray_letter(shuffleArray(array_letter)); + setFocus(()=>E); + } + + const [entry3,setEntry3] = useState("") + function E3(ent:string) { + setEntry3(entry3+ent); + } + + const [tel,setTel] = useState(0) + + + return( +
+

Chaos Page

+

Quel est votre nom ?

+ changeFocus(E1)} police={""}/> +

Quel adjectif désigne le mieux Xi Junpin ?

+ changeFocus(E2)} police={""}/> +

Combien font 1+1 ?

+ changeFocus(E3)} police={"Wingdings"}/> +
+ {array_letter.map((letter) => {return })} +
+
+ Formulaire super mega bien + + + + + + + setTel(parseInt(e.target.value))}/> + +
+
+ ) +} \ No newline at end of file diff --git a/front/src/pages/GamePage.tsx b/front/src/pages/GamePage.tsx index 69552df..4ebcb50 100644 --- a/front/src/pages/GamePage.tsx +++ b/front/src/pages/GamePage.tsx @@ -1,9 +1,7 @@ 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 { useEffect, 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"; @@ -139,7 +137,7 @@ export default function GamePage() { - + {/* */} {/* */} 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": {} +}