요구사항 모달제어.

필수 이미지를 검색한 후 결과로 주어진 이미지를 클릭하면 모달이 뜨는데, 모달 영역 밖을 누르거나 / 키보드의 ESC 키를 누르거나 / 모달 우측의 닫기(x) 버튼을 누르면 닫히도록 수정해야 합니다. 모달에서 고양이의 성격, 태생 정보를 렌더링합니다. 해당 정보는 /cats/:id 를 통해 불러와야 합니다.

모달제어 : ImageInfo.js + cat데이터 들어오는 부분 수정.(setState)

this.searchResult = new SearchResult({
    $target,
    initialData: this.data,
    onClick: image => {
      **console.log(image)**
      this.imageInfo.setState({
        visible: true,
        image
      });
    },
  });
{
	id: "dlq",
	name: "Scottish Fold / 스코티시 폴드",
	url: "<https://cdn2.thecatapi.com/images/dlq.png>"
}
this.searchResult = new SearchResult({
  $target,
  initialData: this.data,
  **onClick: cat => {
    this.imageInfo.setState({
      visible: true,
      cat
    });
  },**
});
this.searchResult = new SearchResult({
  $target,
  initialData: this.data,
  onClick: cat => {
    //this.imageInfo.setState({ ... 로 데이터를 넣은 곳을 바꿔줌.
    **this.imageInfo.showDetail({
      visible: true,
      cat
    });**
  },
});
class ImageInfo {
  $imageInfo = null;
  data = null;

  constructor({ $target, data }) {
    const $imageInfo = document.createElement("div");
    $imageInfo.className = "ImageInfo";
    this.$imageInfo = $imageInfo;
    $target.appendChild($imageInfo);

    this.data = data;

    this.render();
  }

  setState(nextData) {
    this.data = nextData;
    this.render();
  }

  
  **showDetail(cat){
		this.setState(cat); 
		//app.js > searchResult onClick 이벤트 > showDetail로 들어온 데이터는 여기서 setState()시켜서 데이터를 받아준다.
  }**

  
  render() {
    if (this.data.visible) {
      const { name, url, temperament, origin } = **this.data.cat;  //이름도 cat으로 바꿈.**

      this.$imageInfo.innerHTML = `
        <div class="content-wrapper">
          <div class="title">
            <span>${name}</span>
            <div class="close">x</div>
          </div>
          <img src="${url}" alt="${name}"/>        
          <div class="description">
            <div>성격: ${temperament}</div>
            <div>태생: ${origin}</div>
          </div>
        </div>`;
      this.$imageInfo.style.display = "block";
    } else {
      this.$imageInfo.style.display = "none";
    }
  }
}

모달 상세 데이터 API 요청

fetchCatDetail: id => {
  return fetch(`${API_ENDPOINT}/api/cats/${id}`).then(res =>
    res.json()
  );
},