Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/api/v1/books_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 55 additions & 0 deletions app/javascript/components/Books/Books.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 (
<div className={ classes.booksContainer }>
<div className={ classes.columnOne}>
<h1>Books</h1>
<ul>{book_list}</ul>
</div>
<div className={ classes.columnTwo}>
<button className="button" onClick={handleFormVisibilty}>Push it</button>
{formVisible &&
<div>
<FormControl>
<TextField
name='title'
label='Title'
onChange={ handleChange }
/>
<TextField
name='author'
label='Author'
onChange={ handleChange }
/>
{/* <TextField
name='rating'
label='Rating'
type='number'
InputProps={{
inputProps: {
min: 1,
max: 5
}
}}
onChange={ handleChange }
/> */}

<button onClick={ handleSubmit }
className={ classes.button }>
Save Book
</button>
</FormControl>
</div>
}
</div>
</div>
)
}
Expand Down
2 changes: 1 addition & 1 deletion app/views/pages/index.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Hello World
Hello World erb
Loading