diff --git a/frontend/components/FunctionCard/FunctionCard.css b/frontend/components/FunctionCard/FunctionCard.css index 63c6d9d..939fb21 100644 --- a/frontend/components/FunctionCard/FunctionCard.css +++ b/frontend/components/FunctionCard/FunctionCard.css @@ -27,6 +27,9 @@ } } +.FunctionCard__image { + width: 150px; +} .FunctionCard__title { font-size: 1.4em; margin: 0; diff --git a/frontend/config/api.js b/frontend/config/api.js new file mode 100644 index 0000000..81b78c3 --- /dev/null +++ b/frontend/config/api.js @@ -0,0 +1,11 @@ +import axios from 'axios'; +import { API_URL } from './config'; + +const api = axios.create({ + baseURL: API_URL, + headers: { + 'Content-Type': 'application/json' + } +}); + +export default api; \ No newline at end of file diff --git a/frontend/config/config.js b/frontend/config/config.js new file mode 100644 index 0000000..f334f3c --- /dev/null +++ b/frontend/config/config.js @@ -0,0 +1 @@ +export const API_URL = "http://localhost:8080"; \ No newline at end of file diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 775e687..225a12e 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -1796,6 +1796,37 @@ "postcss-value-parser": "^4.0.2" } }, + "axios": { + "version": "0.19.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.19.2.tgz", + "integrity": "sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==", + "requires": { + "follow-redirects": "1.5.10" + }, + "dependencies": { + "debug": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", + "requires": { + "ms": "2.0.0" + } + }, + "follow-redirects": { + "version": "1.5.10", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz", + "integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==", + "requires": { + "debug": "=3.1.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + } + } + }, "babel-code-frame": { "version": "6.26.0", "resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz", diff --git a/frontend/package.json b/frontend/package.json index 4f962ae..b2f8f14 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -9,6 +9,7 @@ }, "dependencies": { "@zeit/next-css": "^1.0.1", + "axios": "^0.19.2", "next": "9.3.1", "next-fonts": "^1.0.3", "react": "16.13.0", diff --git a/frontend/pages/functions.js b/frontend/pages/functions.js index 324adb7..c8654c2 100644 --- a/frontend/pages/functions.js +++ b/frontend/pages/functions.js @@ -1,48 +1,86 @@ -import { Fragment } from 'react'; +import { Fragment, useState, useEffect } from 'react'; import HeadTag from '../components/HeadTag'; import FunctionCard from '../components/FunctionCard/FunctionCard'; import '../public/css/pages/functions.css'; +import { API_URL } from '../config/config'; +import api from '../config/api'; -const Functions = () => ( - - +const Functions = () => { + + const [categories, setCategories] = useState([]); + + const [functions, setFunctions] = useState([]); + const [isLoadingFunctions, setLoadingFunctions] = useState(true); + const [pageFunctions, setPageFunctions] = useState(1); + const [hasMoreFunctions, sethasMoreFunctions] = useState(false); + + // Récupère les catégories + useEffect(() => { + api.get('/categories') + .then((result) => { + setCategories(result.data); + }) + .catch((error) => console.error(error)); + }, []); -
+ // Récupère les fonctions + useEffect(() => { + api.get(`/functions?page=${pageFunctions}&limit=10`) + .then((result) => { + setLoadingFunctions(false); + sethasMoreFunctions(result.data.hasMore); + setFunctions([...functions, ...result.data.rows]); + }) + .catch((error) => console.error(error)); + }, [pageFunctions]); -
-

Fonctions

-
+ const loadMore = () => { + setLoadingFunctions(true); + setPageFunctions(pageFunctions + 1); + } -
- - -
+ return ( + + + +
+
+

Fonctions

+
+ +
+ + +
+ +
-
- {/* TODO: API Call to fetch data */} - - - - - - - - - - - - + {functions.map((f) => ( + + ))} + + { + !isLoadingFunctions && hasMoreFunctions + ? + + : !hasMoreFunctions ? + null + : +

Chargement...

+ } +
-
-
-); + + ); +} export default Functions; \ No newline at end of file diff --git a/frontend/public/css/general.css b/frontend/public/css/general.css index 738cfae..4591285 100644 --- a/frontend/public/css/general.css +++ b/frontend/public/css/general.css @@ -72,4 +72,23 @@ a, .important { background-clip: padding-box; border: 1px solid #ced4da; border-radius: .5em; +} +.btn { + cursor: pointer; + border: 1px solid transparent; + padding: .375rem .75rem; + font-size: 1rem; + line-height: 1.5; + border-radius: .25rem; + transition: color .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out; +} +.btn-dark:hover { + color: #fff; + background-color: #23272b; + border-color: #1d2124; +} +.btn-dark { + color: #fff; + background-color: #343a40; + border-color: #343a40; } \ No newline at end of file diff --git a/frontend/public/images/functions/weatherRequest.png b/frontend/public/images/functions/weatherRequest.png deleted file mode 100644 index 06530db..0000000 Binary files a/frontend/public/images/functions/weatherRequest.png and /dev/null differ