Как я могу отобразить мой card Item
в соответствии с project_type
, который будет доступен в массиве.
Например, если type
равен Reactjs
, он будет показан на первой вкладке или в секунду. что-то, используя projects.filter(project => project.project_type === "Reactjs"
Любое предложение о том, что мне нужно сделать здесь?
// project. js
class Projects extends Component{
constructor(props){
super(props);
this.state={activeTab: 0};
}
static propTypes = {
getProject: PropTypes.func.isRequired,
deleteProject: PropTypes.func.isRequired,
resume: PropTypes.object.isRequired,
isAuthenticated: PropTypes.bool,
auth: PropTypes.object.isRequired,
loading: PropTypes.object.isRequired
}
componentDidMount() {
this.props.getProject();
}
onDeleteProjectClick = (id) => {
this.props.deleteProject(id);
};
toggleCategories(projects, user){
if(this.state.activeTab === 0 &&projects.filter(project => project.project_type === "Reactjs" ){
return (
<div>
{projects.map(({ _id, project_type, project_name, project_description, project_link, project_image_link }) => (
<Grid key={_id} timeout={100} className="projects-grid" >
<Card shadow={5} className="cards-grid">
<CardTitle style={{color:'#fff', height:'176px', background:"url("") center/cover"}}>{project_name}</CardTitle>
<CardText>
{project_description}
</CardText>
<CardActions border>
<Button colored><a href={project_link} target="_blank">Live</a></Button>
<Button colored><a href="" target="_blank">Github</a></Button>
</CardActions>
</Card>
</Grid>
))}
</div>
)
}else if(this.state.activeTab === 1 && projects.filter(project => project.project_type === "Html" ){
return(
<div>
{projects.map(({ _id, project_type, project_name, project_description, project_link, project_image_link }) => (
<Grid key={_id} timeout={100} className="projects-grid" >
<Card shadow={5} className="cards-grid">
<CardTitle style={{color:'#fff', height:'176px', background:"url("") center/cover"}}>{project_name}</CardTitle>
<CardText>
{project_description}
</CardText>
<CardActions border>
<Button colored><a href={project_link} target="_blank">Live</a></Button>
<Button colored><a href="" target="_blank">Github</a></Button>
</CardActions>
</Card>
</Grid>
))}
</div>
)
}
}
render(){
const { projects, loading} = this.props.resume;
const { user } = this.props.auth;
return(
<Container>
{loading ? (
<div><Loading/></div>) :
( <div className="category-tabs">
<Tabs activeTab ={this.state.activeTab} onChange={(tabId) => this.setState({activeTab: tabId})} ripple>
<Tab> React/Node </Tab>
<Tab> HTML/CSS/JS </Tab>
</Tabs>
<Grid >
<Cell col={12}>
{this.toggleCategories(projects, user)}
</Cell>
</Grid>
</div> )}
</Container>
)
}
}
const mapStateToProps = (state) => ({
resume: state.resume,
isAuthenticated : state.auth.isAuthenticated,
auth: state.auth,
loading: state.apiCallsInProgress > 0
});
export default connect(mapStateToProps, {getProject, deleteProject }) (Projects);
// JSOn array
[
{
"_id": "5e9b2ca0e02bb43b2c3dee9c",
"project_type": "Html",
"project_name": "abc",
"project_description": "abc",
"project_link": "example.com",
"project_image_link": "example.com",
"date": "2020-04-18T16:36:48.902Z",
"__v": 0
},
{
"_id": "5e9b2c91e02bb43b2c3dee9b",
"project_type": "Reactjs",
"project_name": "abc",
"project_description": "abc",
"project_link": "example.com",
"project_image_link": "example.com",
"date": "2020-04-18T16:36:33.901Z",
"__v": 0
}
]