-
-
Save sithumonline/a02db551c885313e6167fa3014adef6f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import React, { useState, useEffect } from 'react' | |
| import axios from 'axios' | |
| // @material-ui/core components | |
| import { makeStyles } from '@material-ui/core/styles' | |
| import authHeader from '../assets/jss/services/auth-header' | |
| //import Grid from '@material-ui/core/Grid' | |
| // @material-ui/icons | |
| // core components | |
| import CardComponent from './card.component' | |
| const useStyles = makeStyles(theme => ({ | |
| root: { | |
| flexGrow: 1, | |
| }, | |
| })) | |
| export default function ClassListSection(props) { | |
| const classes = useStyles() | |
| const [ResData, setResData] = useState([]) | |
| const [Details, setDetails] = useState([]) | |
| const ID = props.location.pathname.split('/teacher/')[1] | |
| var CardSectionList | |
| const List = [] | |
| useEffect(() => { | |
| function fetchPart(id) { | |
| axios | |
| .get('http://clz-api.vercel.app/api/teacher/classlist/' + id, { | |
| headers: authHeader(), | |
| }) | |
| .then(res => { | |
| setResData(res.data) | |
| }) | |
| .catch(err => { | |
| console.log('Error from classlist') | |
| }) | |
| } | |
| fetchPart(ID) | |
| }, [ID]) | |
| ResData.map(_class => | |
| _class.teacher_class.map(_id => { | |
| axios | |
| .get('http://clz-api.vercel.app/api/teacher/classdetails/' + _id, { | |
| headers: authHeader(), | |
| }) | |
| .then(res => { | |
| List.push(res.data) | |
| }) | |
| .catch(err => { | |
| console.log('Error from classdetails ', err) | |
| }) | |
| }), | |
| ) | |
| if (!List) { | |
| CardSectionList = 'Classes is not availabe' | |
| } else { | |
| console.log('Arr :: ', List) | |
| //code block 01 | |
| CardSectionList = List.map(element => | |
| element.map(vale => <CardComponent data={vale} />), | |
| ) | |
| // code block 02 | |
| // setDetails(List) | |
| // CardSectionList = Details.map(element => | |
| // element.map(vale => <CardComponent data={vale} />), | |
| // ) | |
| } | |
| return <div className={classes.root}>{CardSectionList}</div> | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment