-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed the items in the menu and added minor changes to the code
Showing
9 changed files
with
296 additions
and
44 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import React from 'react'; | ||
import axios from 'axios'; | ||
import { withRouter } from "react-router"; | ||
|
||
import { Upload, Form, Input, Button, Typography } from 'antd'; | ||
const { Title } = Typography; | ||
const { TextArea } = Input; | ||
|
||
const formItemLayout = { | ||
labelCol: { xs: { span: 24 }, sm: { span: 6 } }, | ||
wrapperCol: { xs: { span: 24 }, sm: { span: 12 } } | ||
}; | ||
|
||
const tailFormItemLayout = { | ||
wrapperCol: { xs: { span: 24, offset: 0 }, sm: { span: 16, offset: 6 } }, | ||
}; | ||
|
||
class EditDog extends React.Component { | ||
|
||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
selectedFile: null | ||
} | ||
|
||
} | ||
|
||
componentDidMount(){ | ||
this.setState({ | ||
dogID: this.props.match.params.id | ||
}) | ||
} | ||
|
||
handleBreedChange=event=>{ | ||
this.setState({ | ||
breed: event.target.value | ||
}) | ||
} | ||
|
||
handleAgeChange=event=>{ | ||
this.setState({ | ||
age: event.target.value | ||
}) | ||
} | ||
|
||
handleSizeChange=event=>{ | ||
this.setState({ | ||
size: event.target.value | ||
}) | ||
} | ||
|
||
handleDescriptionChange=event=>{ | ||
this.setState({ | ||
description: event.target.value | ||
}) | ||
} | ||
|
||
handleImageChange=event=>{ | ||
this.setState({ | ||
selectedFile: event.target.files[0], | ||
loaded: 0, | ||
}) | ||
} | ||
|
||
onClickHandler = () => { | ||
const data = new FormData() | ||
if(this.state.selectedFile){data.append('upload', this.state.selectedFile)} | ||
if(this.state.breed){data.append('breed', this.state.breed)} | ||
if(this.state.age){data.append('age', this.state.age)} | ||
if(this.state.size){data.append('size', this.state.size)} | ||
if(this.state.description){data.append('description', this.state.description)} | ||
axios.put(`https://animal-hello-3000.codio-box.uk/api/v1/dogs/${this.state.dogID}`, data, { | ||
auth: { | ||
username: 'daniel', | ||
password: 'abc' | ||
}, | ||
headers: { | ||
'content-type': 'multipart/form-data' | ||
} | ||
}) | ||
.then(res => { // then print response status | ||
console.log(res.statusText) | ||
this.props.history.push('/') | ||
}) | ||
} | ||
|
||
render(){ | ||
return ( | ||
<Form {...formItemLayout}> | ||
<Title level={2}> Edit dog</Title> | ||
<Form.Item name="breed" label="Breed"> | ||
<Input onChange={this.handleBreedChange}/> | ||
</Form.Item> | ||
<Form.Item name="age" label="Age"> | ||
<Input onChange={this.handleAgeChange}/> | ||
</Form.Item> | ||
<Form.Item name="size" label="Size"> | ||
<Input onChange={this.handleSizeChange}/> | ||
</Form.Item> | ||
<Form.Item name="description" label="Description"> | ||
<TextArea rows={3} onChange={this.handleDescriptionChange}/> | ||
</Form.Item > | ||
<Form.Item label="Image"> | ||
<Input type="file" name="file" onChange={this.handleImageChange}/> | ||
</Form.Item> | ||
<Button type="button" onClick={this.onClickHandler}>Submit</Button> | ||
</Form> | ||
); | ||
} | ||
|
||
} | ||
|
||
|
||
export default withRouter(EditDog); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react'; | ||
|
||
function Messages(props) { | ||
return ( | ||
<> | ||
<p>This is where the messages page is displayed</p> | ||
</> | ||
); | ||
} | ||
|
||
export default Messages; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import React from 'react'; | ||
import axios from 'axios'; | ||
|
||
import { Upload, Form, Input, Button, Typography } from 'antd'; | ||
const { Title } = Typography; | ||
const { TextArea } = Input; | ||
|
||
const formItemLayout = { | ||
labelCol: { xs: { span: 24 }, sm: { span: 6 } }, | ||
wrapperCol: { xs: { span: 24 }, sm: { span: 12 } } | ||
}; | ||
|
||
const tailFormItemLayout = { | ||
wrapperCol: { xs: { span: 24, offset: 0 }, sm: { span: 16, offset: 6 } }, | ||
}; | ||
|
||
class NewDog extends React.Component { | ||
|
||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
selectedFile: null | ||
} | ||
|
||
} | ||
handleBreedChange=event=>{ | ||
this.setState({ | ||
breed: event.target.value | ||
}) | ||
} | ||
|
||
handleAgeChange=event=>{ | ||
this.setState({ | ||
age: event.target.value | ||
}) | ||
} | ||
|
||
handleSizeChange=event=>{ | ||
this.setState({ | ||
size: event.target.value | ||
}) | ||
} | ||
|
||
handleDescriptionChange=event=>{ | ||
this.setState({ | ||
description: event.target.value | ||
}) | ||
} | ||
|
||
handleImageChange=event=>{ | ||
this.setState({ | ||
selectedFile: event.target.files[0], | ||
loaded: 0, | ||
}) | ||
} | ||
|
||
onClickHandler = () => { | ||
const data = new FormData() | ||
data.append('upload', this.state.selectedFile) | ||
data.append('breed', this.state.breed) | ||
data.append('age', this.state.age) | ||
data.append('size', this.state.size) | ||
data.append('description', this.state.description) | ||
axios.post("https://animal-hello-3000.codio-box.uk/api/v1/dogs", data, { | ||
auth: { | ||
username: 'daniel', | ||
password: 'abc' | ||
}, | ||
headers: { | ||
'content-type': 'multipart/form-data' | ||
} | ||
}) | ||
.then(res => { // then print response status | ||
console.log(res.statusText) | ||
}) | ||
} | ||
|
||
render(){ | ||
return ( | ||
<Form {...formItemLayout}> | ||
<Title level={2}> Insert a new dog</Title> | ||
<Form.Item name="breed" label="Breed"> | ||
<Input onChange={this.handleBreedChange}/> | ||
</Form.Item> | ||
<Form.Item name="age" label="Age"> | ||
<Input onChange={this.handleAgeChange}/> | ||
</Form.Item> | ||
<Form.Item name="size" label="Size"> | ||
<Input onChange={this.handleSizeChange}/> | ||
</Form.Item> | ||
<Form.Item name="description" label="Description"> | ||
<TextArea rows={3} onChange={this.handleDescriptionChange}/> | ||
</Form.Item > | ||
<Form.Item label="Image"> | ||
<Input type="file" name="file" onChange={this.handleImageChange}/> | ||
</Form.Item> | ||
<Button type="button" onClick={this.onClickHandler}>Submit</Button> | ||
</Form> | ||
); | ||
} | ||
|
||
} | ||
|
||
|
||
export default NewDog; |