From 7440f41991668b27975d7ba8792546e47162d38d Mon Sep 17 00:00:00 2001 From: kathleenconnaghan <77138134+kathleenconnaghan@users.noreply.github.com> Date: Sat, 10 Jul 2021 13:02:22 -0400 Subject: [PATCH] completed cycle 1 & 2 Connect & Link --- client/components/Main.js | 1 + client/components/SingleStudent.js | 30 +++++++++++- client/components/StudentList.js | 78 ++++++++++++++++++++++-------- client/redux/store.js | 71 +++++++++++++++++++++------ 4 files changed, 145 insertions(+), 35 deletions(-) diff --git a/client/components/Main.js b/client/components/Main.js index 7fd3d8b..df1953c 100644 --- a/client/components/Main.js +++ b/client/components/Main.js @@ -16,6 +16,7 @@ export default class Main extends React.Component { + ); diff --git a/client/components/SingleStudent.js b/client/components/SingleStudent.js index d350227..f62889c 100644 --- a/client/components/SingleStudent.js +++ b/client/components/SingleStudent.js @@ -1,4 +1,7 @@ import React from 'react'; +import { Route, Link } from 'react-router-dom' +import { connect } from 'react-redux'; +import { getSingleStudent, fetchSingleStudent } from "../redux/store"; const avgGrade = (tests) => { return Math.round( @@ -11,6 +14,18 @@ class SingleStudent extends React.Component { super(props); } + + componentDidMount () { + try { + const studentId = this.props.match.params.id + this.props.getSingleStudent(id) + } + catch (error) { + console.error(error) + } + } + + render() { const { student } = this.props; const hasTests = student.tests.length; @@ -50,4 +65,17 @@ class SingleStudent extends React.Component { } }; -export default SingleStudent; +const mapStateToProps = (state) => { + return { + student: state.singleS + } +} + +const mapDispatchToProps = (dispatch) => { + return { + getSingleStudent: (id) => dispatch(fetchSingleStudent(id)) + } +} + + +export default connect(mapStateToProps, mapDispatchToProps)(SingleStudent) diff --git a/client/components/StudentList.js b/client/components/StudentList.js index c5d4c5a..f79774e 100644 --- a/client/components/StudentList.js +++ b/client/components/StudentList.js @@ -1,36 +1,49 @@ import React from 'react'; import {Link} from 'react-router-dom' +import { connect } from 'react-redux' +import {fetchStudents} from '../redux/store' +// thunk is imported because it's middle ware -const DUMMY_DATA = [ - { - id: 1, - fullName: "Jordan Walke", - firstName: "Jordan", - lastName: "Walke", - email: "jw@react.com", - }, - { - id: 2, - fullName: "Dan Abramov", - firstName: "Dan", - lastName: "Avramov", - email: "da@react.com", - } -] +// const DUMMY_DATA = [ +// { +// id: 1, +// fullName: "Jordan Walke", +// firstName: "Jordan", +// lastName: "Walke", +// email: "jw@react.com", +// }, +// { +// id: 2, +// fullName: "Dan Abramov", +// firstName: "Dan", +// lastName: "Avramov", +// email: "da@react.com", +// } +// ] class StudentList extends React.Component { constructor(props) { super(props); } + componentDidMount() { + this.props.loadStudents() + } + render() { + console.log('RENDER SOMETHING ') + // going to mapStateToProvps via pops and mapping throught he stu return ( -