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

[ Week4 JS -> TS ] 깃허브 검색기 TS 변환 #6

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Brokyeom
Copy link
Member

🎁 PR Point

  • 타입 interface 생성
    • 깃허브 데이터의 타입을 별도의 인터페이스로 지정하여 export 하여 사용하였습니다.
export interface UserInfoProps {
  login: string;
  name: string;
  avatar_url: string;
  followers: number;
  following: number;
  public_repos: number;
  html_url: string;
}
// UserInfo.tsx
function UserInfo(userInfo: UserInfoProps) {
  const {
    login,
    name,
    avatar_url,
    html_url,
    followers,
    following,
    public_repos,
  } = userInfo;


// Search.tsx
  const [historyArr, setHistoryArr] = useState<string[]>([]);
  const [openHistory, setOpenHistory] = useState<boolean>(false);
  const [isSearch, setIsSearch] = useState<boolean>(false);
  const [userInfo, setUserInfo] = useState<UserInfoProps>();

이벤트 함수에서 event 인자의 타입 지정에서 오버로드 오류가 발생해서 해결 중인데, 꾸준히 고민해보겠습니다. 처음에 하드코딩한 결과가 지금 어려움으로 다가오는 것 같은.. ㅜㅜ

Copy link
Member

@Happhee Happhee left a comment

Choose a reason for hiding this comment

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

자랫는데! 혹시 도움 필요한 부분이씀 갠톡해죠! 클론바다서 도와주꼐!

<BrowserRouter>
<Routes>
<Route path="/search" element={<Search />}>
<Route path=":userId" element={<Search />} />
Copy link
Member

Choose a reason for hiding this comment

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

이거 왜 경로가 다른데 같은 컴포넌트를 보여주나요?

Copy link
Member Author

Choose a reason for hiding this comment

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

이거 왜 경로가 다른데 같은 컴포넌트를 보여주나요?

중첩라우팅을 통해서 검색 전의 Search 컴포넌트와 검색 후의 컴포넌트의 경로를 다르게 설정한 것이고, 컴포넌트 구조는 똑같기 때문에 경로만 다르게 설정한 것인데 이것이 올바르지 않은 방법일까?

Comment on lines +4 to +5
const res = await axios.get(`https://api.github.com/users/${username}`);
return res.data;
Copy link
Member

Choose a reason for hiding this comment

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

인스턴스 객체 만들어서 분할하는것도 해보쟝ㅇ!!

const [historyArr, setHistoryArr] = useState<string[]>([]);
const [openHistory, setOpenHistory] = useState<boolean>(false);
const [isSearch, setIsSearch] = useState<boolean>(false);
const [userInfo, setUserInfo] = useState<UserInfoProps>();
Copy link
Member

Choose a reason for hiding this comment

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

우리 props는 컴포넌트 props에서만 사용하기로 했던 이유알지용?!

Comment on lines +26 to +34
setUserInfo({
login: userData.login,
name: userData.name,
avatar_url: userData.avatar_url,
followers: userData.followers,
following: userData.following,
public_repos: userData.public_repos,
html_url: userData.html_url,
});
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
setUserInfo({
login: userData.login,
name: userData.name,
avatar_url: userData.avatar_url,
followers: userData.followers,
following: userData.following,
public_repos: userData.public_repos,
html_url: userData.html_url,
});
setUserInfo(userData);

로 묶을수있게 반환받았으면 좋겟다!

isSearch={isSearch}
placeholder="Search User..."
/>
{openHistory && (
Copy link
Member

Choose a reason for hiding this comment

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

요기는 왜 isOpenHistory로 안하고 변수명 다르게 한 이유가 있을까?!

}
`;

const StHistoryCard = styled.div`
Copy link
Member

Choose a reason for hiding this comment

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

article이 더 명확하겟지요?!

Comment on lines +5 to +14
const {
login,
name,
avatar_url,
html_url,
followers,
following,
public_repos,
} = userInfo;

Copy link
Member

Choose a reason for hiding this comment

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

아하 이거때매 props라고 햇는데 사실 이거 서버로부터 받아오는 타입이라 여기서는props 단어를 빼주어야 할것같아!

Comment on lines +23 to +26
<StUserName>
<h1>{login}</h1>
<p>{name}</p>
</StUserName>
Copy link
Member

Choose a reason for hiding this comment

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

이거 h1 태그 있어서 내려서 밧는데 header가 아니도라고?!

<h1>{login}</h1>
<p>{name}</p>
</StUserName>
<StUserVisitBtn onClick={visitHandler}>Visit {login}</StUserVisitBtn>
Copy link
Member

Choose a reason for hiding this comment

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

버튼 타입어디갓고!!ㅋㅎㅋㅎ


return (
<StUserInfoWrapper>
<StUserImg src={avatar_url} />
Copy link
Member

Choose a reason for hiding this comment

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

alt태그 어디갓는데,,,ㅠㅠ

Copy link
Member Author

Choose a reason for hiding this comment

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

alt태그 어디갓는데,,,ㅠㅠ

타스로 변환만 하다가 기본적인 것들을 수정 안하고 허술하게 넘어갔네 얼른 반영할게 쏘리;; ㅜ

Comment on lines +63 to +65
const deleteHistoryHanlder = (e: {
target: { parentNode: { textContent: string } };
}) => {
Copy link
Member

Choose a reason for hiding this comment

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

이것두,,, 구조분해할당으로 한건가??!

Choose a reason for hiding this comment

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

저어도 e: {target: { parentNode: { textContent: string } 요 부분이 어떤 구조인지 궁금해요오!

@Brokyeom
Copy link
Member Author

아;; ㅋㅋㅋㅜㅜ 충분히 고민 안하고 타스 변환만 급하게 하다보니 alt 나 웹접근성 등 기존 과제에서 허술했던 부분을 수정을 안하고 변환만 했네요 오늘 잠들기전까지 반영하고 리팩토링 들어갑니다 고마워!!!

Copy link

@pinktopaz pinktopaz left a comment

Choose a reason for hiding this comment

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

여행 갔다와서 제대로 쉬지도 못했을텐데 호다닥 하느라 수고 많았어 시루~!
코드 보면서 많이 배워갑니다아✨

const GlobalStyle = createGlobalStyle`
${reset};

html,

Choose a reason for hiding this comment

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

html과 body 모두에 적용해준 이유가 있을까요! html이 body를 감싸고 있어서 html에만 적용해도 적용이 될 것 같은데...! (아니라면 말씀해주셔요)

font-size: 62.5%;
}

* {

Choose a reason for hiding this comment

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

먼가 * -> html -> body -> 세부 태그 요런 식으로 순서를 맞춰서 쓰면 더 가독성이 좋을 것 같은 느낌!

function Search() {
const navigate = useNavigate();
const [historyArr, setHistoryArr] = useState<string[]>([]);
const [openHistory, setOpenHistory] = useState<boolean>(false);

Choose a reason for hiding this comment

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

현지 pr에 서히가 달아준 코드리뷰에서 쇽샥!

boolean 네이밍 규칙 is를 붙여주면 좋을 것 같아요오

Comment on lines +63 to +65
const deleteHistoryHanlder = (e: {
target: { parentNode: { textContent: string } };
}) => {

Choose a reason for hiding this comment

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

저어도 e: {target: { parentNode: { textContent: string } 요 부분이 어떤 구조인지 궁금해요오!

}) => {
setHistoryArr((usernames) =>
usernames.filter(
(username) => username !== e.target.parentNode.textContent.slice(0, -1)

Choose a reason for hiding this comment

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

slice(0,-1) 하면 맨뒤 요소 말하는 거 맞져?! 또 하나 배워갑니다아!

</StUserName>
<StUserVisitBtn onClick={visitHandler}>Visit {login}</StUserVisitBtn>
<StUserRate>
<StUserRateBlock>

Choose a reason for hiding this comment

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

요거 map 함수로 묶어줄 수 있을 것 같아!

{["Following", "Follower", "Repos"].map((info) => (
            <StUserRateBlock>
            <p>{info}</p>
            <span>
                {info === "Following"
                     ? following
                     : info === "Follower"
                     ? followers
                     : public_repos
                }
            </span>
            </StUserRateBlock>
        ))}

요런 식으로?! (혹시 해보고 틀리면 알려줘유,,,)

import ReactDOM from "react-dom/client";
import App from "./App";

ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(

Choose a reason for hiding this comment

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

여기 파일명이 index.tsx가 아니라 main.tsx로 되어있는데 혹시 index.tsx로 하지 않고 main.tsx로 하는 이유가 있나요?!
나도 보고 궁금해서 찾아봤는데 잘 안나와서!!ㅠㅜㅠ

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.

4 participants