From 12b12cfe847e83278b7c9aa982c49d994d9c1069 Mon Sep 17 00:00:00 2001 From: "np.w" Date: Wed, 25 Nov 2020 19:06:47 -0600 Subject: [PATCH] make boxes look better --- client/src/app.js | 46 ++++++++++++++++++++------------------- client/src/box.js | 13 ++++++----- client/src/item.js | 14 +++++------- client/src/styles/app.css | 46 +++++++++++++++++++++++++++++++++++++++ server/server.js | 1 + 5 files changed, 84 insertions(+), 36 deletions(-) diff --git a/client/src/app.js b/client/src/app.js index c23afc9..05e8b6f 100644 --- a/client/src/app.js +++ b/client/src/app.js @@ -14,11 +14,12 @@ function App() { fetchData(); }, []); - const [data, setData] = useState([]); + const [data, setData] = useState(); + const [boxName, setBoxName] = useState(''); const [boxDescription, setBoxDescription] = useState(''); - + const [showFormBox, setShowFormBox] = useState(false); const fetchDataAsync = async () => { try { @@ -40,10 +41,10 @@ function App() { } } - const deleteBox = async (id) => { + const removeBox = async (id) => { try { const response = await axios.delete(`${api.baseApiUrl}/${id}`); - setData(response.data); + setData(data.filter(box => box._id !== id)); } catch (error) { console.log(error); @@ -60,6 +61,8 @@ function App() { const handleSubmitBox = (event) => { event.preventDefault(); + setShowFormBox(false); + clearForm(); const boxData = { name: boxName, description: boxDescription @@ -69,29 +72,21 @@ function App() { } const handleRemoveBox = (id) => { - deleteBox(id); + removeBox(id); } - - - - + const handleAddBox = () => { + setShowFormBox(true); + } + const clearForm = () => { + setBoxName(); + setBoxDescription(); + } const boxHandler = { handleSubmit: handleSubmitBox, handleRemove: handleRemoveBox, handleName: handleBoxName, handleDescription: handleBoxDescription }; - - const lstBoxes = data.map((box) => { - return ( - - ); - }); - - - const formNewBox =
New Box @@ -108,8 +103,15 @@ function App() { return ( <> - {formNewBox} - {lstBoxes} + + {!showFormBox && } + {showFormBox && formNewBox} ); diff --git a/client/src/box.js b/client/src/box.js index 48c2555..da068d2 100644 --- a/client/src/box.js +++ b/client/src/box.js @@ -4,6 +4,7 @@ import api from './api'; import axios from 'axios'; const Box = ({ boxData, handleRemove }) => { + console.log(boxData); const [data, setData] = useState(boxData); const [showFormItem, setShowFormItem] = useState(false); @@ -86,16 +87,18 @@ const Box = ({ boxData, handleRemove }) => { return (
  • -

    {data.name}

    -

    {data.description}

    +

    {data.name}

    +
    +

    {data.description}

    + +
      -

      {data.item.length}

      + {data.item.map(((item) => { return }))}
    - - + {showFormItem && formNewItem}
  • ) diff --git a/client/src/item.js b/client/src/item.js index 3e8cbd5..7550558 100644 --- a/client/src/item.js +++ b/client/src/item.js @@ -1,14 +1,10 @@ -import React, {useState, setState } from 'react'; +import React, { useState, setState } from 'react'; -const item = ({data, handleRemove}) => { +const item = ({ data, handleRemove }) => { return (
  • -

    {data.name}

    -
      -
    • {data.description}
    • -
    • {data.quantity}
    • -
    - -
  • ); +

    {data.name}

    + + ); }; export default item; \ No newline at end of file diff --git a/client/src/styles/app.css b/client/src/styles/app.css index 1aa60c6..8cb0c15 100644 --- a/client/src/styles/app.css +++ b/client/src/styles/app.css @@ -4,4 +4,50 @@ form > fieldset > label { form > fieldset { border: none; +} + +li { + list-style: none; + font-size: 11px; +} +li.item { + display: grid; + grid-template-columns: 1fr 4em; + column-gap: 1em; + margin: 0.4em 0 0 0; +} +h1, h2, h3, h4 { + font-weight:normal; + margin: 0; + padding: 0; +} +button { +border: none; +font-size: 0.8em; +padding: 0.1em; +} +button.remove-box { + width: 100%; +} +button:hover { + cursor: pointer; +} +.box-subtitle { + display: grid; + grid-template-columns: 1fr 1fr; + font-size: 12px; + text-transform: lowercase; +} +ul.list-box { + display: grid; + grid-template-columns: repeat(5, 1fr); + padding: 0 0 0 1em; + margin: 0; +} +ul.list-box-item { + padding: 0 0 0 1em; + display: grid; +} +p { + margin: 0; } \ No newline at end of file diff --git a/server/server.js b/server/server.js index 85fae65..d831fb4 100644 --- a/server/server.js +++ b/server/server.js @@ -60,6 +60,7 @@ app.post('/box', async (request, response) => { app.delete('/box/:id', async (request, response) => { await Box.deleteOne({_id: request.params.id}); const updatedBoxes = await getAllBoxes(); + console.log(updatedBoxes); response.send(updatedBoxes); });