Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
Expand All @@ -18,7 +18,7 @@
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<noscript>You need to enable JavaScript to run this app 🎉.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
Expand Down
89 changes: 76 additions & 13 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,31 +1,94 @@
.App {
text-align: center;
body {
background: #f8fafc;
margin: 0;
font-family: "Segoe UI", "Roboto", "Arial", sans-serif;
}

.App-logo {
height: 40vmin;
pointer-events: none;
.App {
text-align: center;
}

.App-header {
background-color: #282c34;
background: #f8fafc;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
justify-content: flex-start;
font-size: calc(10px + 2vmin);
color: white;
color: #3a3a3a;
padding-top: 40px;
}

.App-link {
color: #61dafb;
h1 {
color: #355c7d;
margin-bottom: 24px;
font-weight: 700;
letter-spacing: 1px;
text-shadow: 0 2px 8px #e3ecfa;
}

.heart {
color: #ff0000;
form input[type="text"] {
padding: 10px;
border: 1px solid #e0e7ef;
border-radius: 8px;
background: #f0f4ff;
color: #3a3a3a;
font-size: 1rem;
outline: none;
transition: border 0.2s;
}
form input[type="text"]:focus {
border: 1.5px solid #a5b4fc;
background: #e0e7ef;
}
form button {
background: linear-gradient(90deg, #a5b4fc 0%, #fbc2eb 100%);
color: #3a3a3a;
border: none;
border-radius: 8px;
padding: 10px 18px;
font-size: 1rem;
margin-left: 8px;
cursor: pointer;
transition: background 0.2s;
}
form button:hover {
background: linear-gradient(90deg, #fbc2eb 0%, #a5b4fc 100%);
}

ul {
list-style: none;
padding: 0;
}
li {
background: linear-gradient(135deg, #e3ecfa 0%, #b6c6e6 100%);
border-radius: 14px;
margin-bottom: 20px;
padding: 22px 28px 16px 28px;
box-shadow: 0 4px 16px rgba(120, 140, 180, 0.1);
text-align: left;
border: 1.5px solid #d0d8e8;
}
li a {
color: #355c7d;
text-decoration: none;
font-size: 1.18rem;
font-weight: 600;
letter-spacing: 0.5px;
transition: color 0.2s;
}
li a:hover {
color: #2a4365;
text-decoration: underline;
}
.App-link {
color: #7f9cf5;
}
.heart {
color: #fbb6ce;
}
.small {
font-size: 0.75rem;
}
color: #a0aec0;
}
74 changes: 56 additions & 18 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,64 @@
import './App.css';
import React, { useState } from "react";
import "./App.css";

function App() {
const [query, setQuery] = useState("");
const [results, setResults] = useState([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState(null);

const handleSearch = async (e) => {
e.preventDefault();
if (!query.trim()) return;
setLoading(true);
setError(null);
setResults([]);
try {
const response = await fetch(
`https://fr.wikipedia.org/w/api.php?action=query&list=search&format=json&origin=*&srsearch=${encodeURIComponent(query)}`,
);
const data = await response.json();
setResults(data.query?.search || []);
} catch (err) {
setError("Erreur lors de la recherche Wikipedia.");
} finally {
setLoading(false);
}
};

return (
<div className="App">
<header className="App-header">
<img src="Octocat.png" className="App-logo" alt="logo" />
<p>
GitHub Codespaces <span className="heart">♥️</span> React
</p>
<p className="small">
Edit <code>src/App.jsx</code> and save to reload.
</p>
<p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</p>
<h1>Recherche Wikipedia</h1>
<form onSubmit={handleSearch} style={{ marginBottom: 20 }}>
<input
type="text"
value={query}
onChange={(e) => setQuery(e.target.value)}
placeholder="Rechercher sur Wikipedia..."
style={{ padding: 8, width: 250 }}
/>
<button type="submit" style={{ marginLeft: 8, padding: 8 }}>
Chercher
</button>
</form>
{loading && <p>Recherche en cours...</p>}
{error && <p style={{ color: "red" }}>{error}</p>}
<ul style={{ textAlign: "left", maxWidth: 600, margin: "0 auto" }}>
{results.map((item) => (
<li key={item.pageid} style={{ marginBottom: 12 }}>
<a
href={`https://fr.wikipedia.org/?curid=${item.pageid}`}
target="_blank"
rel="noopener noreferrer"
style={{ color: "#61dafb", fontWeight: "bold" }}
>
{item.title}
</a>
<div dangerouslySetInnerHTML={{ __html: item.snippet + "..." }} />
</li>
))}
</ul>
</header>
</div>
);
Expand Down