diff --git a/src/api/items.js b/src/api/items.js index 0f8ca38..bcddc8b 100644 --- a/src/api/items.js +++ b/src/api/items.js @@ -2,8 +2,6 @@ import axios from "axios"; export const createItem = async (settings) => { try { - console.log(settings); - const formData = new FormData(); formData.append("room", settings.room); formData.append("brand", settings.brand); @@ -26,8 +24,6 @@ export const createItem = async (settings) => { export const updateItem = async (settings) => { try { - console.log(settings); - const formData = new FormData(); formData.append("brand", settings.brand); formData.append("model", settings.model); @@ -52,7 +48,6 @@ export const updateItem = async (settings) => { export const deleteItem = async (id) => { try { - console.log(id); const response = await axios.delete(`/item/${id}`); return response.data; } catch (err) { diff --git a/src/api/user.js b/src/api/user.js index c48c246..33970fa 100644 --- a/src/api/user.js +++ b/src/api/user.js @@ -26,7 +26,6 @@ export const createUser = async (username, password, confirmation) => { export const updateUser = async (settings) => { try { - console.log("try"); // const formData = new FormData(); // formData.append("username", settings.username); // formData.append("password", settings.password); diff --git a/src/contexts/auth-context.jsx b/src/contexts/auth-context.jsx index 9035e08..1ca58de 100644 --- a/src/contexts/auth-context.jsx +++ b/src/contexts/auth-context.jsx @@ -46,7 +46,6 @@ export const AuthenticationProvider = ({ children }) => { const register = async (username, password, confirmation) => { try { const user = await registerApi(username, password, confirmation); - console.log(user); setAuthState({ user }); redirect(); } catch (error) { diff --git a/src/pages/home/home.jsx b/src/pages/home/home.jsx index 86eb64e..d77f16f 100644 --- a/src/pages/home/home.jsx +++ b/src/pages/home/home.jsx @@ -21,7 +21,6 @@ export const Home = () => { getState().then((res) => { try { setIsLoad(false); - console.log(res); setDataset(res); setupRoomsStats(res.rooms); setupGlobalStat({ years: res.years, global: res.global }); diff --git a/src/pages/profile/Profile.jsx b/src/pages/profile/Profile.jsx index 3991d05..30c5b9e 100644 --- a/src/pages/profile/Profile.jsx +++ b/src/pages/profile/Profile.jsx @@ -30,7 +30,6 @@ export default function Profile() { useEffect(() => { document.title = `Profil de ${user.user.username}`; - console.log(user); }, [user]); const handleHelpIE = () => { @@ -71,7 +70,6 @@ export default function Profile() { setImportMsg("Vos depenses ont ete transfere avec sucess."); } setIsIELoad(false); - console.log(res); }); }; @@ -104,8 +102,6 @@ export default function Profile() { logout().then((_) => { refresh(); }); - console.log(res); - console.log(oldPPassword, password, confirmPassword); }); }; diff --git a/src/pages/room/Room.jsx b/src/pages/room/Room.jsx index 1c382da..6400c12 100644 --- a/src/pages/room/Room.jsx +++ b/src/pages/room/Room.jsx @@ -23,7 +23,6 @@ export default function Room() { setIsLoading(true); getRoom(id).then((res) => { - console.log(res); document.title = `Piece - ${res.name}`; setData(res); setIsLoading(false); @@ -81,12 +80,11 @@ export default function Room() { // TODO: Je ferai une modification unitaire plus tard getRoom(id).then((res) => { handleFormUpdate(); - console.log(res); setData(res); }); }); } catch (err) { - console.log(err); + console.error(err); handleFormUpdate(); } }; @@ -113,7 +111,7 @@ export default function Room() { handleForm(); } catch (err) { alert("Quelque chose cloche avec le formulaire ..."); - console.log(err); + console.error(err); } }; diff --git a/src/pages/rooms/Rooms.jsx b/src/pages/rooms/Rooms.jsx index 0c14625..e990a1b 100644 --- a/src/pages/rooms/Rooms.jsx +++ b/src/pages/rooms/Rooms.jsx @@ -8,6 +8,7 @@ import { useAuth } from "../../hooks"; import { useParams } from "react-router-dom"; import { getRoomsLength } from "../../api"; import StylizedBtn from "../../components/StylizedBtn/StylizedBtn"; +import refresh from "../../services/pageManagement"; export default function Rooms() { const { _user } = useAuth(); @@ -18,6 +19,7 @@ export default function Rooms() { const { pageIndex } = useParams(); const [virtualIndex, setVirtualIndex] = useState(0); const [roomsLen, setRoomLen] = useState(null); + const [specialSearch, setSpecialSearch] = useState(false); const onClickCreate = () => { const name = prompt("Nom de la piece ?"); @@ -33,22 +35,23 @@ export default function Rooms() { values.push(res); setRooms(values); alert(`Creation de la piece ${name} reussite !`); + refresh(); }); }; + const splicer = (rms, datasPerPage) => { + const partitions = []; + let index = 0; + + while (index < rms.length) { + partitions.push(rms.slice(index, index + datasPerPage)); + index += datasPerPage; + } + + return partitions; + }; + const configureRooms = (data) => { - const splicer = (rms, datasPerPage) => { - const partitions = []; - let index = 0; - - while (index < rms.length) { - partitions.push(rms.slice(index, index + datasPerPage)); - index += datasPerPage; - } - - return partitions; - }; - const newData = splicer(data, 8); const blabla = newData[pageIndex ? pageIndex : 0]; @@ -58,7 +61,6 @@ export default function Rooms() { setRooms(newData); - console.log(newData[pageIndex ? pageIndex : 0]); setDisplayRooms(newData[pageIndex ? pageIndex : 0]); if (!blabla) { @@ -67,13 +69,36 @@ export default function Rooms() { } }; + const handleSearch = (e) => { + const word = e.target.value; + + if (word.trim().length === 0) { + setSpecialSearch(false); + setDisplayRooms(rooms[virtualIndex]); + return; + } + + setSpecialSearch(true); + const stock = []; + + for (let room of rooms) { + for (let item of room) { + if (item.name.toLowerCase().includes(word.toLowerCase())) { + stock.push(item); + } + } + } + + setVirtualIndex(0); + setDisplayRooms(stock); + }; + const handleBefore = () => { if (virtualIndex === 0) { return; } const index = virtualIndex - 1; - console.log(rooms[index]); setDisplayRooms(rooms[index]); setVirtualIndex(index); }; @@ -84,7 +109,6 @@ export default function Rooms() { } const index = virtualIndex + 1; - console.log(rooms[index]); setDisplayRooms(rooms[index]); setVirtualIndex(index); }; @@ -106,7 +130,6 @@ export default function Rooms() { setRooms(values); setDisplayRooms(values[virtualIndex]); - console.log(res); setRoomLen(roomsLen - 1); @@ -143,6 +166,15 @@ export default function Rooms() { +
+ +
+ {displayRooms ? (
{displayRooms.map((i, j) => ( @@ -174,7 +206,7 @@ export default function Rooms() { )} - {rooms ? ( + {rooms && !specialSearch ? (
{virtualIndex > 0 ? (