Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with part 6 CRUD #7

Open
Leonardll opened this issue Oct 30, 2021 · 0 comments
Open

Issues with part 6 CRUD #7

Leonardll opened this issue Oct 30, 2021 · 0 comments

Comments

@Leonardll
Copy link

Hi Paul,

Thank you for the great contest you have shared online. I am going following along your course then i got stuck on the below error which i don't understand as i have mirrored your code. Can you help me spot where i made a mistake please?

The error message is cannot read properties of undefined reading "id"

Skill.js is equivalent to your speaker.js

import Image from "next/dist/client/image";
import { FaTimes, FaRegCalendarAlt, FaSchool,FaSpinner } from "react-icons/fa";
import styles from '../../styles/Home.module.scss'
//import { FaStar } from 'react-icons/fa';
import { AiFillStar , AiOutlineStar } from 'react-icons/ai'
import { useState, useContext } from 'react';
import { CourseFilterContext } from "../contexts/CourseFilterContext";
import { SkillProvider, SkillContext } from "../contexts/SkillContext";

function Course({ courseTitle, hours, level, year }) {
return (
<>

Course : {courseTitle}{" "}


Hours: {hours}


Level : {level}


Year : {year}

</>
);
}

function Courses() {
const { courseYear } = useContext(CourseFilterContext);
const { skillCard } = useContext(SkillContext);
const courses = skillCard.courses;
const level = skillCard.level;

return (
  <div className={styles.courseBox, "h-250"}>
    {courses
    .filter(function (course) {
      return course.year === courseYear;
    })
    .map(function (course) {
      return (
        <Course {...course} level={level} key={skillCard.courses.id} />
      )
    })
    }        
  </div>  
);

}

function SkillImage() {
const { skillCard: {id, skill} } = useContext(SkillContext);
return (


<Image
src={/images/skill-${id}.png}
className="contain-fit"
alt={${skill}}
width="300"
height="300"
/>

);
}

function SkillFavorite () {
const { skillCard, updateRecord } = useContext(SkillContext);
const [inTransition, setInTransition] = useState(false);

function doneCallBack () {
  setInTransition(false);
  console.log(`In SkillFavorite: doneCallBack  ${new Date().getMilliseconds()}`)
}
return (
  <div className={styles.icon}>
    <span onClick={function () {
      setInTransition(true);
      updateRecord(
        {
          ...skillCard, favorite: !skillCard.favorite,
        },
        doneCallBack
      )
      }}>
    { skillCard.favorite === false ?
    <AiFillStar fill="orange"/> : <AiOutlineStar fill="yellow"/>
    }{" "}
    Favorite{" "}
    { inTransition === true ? (
      <span><FaSpinner className="fa-spin" fill="orange"/></span>
    ): null}
    </span>
  </div>
)

}
function SkillDescription() {
const { skillCard } = useContext(SkillContext);
const { skill, description, school, } = skillCard;
return (



{skill}



{description}




{/* /}
School

{school}



{/
/}
{/
Year

{courses[0].year}
*/}



);
}

function SkillAction () {
return (


<button
className="btn btn-primary w-100"
onClick={() => handleEditClick()}
>Edit


<FaTimes className="m-3 " fill="#ffc800" onClick={() => handleDeleteClick(idx)} />


);
}

function Skill({ skillCard, updateRecord }) {
const {id, skill, courses, level, year} = skillCard;
const { showCourses } = useContext(CourseFilterContext);
return (






{showCourses === true ?
: null}







);
}

export default Skill;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant