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

[박지민] sprint10 #657

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["next/babel"],
"plugins": [["styled-components", { "ssr": true }]]
}
92 changes: 92 additions & 0 deletions components/Header.tsx
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는 컴포넌트 하단에 작성해주시는 것이 좋습니다. styled-component가 많아 질수록 컴포넌트 코드가 하단에 배치되서 찾아가기 힘들어지기 때문입니다!

Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import Logo from "@/public/logo.svg";
import Link from "next/link";
import { useRouter } from "next/router";
import styled from "styled-components";
import profileImg from "@/public/btn_visibility.svg";
import Image from "next/image";

const GlobalHeader = styled.header`
display: flex;
justify-content: space-between;
align-items: center;
`;

const HeaderLeft = styled.div`
display: flex;
align-items: center;
`;

const HeaderLogo = styled(Link)`
margin-right: 16px;

@media (min-width: 768px) {
margin-right: 35px;
}

@media (min-width: 1280px) {
margin-right: 47px;
}
`;

const NavList = styled.ul`
display: flex;
list-style: none;
gap: 6px;
font-weight: bold;
font-size: 16px;
color: var(--gray-600);

@media (min-width: 768px) {
gap: 36px;
font-size: 18px;
}
`;

const NavItem = styled.li`
a:hover {
color: var(--blue);
}
`;
const HeaderRight = styled.div`
margin-right: 16px;
`;
function getLinkStyle(isActive: boolean) {
return { color: isActive ? "var(--blue)" : undefined };
}
Comment on lines +53 to +55
Copy link
Collaborator

Choose a reason for hiding this comment

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

style을 적용하기 위해 공통으로 사용될 함수를 잘 만들어주셨네요!


export default function Header() {
const { pathname } = useRouter();

return (
<GlobalHeader>
<HeaderLeft>
<HeaderLogo href="/" aria-label="홈으로 이동">
<Logo alt="판다마켓 로고" width="153" />
</HeaderLogo>

<nav>
<NavList>
<NavItem>
<Link href="/boards" style={getLinkStyle(pathname === "/boards")}>
자유게시판
</Link>
</NavItem>
<NavItem>
<Link
href="/items"
style={getLinkStyle(
pathname.includes("/items") || pathname === "/additem"
)}
>
중고마켓
</Link>
</NavItem>
</NavList>
</nav>
</HeaderLeft>
<HeaderRight>
<Image src={profileImg} alt="프로필" width={50} />
Copy link
Collaborator

Choose a reason for hiding this comment

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

next/image는 크기값을 줘야하기 때문에 width와 height 둘 다 작성해주시는 것을 추천드립니다.

</HeaderRight>
</GlobalHeader>
);
}
30 changes: 30 additions & 0 deletions components/fileInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { useEffect, useState } from "react";
import Image from "next/image";

export default function AddImage() {
const [imgSrc, setimgSrc] = useState<string>("/images/default-image.png");
Copy link
Collaborator

Choose a reason for hiding this comment

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

상태를 문자열로 초기화 해주시는 경우, 타입추론에 의해서 상태가 string으로 추론 되기 때문에 useState에 string 타입을 명시해주시지 않아도 괜찮습니다!


const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const file = e.target.files?.[0];
if (!file) return;
const fileReader = new FileReader();
fileReader.readAsDataURL(file);
fileReader.onload = (e) => {
if (typeof e.target?.result === "string") {
setimgSrc(e.target?.result);
}
};
};

useEffect(() => {
console.log(imgSrc);
}, [imgSrc]);
Comment on lines +19 to +21
Copy link
Collaborator

Choose a reason for hiding this comment

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

console.log는 제거해주시는 것을 추천드립니다!


return (
<div>
<h2>이미지</h2>
<input type="file" accept="image/*" onChange={handleChange} />
<Image src={imgSrc} alt="" width={200} height={150} priority />
Copy link
Collaborator

Choose a reason for hiding this comment

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

priority 옵션 잘 사용해주셨네요.

</div>
);
}
Loading
Loading