Skip to content
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
6 changes: 0 additions & 6 deletions React/package-lock.json

This file was deleted.

46 changes: 46 additions & 0 deletions React/panda-market/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Getting Started with Create React App

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.\
You will also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).
1,294 changes: 548 additions & 746 deletions React/panda-market/package-lock.json

Large diffs are not rendered by default.

18 changes: 13 additions & 5 deletions React/panda-market/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
{
"name": "panda-market",
"name": "panda-market-ts",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.2.0",
"@testing-library/user-event": "^13.5.0",
"@types/jest": "^27.5.2",
"@types/node": "^16.18.126",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-helmet": "^6.1.0",
"react-router-dom": "^7.3.0",
"react-scripts": "5.0.1",
"typescript": "^4.9.5",
"web-vitals": "^2.1.4"
},
"scripts": {
Expand Down Expand Up @@ -37,10 +42,13 @@
]
},
"devDependencies": {
"@types/lodash.debounce": "^4.0.9",
"@types/react": "^19.0.10",
"@types/react-dom": "^19.0.4",
"@types/react-helmet": "^6.1.11",
"ajv": "^7.2.4",
"axios": "^1.7.9",
"classnames": "^2.5.1",
"lodash.debounce": "^4.0.8",
"react-router-dom": "^6.28.1"
"lodash.debounce": "^4.0.8"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ function App() {

return (
<>
{!isAuthPage && <Header className={styles.nav} />}
{!isAuthPage && <Header />}
<div className={styles.body}>
<Outlet />
</div>
{isHomePage && <Footer className={styles.footer} />}
{isHomePage && <Footer />}
</>
);
}
Expand Down
File renamed without changes.
39 changes: 0 additions & 39 deletions React/panda-market/src/apis/itemApi.js

This file was deleted.

64 changes: 64 additions & 0 deletions React/panda-market/src/apis/itemApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import axios from "axios";
import { Product, Comment } from "../utils/types";

const instance = axios.create({
baseURL: "https://panda-market-api.vercel.app",
Copy link
Collaborator

Choose a reason for hiding this comment

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

base URL은 환경 변수에 저장하시는게 좋습니다!

환경 변수(Environment Variable): process.env에 내장되며 앱이 실행될 때 적용할 수 있는 값입니다!

다음과 같이 적용할 수 있습니다:

// .env.development
REACT_APP_BASE_URL="http://localhost:3000"

// .env.production
REACT_APP_BASE_URL="http://myapi.com"

// 사용시
<a href={`${process.env.REACT_APP_BASE_URL}/myroute`}>URL</a>

왜 환경 변수에 저장해야 하나요?

개발(dev), 테스트(test), 실제 사용(prod) 등 다양한 환경에서 앱을 운영하게 되는 경우, 각 환경에 따라 다른 base URL을 사용해야 할 수 있습니다. 만약 코드 내에 하드코딩되어 있다면, 각 환경에 맞춰 앱을 배포할 때마다 코드를 변경해야 하며, 이는 매우 번거로운 작업이 됩니다. 하지만, 환경 변수를 .env.production, .env.development, .env.test와 같이 설정해두었다면, 코드에서는 단지 다음과 같이 적용하기만 하면 됩니다.

const apiUrl = `${process.env.REACT_APP_BASE_URL}/api`;

이러한 방식으로 환경 변수를 사용하면, 배포 환경에 따라 쉽게 URL을 변경할 수 있으며, 코드의 가독성과 유지보수성도 개선됩니다.

실제 코드 응용과 관련해서는 다음 한글 아티클을 참고해보세요! => 보러가기

});

const COMMENTS_LIMIT = 3;

export interface GetItemsResponse {
list: Product[];
totalCount?: number;
}

export interface GetCommentsResponse {
list: Comment[] | null;
nextCursor: number | null;
}

export async function getItems({
page = "",
pageSize = "",
order = "",
}: {
page: string;
pageSize: string;
order: string;
Comment on lines +23 to +27
Copy link
Collaborator

Choose a reason for hiding this comment

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

(이어서) 여기도 타입을 "recent" | "favorite"로 하시면 어떨까요?

Suggested change
order = "",
}: {
page: string;
pageSize: string;
order: string;
order = "",
}: {
page: string;
pageSize: string;
order: "recent" | "favorite";

그리고 "recent" | "favorite"getItems 함에 필요한 타입이므로 타입 선언을 해당 파일에서 선언하셔도 될 것 같습니다 =)

}): Promise<GetItemsResponse> {
const query = new URLSearchParams({ page, pageSize, orderBy: order });
Copy link
Collaborator

Choose a reason for hiding this comment

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

굿굿 ! 피드백 반영 너무 좋습니다 ~! 😊

try {
const res = await instance.get(`/products?${query}`);
return res.data;
} catch (error) {
console.error(error);
throw error;
}
}

export async function getItemById(productId: string): Promise<Product> {
try {
const res = await instance.get(`/products/${productId}`);
return res.data;
} catch (error) {
console.error(error);
throw error;
}
}

export async function getItemComments(
productId: string,
{ cursor = 0 }: { cursor: number }
): Promise<GetCommentsResponse> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

오호 ~ 반환 타입을 정의하셨군요? 👍👍

