Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Created react list, reusable components and mock data to test
- Loading branch information
Showing
7 changed files
with
219 additions
and
50 deletions.
There are no files selected for viewing
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,36 @@ | ||
import React from 'react'; | ||
import { Card } from 'antd'; | ||
import PostIcon from './dogicon'; | ||
import NavImage from './navimage' | ||
|
||
const { Meta } = Card; | ||
|
||
class DogCard extends React.Component { | ||
|
||
constructor(props) { | ||
super(props); | ||
this.handleNav = this.handleNav.bind(this); | ||
} | ||
|
||
handleNav() { | ||
console.log(`clicked post ${this.props.id}`); | ||
} | ||
|
||
render() { | ||
const dogID = this.props.id; | ||
return ( | ||
<Card | ||
style={{ width: 320 }} | ||
cover={<NavImage img alt="test" src={this.props.imgURL} to={`/dog/${dogID}`}/>} | ||
hoverable={true} | ||
actions={[ | ||
<PostIcon type="heart" selected={this.props.heart}/>, | ||
<PostIcon type="edit" selected={this.props.edit}/> | ||
]}> | ||
<Meta title={this.props.Name} description={this.props.about} /> | ||
</Card> | ||
); | ||
} | ||
} | ||
|
||
export default DogCard; |
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,41 @@ | ||
import React from 'react'; | ||
import { Col, Row } from 'antd'; | ||
import DogCard from './dogcard'; | ||
|
||
class BlogGrid extends React.Component { | ||
|
||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
posts: [] | ||
} | ||
} | ||
|
||
componentDidMount() { | ||
this.setState({ | ||
posts: require('../data/dogs.json') | ||
}) | ||
} | ||
|
||
render() { | ||
if (!this.state.posts.length) { | ||
return <h3>Loading posts...</h3> | ||
} | ||
const cardList = this.state.posts.map(post => { | ||
return ( | ||
<div style={{padding:"10px"}} key={post.id}> | ||
<Col span={6}> | ||
<DogCard {...post} /> | ||
</Col> | ||
</div> | ||
) | ||
}); | ||
return ( | ||
<Row type="flex" justify="space-around"> | ||
{cardList} | ||
</Row> | ||
); | ||
} | ||
} | ||
|
||
export default BlogGrid; |
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,54 @@ | ||
import React from 'react'; | ||
import { EditOutlined, EditFilled, HeartOutlined, HeartFilled} from "@ant-design/icons"; | ||
|
||
function getIcon (theme, iconType) { | ||
let Icon; | ||
|
||
if (theme === 'filled') { | ||
if (iconType === 'edit') { | ||
Icon = EditFilled | ||
} else if (iconType === 'heart') { | ||
Icon = HeartFilled | ||
} | ||
} else if (theme === 'outlined') { | ||
if (iconType === 'edit') { | ||
Icon = EditOutlined | ||
} else if (iconType === 'heart') { | ||
Icon = HeartOutlined | ||
} | ||
} | ||
|
||
return Icon; | ||
} | ||
|
||
class PostIcon extends React.Component { | ||
constructor(props){ | ||
super(props); | ||
this.state = { | ||
selected: props.selected | ||
}; | ||
this.onClick = this.onClick.bind(this); | ||
} | ||
|
||
onClick(){ | ||
//reverse the selected state with every click | ||
this.setState({selected: !this.state.selected}); | ||
} | ||
|
||
render(){ | ||
const theme = this.state.selected ? 'filled' : 'outlined'; | ||
const iconType = this.props.type; | ||
const Icon = getIcon(theme, iconType); | ||
|
||
return ( | ||
<span> | ||
<Icon | ||
onClick={this.onClick} | ||
style={{color:'steelblue'}} /> | ||
{this.props.count} | ||
</span> | ||
); | ||
} | ||
} | ||
|
||
export default PostIcon; |
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,12 @@ | ||
/** | ||
* Wrap an image tag as a React component to allow router linking. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { useHistory } from 'react-router-dom'; | ||
|
||
const NavImage = (props) => { | ||
const history = useHistory(); | ||
return <img alt={props.alt} src={props.src} onClick={() => history.push(props.to)} />; | ||
} | ||
export default NavImage; |
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,71 @@ | ||
[{ | ||
"id": 1, | ||
"Name": "dog1", | ||
"Breed": "some desription about the article", | ||
"Age": "4", | ||
"about": "dog description", | ||
"imgURL": "https://picsum.photos/id/1025/400", | ||
"heart": false, | ||
"edit": false | ||
}, | ||
{ | ||
"id": 2, | ||
"Name": "dog2", | ||
"Breed": "some desription about the article", | ||
"Age": "4", | ||
"about": "dog description", | ||
"imgURL": "https://picsum.photos/id/1025/400", | ||
"heart": false, | ||
"edit": false | ||
}, | ||
{ | ||
"id": 3, | ||
"Name": "dog3", | ||
"Breed": "some desription about the article", | ||
"Age": "4", | ||
"about": "dog description", | ||
"imgURL": "https://picsum.photos/id/1025/400", | ||
"heart": false, | ||
"edit": false | ||
}, | ||
{ | ||
"id": 4, | ||
"Name": "dog4", | ||
"Breed": "some desription about the article", | ||
"Age": "4", | ||
"about": "dog description", | ||
"imgURL": "https://picsum.photos/id/1025/400", | ||
"heart": false, | ||
"edit": false | ||
}, | ||
{ | ||
"id": 5, | ||
"Name": "dog5", | ||
"Breed": "some desription about the article", | ||
"Age": "4", | ||
"about": "dog description", | ||
"imgURL": "https://picsum.photos/id/1025/400", | ||
"heart": false, | ||
"edit": false | ||
}, | ||
{ | ||
"id": 6, | ||
"Name": "dog6", | ||
"Breed": "some desription about the article", | ||
"Age": "4", | ||
"about": "dog description", | ||
"imgURL": "https://picsum.photos/id/1025/400", | ||
"heart": false, | ||
"edit": false | ||
}, | ||
{ | ||
"id": 7, | ||
"Name": "dog7", | ||
"Breed": "some desription about the article", | ||
"Age": "4", | ||
"about": "dog description", | ||
"imgURL": "https://picsum.photos/id/1025/400", | ||
"heart": false, | ||
"edit": false | ||
} | ||
] |