Skip to content

Commit

Permalink
Merge pull request #213 from Injaeeee/React-정인재-Sprint7
Browse files Browse the repository at this point in the history
[정인재] Sprint7
  • Loading branch information
JaeSang1998 authored Jul 8, 2024
2 parents a508df1 + b5695c3 commit c7b4e82
Show file tree
Hide file tree
Showing 27 changed files with 481 additions and 79 deletions.
15 changes: 0 additions & 15 deletions .github/delete-merged-branch-config.yml

This file was deleted.

7 changes: 6 additions & 1 deletion src/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import App from "./components/App";
import Items from './pages/Items';
import AddItems from './pages/AddItem';
import NotFound from './pages/NotFound';
import Products from './pages/Products';

function Main() {

Expand All @@ -11,8 +12,12 @@ function Main() {
<Routes>
<Route path='/' element={<App />} >
<Route index></Route>
<Route path='items' element={<Items />}></Route>
<Route path='items'>
<Route index element={<Items />}></Route>
<Route path=':productSlug' element={<Products />}></Route>
</Route>
<Route path='additem' element={<AddItems />}></Route>

<Route path='*' element={<NotFound />}></Route>
</Route>
</Routes>
Expand Down
21 changes: 16 additions & 5 deletions src/api.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
const BASE_URL = 'https://panda-market-api.vercel.app';

export async function getProducts(order = 'recent') {
export async function getProducts({ order = 'recent', page = 1, pageSize }) {

const query = `orderBy=${order}`;
const response = await fetch(`${BASE_URL}/products?${query}`);
const response = await fetch(`${BASE_URL}/products?${query}&page=${page}&pageSize=${pageSize}`);
const body = await response.json();
return body;
}

export async function getProduct(productSlug) {
const response = await fetch(`${BASE_URL}/products/${productSlug}`);
const body = await response.json();
return body;
}

export async function createProducts(formData) {

export async function getComment(productSlug) {
const response = await fetch(`${BASE_URL}/products/${productSlug}/comments?limit=10`)
const body = await response.json();
return body;

}

export async function createProducts(formData) {

const response = await fetch(`${BASE_URL}/products?`,
{
Expand All @@ -21,5 +33,4 @@ export async function createProducts(formData) {
const body = await response.json();
return body;

}

}
2 changes: 1 addition & 1 deletion src/components/App.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import Topbar from './Topbar';
import Topbar from './Topbar/Topbar'
import './App.css';
import { Outlet } from 'react-router-dom';

Expand Down
32 changes: 0 additions & 32 deletions src/components/BestProductList.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
display: flex;
flex-direction: column;
padding: 24px 0;
border: 0;
background-color: transparent;
}

.BestProductListItem p,
Expand Down
52 changes: 52 additions & 0 deletions src/components/BestProductList/BestProductList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { useEffect, useState } from 'react';
import { getProducts } from '../../api';
import { Link, useNavigate } from 'react-router-dom';
import './BestProductList.css';

function BestProductListItem({ item }) {
const navigate = useNavigate();
const handleAddItemClick = () => {
navigate(`/items/${item.id}`);
}

return (
<button onClick={handleAddItemClick} className='BestProductListItem'>
<img className="BestProductListItem-img" src={item.images} alt={item.name}></img>
<p> {item.name}</p>
<h3>{item.price}</h3>
<p>{item.favoriteCount}</p>
</button>
);

}

function BestProductList() {


const [items, setItems] = useState([]);

const handleLoad = async () => {
const { list } = await getProducts({ order: 'favorite', page: 1, pageSize: 10 });
setItems(list);
}


useEffect(() => {
handleLoad();
}, []);

const displayedItems = items.slice(0, 4);
return (

<div className='BestProductList'>
{displayedItems.map((item) => {
return (
<BestProductListItem key={item.id} item={item} />

);
})}
</div>
)
}

export default BestProductList;
10 changes: 10 additions & 0 deletions src/components/Button.css → src/components/Button/Button.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,13 @@
font-size: 18px;
font-weight: 700;
}

.disable {
background-color: #9ca3af;
color: #ffffff;
}

.inquiry {
width: 74px;
align-self: flex-end;
}
4 changes: 2 additions & 2 deletions src/components/Button.js → src/components/Button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import './Button.css';



function Button({ children, onClick, select = '' }) {
const classNames = `Button ${select}`;
function Button({ children, onClick, select = '', width = '' }) {
const classNames = `Button ${select} ${width}`;
return (
<button className={classNames} onClick={onClick}>
{children}
Expand Down
43 changes: 43 additions & 0 deletions src/components/CommentList/CommentList.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
.commentWrapper {
display: flex;
flex-direction: column;
gap: 15px;
border-bottom: 1px solid #e5e7eb;
margin: 20px 0;
}

.commentImg {
width: 40px;
height: 40px;
}

.writerWrapper {
display: flex;
flex-direction: row;
gap: 8px;
margin: 20px 0;
}
.writer {
display: flex;
flex-direction: column;
gap: 4px;
}

.commenContent {
font-size: 16px;
font-weight: 400;
color: #1f2937;
}

.emptyComment {
display: flex;
flex-direction: column;
align-items: center;
}

.emptyCommentText {
font-size: 16px;
font-weight: 400;
line-height: 24px;
color: #9ca3af;
}
57 changes: 57 additions & 0 deletions src/components/CommentList/CommentList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { useEffect, useState } from 'react';
import { getComment } from '../../api';
import emptyComment from '../../img/Img_inquiry_empty.png'
import './CommentList.css';

function CommentListItem({ item }) {


return (
<div className='commentWrapper'>
<span className='commentContent'> {item.content}</span>

<div className='writerWraaper'>
<img src={item.writer.image} className='commentImg'></img>
<div className='writer'>
<span className='writerNickname'>{item.writer.nickname}</span>
<span className='updatedAt'>{item.updatedAt}</span>
</div>
</div>

</div>
);

}

function CommentList({ productSlug }) {


const [items, setItems] = useState([]);


const handleLoad = async () => {
const { list } = await getComment(productSlug);
setItems(list);
}

useEffect(() => {
handleLoad();
}, []);

return (

<div>
{items.length > 0 ? (items.map((item) => {
return (

<CommentListItem key={item.id} item={item} />
);
})) : (<div className='emptyComment'>
<img src={emptyComment}></img>
<span className='emptyCommentText'>아직 문의가 없습니다.</span>
</div>)}
</div>
)
}

export default CommentList;
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function FileInput({ name, value, onChange }) {
if (!inputNode) return;

inputNode.value = '';

setPreview(null);
onChange(name, null);

Expand All @@ -26,6 +27,7 @@ function FileInput({ name, value, onChange }) {
if (!value) return;

const nextpreview = URL.createObjectURL(value);

setPreview(nextpreview);

}, [value])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
display: flex;
flex-direction: column;
padding: 24px 0;
border: 0;
background-color: transparent;
}

.ProductListItem p,
Expand All @@ -23,7 +25,7 @@
padding: 0;
}

@media (max-width: 744px) {
@media (max-width: 1000px) {
.ProductList {
width: 696px;
display: grid;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
import './ProductList.css';
import { useNavigate } from 'react-router-dom';

function ProductListItem({ item }) {

const navigate = useNavigate();
const handleAddItemClick = () => {
navigate(`/items/${item.id}`);
}


return (
<div className='ProductListItem'>
<button onClick={handleAddItemClick} className='ProductListItem'>
<img className="ProductListItem-img" src={item.images} alt={item.name}></img>
<p> {item.name}</p>
<h3>{item.price}</h3>
<h3>{item.price}</h3>
<p>{item.favoriteCount}</p>
</div>
</button>
);

}

function ProductList({ items }) {


return (

<div className='ProductList'>
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/components/Topbar.js → src/components/Topbar/Topbar.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pandaLogo from '../img/logo.png';
import pandaLogo from '../../img/logo.png';
import './Topbar.css';
import Button from './Button'
import Button from '../Button/Button';
import { Link } from 'react-router-dom';

function Topbar() {
Expand Down
12 changes: 12 additions & 0 deletions src/components/pageNation/PageNation.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.pageButton {
width: 40px;
height: 40px;
border-radius: 40px;
background-color: #ffffff;
border: #e5e7eb 1px solid;
}

.active {
background-color: #3692ff;
color: #ffffff;
}
Loading

0 comments on commit c7b4e82

Please sign in to comment.