const query = new URLSearchParams({
cursor: cursor.toString(),
limit: COMMENTS_LIMIT.toString(),
});
try {
const res = await instance.get(`/products/${productId}/comments?${query}`);
return res.data;
} catch (error) {
console.error(error);
throw error;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Link, NavLink, useLocation } from "react-router-dom";
import useWindowSize from "../..//hooks/useWindowSize";
import useWindowSize from "../../hooks/useWindowSize";
import BREAKPOINTS from "../../utils/breakpoints";
import PrimaryButton from "../UI/PrimaryButton";
import logoImg from "../../assets/logo/panda-market-logo.svg";
Expand All @@ -11,13 +11,13 @@ function Header() {
const { width } = useWindowSize();
const location = useLocation();

function communityLinkStyle({ isActive }) {
function communityLinkStyle({ isActive }: { isActive: boolean }) {
return {
color: isActive ? "var(--blue)" : "",
};
}

function marketLinkStyle({ isActive }) {
function marketLinkStyle({ isActive }: { isActive: boolean }) {
const isMarketRelatedPage = ["/items", "/additem"].includes(
location.pathname
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import DeleteIcon from "../../assets/icon/ic_delete.svg";
import styles from "./DeleteButton.module.css";

function DeleteButton({ className = "", onClick = () => {} }) {
interface DeleteButtonProps {
className?: string;
onClick?: React.MouseEventHandler<HTMLButtonElement>;
}

function DeleteButton({
className = "",
onClick = () => {},
}: DeleteButtonProps) {
return (
<button type="button" onClick={onClick} className={className}>
<img src={DeleteIcon} alt="" className={styles.deleteIcon} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import MenuIcon from "../../assets/icon/ic_menu.svg";
import styles from "./MenuButton.module.css";

function MenuButton({ className = "", onClick = () => {} }) {
interface MenuButtonProps {
className?: string;
onClick?: React.MouseEventHandler<HTMLButtonElement>;
}

function MenuButton({ className = "", onClick = () => {} }: MenuButtonProps) {
return (
<button
type="button"
Expand Down
18 changes: 0 additions & 18 deletions React/panda-market/src/components/UI/PrimaryButton.jsx

This file was deleted.

32 changes: 32 additions & 0 deletions React/panda-market/src/components/UI/PrimaryButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from "react";
import styles from "./PrimaryButton.module.css";

interface PrimaryButtonProps {
children: React.ReactNode;
className?: string;
onClick?: React.MouseEventHandler<HTMLButtonElement>;
disabled?: boolean;
type?: "button" | "submit" | "reset";
}

function PrimaryButton({
children,
className = "",
onClick = () => {},
disabled = false,
type = "submit",
}: PrimaryButtonProps) {
const buttonClass = `${styles.button} ${className}`;
return (
<button
type={type}
className={buttonClass}
onClick={onClick}
disabled={disabled}
>
{children}
</button>
);
}
Comment on lines +4 to +30
Copy link
Collaborator

Choose a reason for hiding this comment

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

다음과 같이 작성해볼 수도 있을 것 같아요 !

Suggested change
interface PrimaryButtonProps {
children: React.ReactNode;
className?: string;
onClick?: React.MouseEventHandler<HTMLButtonElement>;
disabled?: boolean;
type?: "button" | "submit" | "reset";
}
function PrimaryButton({
children,
className = "",
onClick = () => {},
disabled = false,
type = "submit",
}: PrimaryButtonProps) {
const buttonClass = `${styles.button} ${className}`;
return (
<button
type={type}
className={buttonClass}
onClick={onClick}
disabled={disabled}
>
{children}
</button>
);
}
interface PrimaryButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
className?: string;
children?: React.ReactNode;
}
function PrimaryButton({
children,
className = "",
}: PrimaryButtonProps) {
const buttonClass = `${styles.button} ${className}`;
return (
<button
type={type}
className={buttonClass}
{...rest}
>
{children}
</button>
);
}

ButtonHTMLAttributes<HTMLButtonElement> 타입으로 확장하면 컴파일 단계에서 버튼의 속성들만 받을 수 있도록 할 수 있습니다 😊


export default PrimaryButton;
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function useWindowSize(delay = 300) {
return () => {
window.removeEventListener("resize", handleResize);
};
}, []);
}, [delay]);

return windowSize;
}
Expand Down
6 changes: 0 additions & 6 deletions React/panda-market/src/index.js

This file was deleted.

11 changes: 11 additions & 0 deletions React/panda-market/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import ReactDOM from "react-dom/client";
import Main from "./Main";

const rootElement = document.getElementById("root");

if (rootElement) {
const root = ReactDOM.createRoot(rootElement);
root.render(<Main />);
} else {
console.error("Root element not found");
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function HomePage() {
<Helmet>
<title>판다마켓 - 일상의 모든 물건을 거래해 보세요</title>
</Helmet>
<div className={`${styles.banner} ${styles.top}`}>
<section className={`${styles.banner} ${styles.top}`}>
<div className={styles.wrapper}>
<div className={styles.bannerContainer}>
<div className={styles.bannerLeft}>
Expand All @@ -33,8 +33,8 @@ function HomePage() {
</div>
</div>
</div>
</div>
<div className={`${styles.features} ${styles.wrapper}`}>
</section>
<section className={`${styles.features} ${styles.wrapper}`}>
<div className={styles.feature}>
<img src={HomeImg1} width="68.5%" alt="인기 상품" />
<div className={styles.featureContent}>
Expand Down Expand Up @@ -71,8 +71,8 @@ function HomePage() {
</p>
</div>
</div>
</div>
<div className={`${styles.banner} ${styles.bottom}`}>
</section>
<section className={`${styles.banner} ${styles.bottom}`}>
<div className={styles.wrapper}>
<div className={styles.bannerContainer}>
<div className={styles.bannerLeft}>
Expand All @@ -87,7 +87,7 @@ function HomePage() {
</div>
</div>
</div>
</div>
</section>
</>
);
}
Expand Down
Loading
Loading