Skip to content

Commit

Permalink
Merge pull request #211 from Jaeheon96/React-손재헌-sprint7
Browse files Browse the repository at this point in the history
[손재헌] sprint7
  • Loading branch information
wlgns2223 authored Jul 8, 2024
2 parents 332eb31 + 4062c4b commit 1b113fa
Show file tree
Hide file tree
Showing 31 changed files with 985 additions and 91 deletions.
115 changes: 101 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"react-helmet": "^6.1.0",
"react-router-dom": "^6.24.0",
"react-scripts": "5.0.1",
"styled-components": "^6.1.11",
"web-vitals": "^2.1.4"
},
"scripts": {
Expand Down
6 changes: 5 additions & 1 deletion src/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ import HomePage from "./pages/HomePage";
import ItemsPage from "./pages/ItemsPage";
import AddItemPage from "./pages/AddItemPage";
import App from "./components/App";
import ItemPage from "./pages/ItemPage";

function Main() {
return (
<BrowserRouter>
<Routes>
<Route path="/" element={<App />}>
<Route index element={<HomePage />} />
<Route path="items" element={<ItemsPage />} />
<Route path="items">
<Route index element={<ItemsPage />} />
<Route path=":itemId" element={<ItemPage />} />
</Route>
<Route path="additem" element={<AddItemPage />} />
</Route>
</Routes>
Expand Down
23 changes: 21 additions & 2 deletions src/api/api.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const BASE_URL = "https://panda-market-api.vercel.app";

async function getProducts({ page = 1, pageSize = 10, orderBy = '', keyword = '' }) {
async function getProducts({ page = 1, pageSize, orderBy = '', keyword = '' }) {

const query = `?page=${page}&pageSize=${pageSize}&orderBy=${orderBy}&keyword=${keyword}`
const response = await fetch(`${BASE_URL}/products` + query);
Expand All @@ -22,4 +22,23 @@ async function postProducts(formData) {
return result;
}

export { getProducts, postProducts };
async function getProductById(id) {

const response = await fetch(`${BASE_URL}/products/${id}`)
if (!response.ok) throw new Error("데이터를 불러오는데 실패했습니다.");
const result = await response.json();

return result;
}

async function getComments({ productId, limit = 10, cursor = 0 }) {

const query = `/products/${productId}/comments?limit=${limit}&cursor=${cursor}`;
const response = await fetch(`${BASE_URL}${query}`);
if (!response.ok) throw new Error("데이터를 불러오는데 실패했습니다.");
const result = await response.json();

return result;
}

export { getProducts, postProducts, getProductById, getComments };
Binary file added src/assets/Img_inquiry_empty.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/assets/ic_back.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/assets/ic_sort.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/assets/panda_blog-imagery-_21_Khajitted.jpg
Binary file not shown.
16 changes: 16 additions & 0 deletions src/components/ErrorScreen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import styles from "./ErrorScreen.module.css";
import pandaIsConfused from "../assets/Img_inquiry_empty.png"

function ErrorScreen({ error }) {

return (
<div className={styles.errorComponent}>
<img src={pandaIsConfused} alt="열일하는 판다" />
{error.message
? <span className={styles.errorMessage}>{error.message}</span>
: <span className={styles.errorMessage}>요청을 수행하는데 오류가 발생했습니다.</span>}
</div>
)
}

export default ErrorScreen;
14 changes: 14 additions & 0 deletions src/components/ErrorScreen.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.errorComponent {
width: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
margin-bottom: 1.5rem;

.errorMessage {
font-size: 1rem;
font-weight: 400;
color: var(--gray400);
}
}
Loading

0 comments on commit 1b113fa

Please sign in to comment.