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

[조규진] Sprint7 #224

Conversation

gjrefa9139
Copy link
Collaborator

@gjrefa9139 gjrefa9139 commented Jul 5, 2024

기본

상품 상세

  • 상품 상세 페이지 주소는 “/items/{productId}” 입니다.
  • response 로 받은 아래의 데이터로 화면을 구현합니다.
    • favoriteCount : 하트 개수
    • images : 상품 이미지
    • tags : 상품태그
    • name : 상품 이름
    • description : 상품 설명
  • 목록으로 돌아가기 버튼을 클릭하면 중고마켓 페이지 주소인 “/items” 으로 이동합니다

상품 문의 댓글

  • 문의하기에 내용을 입력하면 등록 버튼의 색상은 “3692FF”로 변합니다.
  • response 로 받은 아래의 데이터로 화면을 구현합니다
    • image : 작성자 이미지
    • nickname : 작성자 닉네임
    • content : 작성자가 남긴 문구
    • description : 상품 설명 ?
    • updatedAt : 문의글 마지막 업데이트 시간

심화

주요 변경사항

스크린샷

멘토에게

  • 셀프 코드 리뷰를 통해 질문 이어가겠습니다.

@gjrefa9139 gjrefa9139 requested a review from 201steve July 5, 2024 14:54
@gjrefa9139 gjrefa9139 added the 미완성🫠 죄송합니다.. label Jul 5, 2024
Copy link
Collaborator

@201steve 201steve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고많으셨습니다 :-)

<nav>
<ul>
<li>
<NavLink to='/community' style={highlightCommunity}>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 인라인 스타일링은 지양하는게 좋습니다.
  • styled-component를 사용하면 component의 스타일링도 가능합니다.
import {NavLink} from 'react-router-dom'
import styled from 'styled-components'

const StyledNavLink = styled(NavLink)`
color : ${({isActive,theme})=>isActive? theme.colors.blue : undefined}
`

styled(NavLink) 이 부분에 인자로 스타일링 할 컴포넌트를 전달하는게 가능합니다 :-)
공식문서 Styling any component 를 참고 해 보세요! :-)

Comment on lines +17 to +52
export async function getProductDetail(productId) {
if (!productId) {
throw new Error('Invalid product ID');
}

try {
const response = await fetch(`https://panda-market-api.vercel.app/products/${productId}`);
if (!response.ok) {
throw new Error(`HTTP error: ${response.status}`);
}
const body = await response.json();
return body;
} catch (error) {
console.error('Failed to fetch product detail:', error);
throw error;
}
}

export async function getProductComments({ productId, params }) {
if (!productId) {
throw new Error('Invalid product ID');
}

try {
const query = new URLSearchParams(params).toString();
const response = await fetch(`https://panda-market-api.vercel.app/products/${productId}/comments?${query}`);
if (!response.ok) {
throw new Error(`HTTP error: ${response.status}`);
}
const body = await response.json();
return body;
} catch (error) {
console.error('Failed to fetch product comments:', error);
throw error;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

url만 다른 함수 2개가 같은 동작을 하고있어서, 공통 함수로 분리하면 반복 코드를 줄일 수 있을것같네요

const fetchData =async(url)=>{
 try {
    const response = await fetch(url);
    if (!response.ok) {
      throw new Error(`HTTP error: ${response.status}`);
    }
    const body = await response.json();
    return body;
  } catch (error) {
    console.error('Failed to fetch product detail:', error);
    throw error;
  }
}
}

export async function getProductDetail(productId){
if (!productId) {
    throw new Error('Invalid product ID');
  }
const url = `https://panda-market-api.vercel.app/products/${productId}`
return fetchData(url)
}

export async function getProductComments({ productId, params }) {
if (!productId) {
    throw new Error('Invalid product ID');
  }
const query = new URLSearchParams(params).toString();
const url = `https://panda-market-api.vercel.app/products/${productId}/comments?${query}`
return fetchData(url)
}

Comment on lines 10 to 20
--gray50: #f9fafb;

--blue: #3692ff;

--white: #fff;
--red: #f74747;

--hover: #1967d6;
--focus: #1251aa;
--disabled: #9ca3af;
--click: #1251aa;
--inactive: #9ca3af;

--header-height: 70px;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아직은 css로도 변수 선언이나 할당이 가능하지만 styled-components를 도입하면 더욱 편하게 사용하실 수 있습니다 :-)

//Main.js
render(
<ThemeProvider theme={{ color: 'mediumseagreen' }}>
   <Router/>
</ThemeProvider>
)

theme에 전달하려는 객체를 보내면
필요로 하는 컴포넌트에서 props로 받는 theme에 접근해서 원하는 값을 쓸 수 있습니다.

const Box = styled.div`
  color: ${props => props.theme.color};
`

}

.button.pill {
/* .button.pill {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 속성은 주석처리만 되어있어서
언제 다시 사용될지, 혹은 사용이 안될지를 주석에 같이 적어주시거나
혹은 사용이 영영 안될 코드라면 삭제 해주시면 좋을것같아요 :-)

}

export default DeleteButton;

// 코드 테스트 중
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지금은 괜찮지만 나중에 회사에 가서는 테스트는 로컬에서만 하고, commit에는 남지 않도록 해주세요. :-)

`;

const CommentItem = ({ item }) => {
const authorInfo = item.writer;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

변수로 중복되는 코드를 잘 할당 해주셨는데,
구조분해할당을 쓰면

const {
writer : {image, nickname},
content
} = item 

이렇게도 표현할 수 있고, 원하는 프로퍼티에 직접 접근도 가능해서 사용하기 편리해집니다

setError(null);
} catch (error) {
console.error('Error fetching comments:', error);
setError('상품의 댓글을 불러오지 못했어요.');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이부분도 위에 리뷰처럼 기획서에는 없는 부분인것같은데 확인 바랍니다~

Comment on lines +5 to +6
const COMMENT_PLACEHOLDER =
'개인정보를 공유 및 요청하거나, 명예 훼손, 무단 광고, 불법 정보 유포시 모니터링 후 삭제될 수 있으며, 이에 대한 민형사상 책임은 게시자에게 있습니다.';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

상수로 처리 잘 해주셨습니다 👍

setComment(e.target.value);
};

const handlePostComment = () => {};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기는 만들어지나다 만 것 같은 함수네요~ :-)

`;

const EmptyStateText = styled.p`
color: var(--gray400);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이런 전역에서 쓰이는 컬러값을 ThemeProvider로 받아서 써보세요 :-) 훨씬 간편할꺼에요!

@201steve 201steve merged commit 8e2def7 into codeit-bootcamp-frontend:React-조규진 Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
미완성🫠 죄송합니다..
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants