-
Notifications
You must be signed in to change notification settings - Fork 35
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
[정인재] Sprint11 #322
The head ref may contain hidden characters: "Next-\uC815\uC778\uC7AC-Sprint11"
[정인재] Sprint11 #322
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,15 @@ import styled from "styled-components"; | |
import Image from "next/image"; | ||
import plusIcon from "@/images/ic_plus.svg"; | ||
import { FileInputType } from "@/interfaces/article"; | ||
import { postImage } from "@/pages/util/api"; | ||
|
||
function FileInput({ value, onChange }: FileInputType) { | ||
function FileInput({ value, fileChange, previewChange }: FileInputType) { | ||
const inputRef = useRef<HTMLInputElement | null>(null); | ||
const [preview, setPreview] = useState<string | null>(null); | ||
|
||
const handleChange = (e: ChangeEvent<HTMLInputElement>) => { | ||
const nextValue = e.target.files ? e.target.files[0] : null; | ||
onChange(nextValue); | ||
fileChange(nextValue); | ||
}; | ||
|
||
const handleClearClick = () => { | ||
|
@@ -22,7 +23,7 @@ function FileInput({ value, onChange }: FileInputType) { | |
inputNode.value = ""; | ||
|
||
setPreview(null); | ||
onChange(null); | ||
fileChange(null); | ||
}; | ||
|
||
useEffect(() => { | ||
|
@@ -31,7 +32,8 @@ function FileInput({ value, onChange }: FileInputType) { | |
const nextpreview = URL.createObjectURL(value); | ||
|
||
setPreview(nextpreview); | ||
console.log(nextpreview); | ||
previewChange(nextpreview); | ||
// console.log(nextpreview); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 불필요한 주석은 지워주시면 좋을 것 같습니다. |
||
|
||
// 메모리 누수를 방지하기 위해 URL 객체를 해제 | ||
return () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,11 @@ export default function PrimaryButton({ | |
disabled: disabled = false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기는 disabled = false 이런식으로 작성해주셔도 똑같이 동작합니다! |
||
onClick, | ||
}: ButtonProps) { | ||
return <Button disabled={disabled}>{children}</Button>; | ||
return ( | ||
<Button disabled={disabled} onClick={onClick}> | ||
{children} | ||
</Button> | ||
); | ||
} | ||
|
||
const Button = styled.button<{ disabled: boolean }>` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { ChangeEventHandler, FocusEventHandler } from "react"; | ||
import styled from "styled-components"; | ||
|
||
interface InputType { | ||
id: string; | ||
name: string; | ||
type: string; | ||
placeholder: string; | ||
onChange?: ChangeEventHandler<HTMLInputElement>; | ||
onBlur?: FocusEventHandler<HTMLInputElement>; | ||
hasError?: boolean; | ||
} | ||
|
||
export default function PrimaryInput({ | ||
id, | ||
name, | ||
type, | ||
placeholder, | ||
onChange, | ||
onBlur, | ||
hasError, | ||
}: InputType) { | ||
return ( | ||
<Input | ||
id={id} | ||
name={name} | ||
type={type} | ||
placeholder={placeholder} | ||
onChange={onChange} | ||
onBlur={onBlur} | ||
hasError={hasError} | ||
/> | ||
); | ||
} | ||
|
||
const Input = styled.input<{ hasError?: boolean }>` | ||
width: 100%; | ||
border-radius: 12px; | ||
padding: 16px 24px; | ||
background-color: #f3f4f6; | ||
color: #9ca3af; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 컬러 변수가 누락된 곳이 종종 있는데, 혹시 사용하지 않고 계시다면 사용해보셔도 좋을 것 같습니다. 컬러를 변수로 관리 하신다면 색상 수정할때 한번에 수정할 수 있거든요. |
||
font-size: 16px; | ||
font-weight: 400; | ||
border: ${({ hasError }) => (hasError ? "1px solid red" : "none")}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hasError가 undefined가 올 수도 있기 때문에 !!hasError 이런식으로 작성해주시면 확실하게 boolean으로 판단이 가능해집니다. |
||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,48 @@ | ||
import PrimaryButton from "./primarybutton"; | ||
import pandaLogo from "@/images/logo.png"; | ||
import mobilePandaLogo from "@/images/mobilelogo.png"; | ||
import userIcon from "@/images/user.png"; | ||
import Link from "next/link"; | ||
import Image from "next/image"; | ||
import styled from "styled-components"; | ||
import { isLoggedIn } from "@/pages/util/api"; | ||
import { useEffect, useState } from "react"; | ||
import PrimaryButton from "./primarybutton"; | ||
|
||
export default function Topbar() { | ||
const [isLogin, setIsLogin] = useState(false); | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
useEffect(() => { | ||
if (isLoggedIn() == true) { | ||
setIsLogin(true); | ||
} else { | ||
setIsLogin(false); | ||
} | ||
}, [isLogin]); | ||
|
||
const handleLogClick = () => { | ||
setIsOpen((prev) => !prev); | ||
}; | ||
|
||
const handleLogoutClick = () => { | ||
setIsLogin(false); | ||
localStorage.removeItem("access_token"); | ||
localStorage.removeItem("refresh_token"); | ||
window.location.href = "/login"; // 로그아웃 후 리다이렉션 | ||
}; | ||
|
||
return ( | ||
<TopbarHeader> | ||
<LeftElement> | ||
<Link href="/"> | ||
<LogoWrapper> | ||
<Image src={pandaLogo} alt="Panda Logo" className="desktop" /> | ||
<Image | ||
src={pandaLogo} | ||
alt="Panda Logo" | ||
className="desktop" | ||
width={153} | ||
height={51} | ||
/> | ||
<Image | ||
src={mobilePandaLogo} | ||
alt="Mobile Panda Logo" | ||
|
@@ -29,8 +59,18 @@ export default function Topbar() { | |
</Link> | ||
</ButtonWrapper> | ||
</LeftElement> | ||
<Image src={userIcon} alt="userIcon" /> | ||
{/* <PrimaryButton>로그인</PrimaryButton> */} | ||
{isLogin ? ( | ||
<LogOutWrapper onClick={handleLogClick}> | ||
<Image src={userIcon} alt="userIcon" /> | ||
{isOpen && ( | ||
<LogOutButton onClick={handleLogoutClick}>로그아웃</LogOutButton> | ||
)} | ||
</LogOutWrapper> | ||
) : ( | ||
<Link href="/login"> | ||
<PrimaryButton>로그인</PrimaryButton> | ||
</Link> | ||
)} | ||
</TopbarHeader> | ||
); | ||
} | ||
|
@@ -99,3 +139,21 @@ const LogoWrapper = styled.div` | |
} | ||
} | ||
`; | ||
|
||
const LogOutWrapper = styled.div` | ||
position: relative; | ||
`; | ||
|
||
const LogOutButton = styled.button` | ||
position: absolute; | ||
width: 139px; | ||
height: 51px; | ||
border: solid 1px #d1d5db; | ||
border-radius: 8px; | ||
padding: 16px 0; | ||
margin-top: 50px; | ||
margin-left: -130px; | ||
font-size: 16px; | ||
Comment on lines
+154
to
+155
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. position이 absolute이기 때문에 margin 대신 left나 top 속성을 써보시는 것도 추천드립니다. |
||
font-weight: 400; | ||
background-color: #ffffff; | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
export interface articleType { | ||
title: string; | ||
content: string; | ||
image: string; | ||
image: string | null; | ||
} | ||
|
||
export interface FileInputType { | ||
value: File | null; | ||
onChange: (file: File | null) => void; | ||
fileChange: (file: File | null) => void; | ||
previewChange: (preview: string | null) => void; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export interface UserInfo { | ||
email: string; | ||
nickname?: string; | ||
password: string; | ||
passwordConfirmation?: string; | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 인터셉터를 활용해서 요청과 응답 시 공통되는 로직을 합쳐주신거 좋네요! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,52 @@ | ||
import axios from "axios"; | ||
import axios, { AxiosError } from "axios"; | ||
|
||
const instance = axios.create({ | ||
baseURL: " https://panda-market-api.vercel.app/", | ||
}); | ||
|
||
// 요청 인터셉터 | ||
instance.interceptors.request.use( | ||
(config) => { | ||
// 요청이 가기 전에 할 작업 | ||
// 예: 인증 토큰 추가 | ||
const token = localStorage.getItem("access_token"); | ||
if (token) { | ||
config.headers.Authorization = `Bearer ${token}`; | ||
} | ||
return config; | ||
}, | ||
(error) => { | ||
// 요청 에러 처리 | ||
return Promise.reject(error); | ||
} | ||
); | ||
|
||
// 응답 인터셉터 | ||
instance.interceptors.response.use( | ||
(response) => { | ||
// 응답 데이터 처리 | ||
return response; | ||
}, | ||
(error: AxiosError) => { | ||
// 응답 에러 처리 | ||
if (axios.isAxiosError(error)) { | ||
if (error.response) { | ||
// 서버 응답이 있는 경우 | ||
console.error("서버 에러:", error.response.data); | ||
alert("유효하지 않은 아이디 입니다."); | ||
} else if (error.request) { | ||
// 요청이 보내졌으나 응답이 없는 경우 | ||
console.error("요청 에러:", error.request); | ||
} else { | ||
// 에러를 발생시킨 요청 구성 문제 | ||
console.error("에러 구성:", error.message); | ||
} | ||
} else { | ||
// Axios가 아닌 다른 에러 | ||
console.error("기타 에러:", error); | ||
} | ||
return Promise.reject(error); | ||
} | ||
); | ||
|
||
export default instance; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
board에 image가 없는 경우 defaultImage를 잘 넣어주셨네요!
추가로 board에 image가 있더라도 이미지 로딩 시 에러가 발생했을때 defaultImage를 넣어주는 것도 반영해주시면 좋을 것 같습니다.