Skip to content
Snippets Groups Projects
Commit e68f15cb authored by Vincent Seyller's avatar Vincent Seyller
Browse files

TP2 working

parent 73ac2f91
No related merge requests found
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/tp/node_modules
/tp/.pnp
/tp/.pnp.js
# testing
/tp/coverage
# production
/tp/build
# misc
/tp/.DS_Store
/tp/.env.local
/tp/.env.development.local
/tp/.env.test.local
/tp/.env.production.local
/tp/npm-debug.log*
/tp/yarn-debug.log*
/tp/yarn-error.log*
[1119/085339.898:ERROR:directory_reader_win.cc(43)] FindFirstFile: Le chemin daccs spcifi est introuvable. (0x3)
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"name": "tp",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.5",
"@testing-library/react": "^11.1.2",
"@testing-library/user-event": "^12.2.2",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.0",
"web-vitals": "^0.2.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
tp/public/favicon.ico

3.78 KiB

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="Web site created using create-react-app" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>LP2 Seyller Vincent</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
\ No newline at end of file
{
"short_name": "LP2 SV",
"name": "LP2 Seyller Vincent",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
\ No newline at end of file
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
.App-logo {
height: 40vmin;
pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}
.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}
.App-link {
color: #61dafb;
}
@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
button {
margin-left: 0.2rem;
margin-right: 0.2rem;
}
// import { useState } from 'react';
import './App.css';
// import TodoList from './TodoList'
import SW from './SW'
// let Toggle = () => {
// let [currentValue, setCurrentValue] = useState(false);
// let handleClick = () => {
// // Ne pas utiliser setCurrentValue(!currentValue)
// setCurrentValue(current => !current);
// };
// return <p>
// Toggle value : {currentValue ? 'true ' : 'false '}
// <button onClick={handleClick}>
// Change
// </button>
// </p >;
// };
// let Counter = () => {
// let [counter, setCounter] = useState(0);
// let handleClick = () => {
// setCounter(current => current + 1);
// };
// return <p>
// Value : {counter}
// <button onClick={handleClick}>+</button>
// <button onClick={() => setCounter(0)}>Reset</button>
// </p>;
// };
let App = () => {
return (
<div className="App">
{/* <Toggle />
<Toggle />
<Toggle />
<Toggle />
<Counter />
<TodoList /> */}
<SW />
</div>
);
};
export default App;
import { render, screen } from '@testing-library/react';
import App from './App';
test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});
import { useState, useEffect } from "react";
// <button onClick={loadData(people.next)}>Next</button>
let SW = () => {
let [people, setPeople] = useState(null);
let [loading, setLoading] = useState(false);
let [details, setDetails] = useState(null);
let loadData = (data) => {
setLoading(true);
fetch(data)
.then(res => res.json())
.then(data => {
setPeople(data);
setLoading(false);
});
}
useEffect(() => {
loadData('https://swapi.dev/api/people/');
}, []);
useEffect(() => {
setDetails(null);
}, []);
return <div>
<h3>Star Wars</h3>
<p></p>
{loading ? "Loading..." : people &&
[
people.previous ? <button key={"previous"} onClick={() => loadData(people.previous)}>Previous</button> : "",
people.next ? <button key={"next"} onClick={() => loadData(people.next)}>Next</button> : "",
<ul key={"people"}>
{people.results.map((p, idx) => {
return <li key={idx}>
{p.name}
<button onClick={() => setDetails(p)}>Details</button>
</li>
})}
</ul>
]
}
<h4>Details</h4>
{details ?
<ul>
<li key={"name"}>Name : {details.name}</li>
<li key={"heigt"}>Height : {details.height}</li>
<li key={"mass"}>Mass : {details.mass}</li>
<li key={"hair_color"}>Hair color : {details.hair_color}</li>
<li key={"skin_color"}>Skin color : {details.skin_color}</li>
<li key={"eye_color"}>Eye color : {details.eye_color}</li>
<li key={"birth_year"}>Birth year : {details.birth_year}</li>
<li key={"gender"}>Gender : {details.gender}</li>
<li key={"films"}>Films :
<ul key={"films-list"}>
{details.films.map((f, idx) => {
return <li key={"film" + idx}><a href={f}>{f}</a></li>
})}
</ul>
</li>
</ul> : "None selected"}
</div>
}
export default SW;
\ No newline at end of file
import useState from "react";
import useLocalState from "./localState"
let TodoList = () => {
let [items, setItems] = useLocalState('items', [
{ text: "Item 1", done: true },
{ text: "Item 2", done: false },
]);
let [text, setText] = useState('');
let addItem = text => {
if (text != "") setItems(current => [{ text, done: false }, ...current]);
};
let removeItem = item => {
setItems(current => current.filter(x => x !== item));
};
let updateItem = (item/* , changes */) => {
setItems(current => current.map(x => {
return x === item ? { ...x, done: !x.done } : x;
// return x === item ? { ...x, ...changes };
}));
}
let handleChange = e => {
setText(e.target.value);
};
let handleSubmit = e => {
e.preventDefault();
addItem(text);
setText('');
};
return <div>
<h3>TodoList</h3>
<form onSubmit={handleSubmit}>
<input type="text" value={text} onChange={handleChange} />
<button>Add</button>
</form>
<ul>
{items.map((i, idx) => {
return <li key={idx}>
{i.done ? <strike>{i.text}</strike> : i.text}
<button onClick={() => removeItem(i)}>Remove</button>
<input type="checkbox" checked={i.done} onChange={() => updateItem(i)}></input>
</li>
})}
</ul>
</div>
}
export default TodoList;
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
import { useState, useEffect } from "react";
let useLocalState = (key, initialValue) => {
// Initialise la liste d'états
let [state, setStates] = useState(initialValue);
// L'ordre des useEffect est important
// useEffect sans comparaison fait forcément la fonction qui est changée au démarrage
// TodoList est evalué une première fois avant que les effects soient executés
useEffect(() => {
let state = localStorage.getItem(key);
if (state) setStates(JSON.parse(state));
}, []);
// Si states change, alors j'exécute la function
useEffect(() => {
localStorage.setItem(key, JSON.stringify(state));
}, [state]);
return [state, setStates];
}
export default useLocalState;
const reportWebVitals = onPerfEntry => {
if (onPerfEntry && onPerfEntry instanceof Function) {
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
getCLS(onPerfEntry);
getFID(onPerfEntry);
getFCP(onPerfEntry);
getLCP(onPerfEntry);
getTTFB(onPerfEntry);
});
}
};
export default reportWebVitals;
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment