-
Notifications
You must be signed in to change notification settings - Fork 0
Fin de la session 1 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: session-1-v3
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { APIGatewayProxyHandler } from 'aws-lambda'; | ||
|
|
||
| import { success } from '@libs/response'; | ||
|
|
||
| export const main: APIGatewayProxyHandler = async event => { | ||
| console.log(event); | ||
| return success({}); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { APIGatewayProxyHandler } from 'aws-lambda'; | ||
| import uuid from 'uuid'; | ||
|
|
||
| import { success } from '@libs/response'; | ||
|
|
||
|
|
||
| export const main: APIGatewayProxyHandler = async (event) => { | ||
| /* | ||
| La fonction doit générer 1 virus si un id est passé en query param | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. de base les commentaires, c'est pas ouf, mieux vaut les retirer. |
||
| Sinon elle en génère 4 | ||
| */ | ||
| let viruses = [{}] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. initialise le seulement avec une liste vide non ? |
||
| if (event.queryStringParameters) { | ||
| if (event.queryStringParameters.id) { | ||
| viruses = [ | ||
| { id: uuid() }, | ||
| ]; | ||
| } else { | ||
| viruses = [ | ||
| { id: uuid() }, | ||
| { id: uuid() }, | ||
| { id: uuid() }, | ||
| { id: uuid() } | ||
| ]; | ||
| } | ||
| } | ||
|
|
||
| return success({ viruses }); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ import { Typography, Row, Button } from 'antd'; | |
| import { PlusOutlined } from '@ant-design/icons'; | ||
| import styled from 'styled-components'; | ||
| import { v4 } from 'uuid'; | ||
|
|
||
| import { useAsync } from 'react-use'; | ||
| import virus1 from 'assets/Virus1.png'; | ||
| import virus2 from 'assets/Virus2.png'; | ||
| import virus3 from 'assets/Virus3.png'; | ||
|
|
@@ -51,22 +51,27 @@ const Virus = styled.img<VirusProps>` | |
|
|
||
| const getRandomPosition = (n: number) => Math.floor(Math.random() * n); | ||
|
|
||
| const getRandomVirus = () => ({ | ||
| id: v4(), | ||
| const getRandomVirus = (id: string) => ({ | ||
| id, | ||
| positionX: getRandomPosition(100), | ||
| positionY: getRandomPosition(100), | ||
| src: VirusImgs[getRandomPosition(6)], | ||
| }); | ||
|
|
||
| export default () => { | ||
| const [viruses, setViruses] = useState<VirusProps[]>([ | ||
| getRandomVirus(), | ||
| getRandomVirus(), | ||
| getRandomVirus(), | ||
| ]); | ||
| const [viruses, setViruses] = useState<VirusProps[]>([]); | ||
|
|
||
| useAsync(async (id = 'TEST') => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. faudra qu'on reparle ensemble en live de tout ça :) j'ai besoin d'un peu de contexte |
||
| const response = await fetch( | ||
| `${process.env.REACT_APP_API_BASE_URL}/virus?id=${encodeURIComponent(id)}`, | ||
| { method: 'GET' }, | ||
| ); | ||
| const { viruses } = await response.json(); | ||
| setViruses(viruses.map(({ id }: { id: string }) => getRandomVirus(id))); | ||
|
|
||
| }); | ||
| const addVirus = () => | ||
| setViruses((prevViruses) => prevViruses.concat(getRandomVirus())); | ||
| setViruses((prevViruses) => prevViruses.concat(getRandomVirus(v4()))); | ||
|
|
||
| const killVirus = (virusId: string) => | ||
| setViruses((prevViruses) => prevViruses.filter(({ id }) => id !== virusId)); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tu peux retirer le console.log