-
Notifications
You must be signed in to change notification settings - Fork 40
[이준희] Sprint12 #346
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
The head ref may contain hidden characters: "Next-\uC774\uC900\uD76C-sprint12"
[이준희] Sprint12 #346
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 |
|---|---|---|
|
|
@@ -34,8 +34,8 @@ export default function AddItemForm({ | |
| values.tags.length > 0; | ||
|
|
||
| const handleChange = (name: string, value: any) => { | ||
| setValues((initialValues) => ({ | ||
| ...initialValues, | ||
| setValues((prevState) => ({ | ||
| ...prevState, | ||
| [name]: value, | ||
| })); | ||
| }; | ||
|
|
@@ -78,16 +78,19 @@ export default function AddItemForm({ | |
|
|
||
| const handleSubmit = async (e: React.FormEvent) => { | ||
| e.preventDefault(); | ||
|
|
||
| const formData = new FormData(); | ||
| formData.append("name", values.name); | ||
| formData.append("favorite", values.favoriteCount.toString()); | ||
| formData.append("description", values.description); | ||
| formData.append("price", values.price.toString()); | ||
|
|
||
| if (values.images) { | ||
| values.images.forEach((image, index) => { | ||
| formData.append(`images[${index}]`, image); | ||
| }); | ||
| } | ||
|
|
||
|
Comment on lines
+81
to
+93
Collaborator
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. 개행 잘해주셔서 가독성이 더 좋아진 것 같습니다. |
||
| formData.append("tags", JSON.stringify(values.tags)); | ||
|
|
||
| const result = await onSubmit(formData); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,9 @@ import getPageSize from "@/lib/utils/getPageSize"; | |
|
|
||
| export default function BestArticles() { | ||
| const [articles, setArticles] = useState<Article[]>([]); | ||
| const [pageSize, setPageSize] = useState<number>(getPageSize("article")); | ||
| const [pageSize, setPageSize] = useState<number>(() => | ||
| getPageSize("article") | ||
| ); | ||
|
Comment on lines
+14
to
+16
Collaborator
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. useState 내부에 콜백 함수 잘 사용해주셨네요. |
||
|
|
||
| useEffect(() => { | ||
| const fetchArticles = async ({ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,4 +18,25 @@ instance.interceptors.request.use( | |
| (error) => Promise.reject(error) | ||
| ); | ||
|
|
||
| instance.interceptors.response.use( | ||
|
Collaborator
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. interceptor 기능을 잘 활용해주셨네요! |
||
| (response) => { | ||
| return response; | ||
| }, | ||
| (error) => { | ||
| if (error.response) { | ||
| const { status, data } = error.response; | ||
|
|
||
| if (status === 401) { | ||
| // 로컬 스토리지에서 토큰 제거 | ||
| localStorage.removeItem("accessToken"); | ||
|
Collaborator
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. localStorage에서 사용하는 키 값도 상수로 관리해주셔도 좋을 것 같습니다. |
||
| // 로그인 페이지로 리디렉션 | ||
| if (typeof window !== "undefined") { | ||
| window.location.href = "/login"; | ||
| } | ||
| } | ||
| } | ||
| return Promise.reject(error); | ||
| } | ||
| ); | ||
|
|
||
| export default instance; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,23 @@ | ||
| export default function getPageSize(context = "default") { | ||
| if (typeof window === "undefined") return context === "default" ? 3 : 10; | ||
| type Context = "default" | "article" | "item"; | ||
|
|
||
| const width = window.innerWidth; | ||
| const pageSize: Record< | ||
| Context, | ||
| { small: number; medium: number; large: number } | ||
| > = { | ||
| article: { small: 1, medium: 2, large: 3 }, | ||
| item: { small: 1, medium: 2, large: 4 }, | ||
| default: { small: 4, medium: 6, large: 10 }, | ||
| }; | ||
|
|
||
| if (context === "article") { | ||
| if (width < 768) return 1; | ||
| if (width < 1280) return 2; | ||
| return 3; | ||
| export default function getPageSize(context: Context = "default"): number { | ||
| if (typeof window === "undefined") { | ||
| return context === "default" ? 3 : 10; | ||
| } | ||
|
|
||
| if (context === "item") { | ||
| if (width < 768) return 1; | ||
| if (width < 1280) return 2; | ||
| return 4; | ||
| } | ||
| const width = window.innerWidth; | ||
| const size = pageSize[context]; | ||
|
|
||
| if (width < 768) return 4; | ||
| if (width < 1280) return 6; | ||
| return 10; | ||
| if (width < 768) return size.small; | ||
| if (width < 1280) return size.medium; | ||
| return size.large; | ||
|
Comment on lines
+13
to
+22
Collaborator
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. 상수를 잘 활용해서 코드가 많이 줄어든 것 같습니다. |
||
| } | ||
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.
좀 더 직관적인 이름으로 잘 수정해주셨네요~