From e4dfe240dd656a972ef06d2d672a446d3de07768 Mon Sep 17 00:00:00 2001 From: manda Date: Tue, 16 Dec 2025 18:41:49 -0800 Subject: [PATCH] Handling form visibility Not sure what this is --- app/controllers/api/v1/books_controller.rb | 2 +- app/javascript/components/Books/Books.jsx | 55 ++++++++++++++++++++++ app/views/pages/index.html.erb | 2 +- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/books_controller.rb b/app/controllers/api/v1/books_controller.rb index fb49d6a..27b44ba 100644 --- a/app/controllers/api/v1/books_controller.rb +++ b/app/controllers/api/v1/books_controller.rb @@ -46,7 +46,7 @@ def destroy private def book_params - params.require(:book).permit(:name, :author) + params.require(:book).permit(:id, :name, :author) end def options diff --git a/app/javascript/components/Books/Books.jsx b/app/javascript/components/Books/Books.jsx index cd5663f..5272efb 100644 --- a/app/javascript/components/Books/Books.jsx +++ b/app/javascript/components/Books/Books.jsx @@ -40,6 +40,7 @@ const styles = { const Books = (props) => { const [books, setBooks] = useState([]); + const [formVisible, setFormVisible] = useState(false); const [book, setBook] = useState({}); const { classes } = props; @@ -61,12 +62,66 @@ const Books = (props) => { ) }) + const handleFormVisibilty = () => { + setFormVisible(true) + } + + const handleChange = (event) => { + const target = event.target + const {value, name} = target + + let tempBook = Object.assign({}, book) + tempBook[name] = value + + setBook(tempBook) + } + + const handleSave = () => { + console.log("Save") + } + return (

Books

    {book_list}
+
+ + {formVisible && +
+ + + + {/* */} + + + +
+ } +
) } diff --git a/app/views/pages/index.html.erb b/app/views/pages/index.html.erb index 5e1c309..78e8900 100644 --- a/app/views/pages/index.html.erb +++ b/app/views/pages/index.html.erb @@ -1 +1 @@ -Hello World \ No newline at end of file +Hello World erb \ No newline at end of file