Skip to content

Commit

Permalink
feat: market page all item list
Browse files Browse the repository at this point in the history
  • Loading branch information
swim-kim committed Sep 6, 2024
1 parent e7a5423 commit ba38ee9
Show file tree
Hide file tree
Showing 4 changed files with 204 additions and 9 deletions.
Binary file added src/assets/images/searchicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/components/Header/Header.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ header {
background: #FFF;
}
.header-container {
max-width:1520px;
max-width:1200px;
width:100%;
display:flex;
justify-content: space-between;
Expand Down
126 changes: 121 additions & 5 deletions src/pages/Market/Market.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
display:flex;
justify-content: center;
align-items: center;
margin-top:24px;
}
.bestitem-container {
.bestitem-container, .allitem-container {
max-width:1200px;
width:100%;
height:100%;
Expand All @@ -22,12 +23,14 @@
line-height: 32px;
}
.card-list {
width:100%;
display: flex;
flex-wrap:wrap;
align-items: flex-start;
gap: 24px;
gap: 23px;
height:100%;
}
.card-container {
.bestitem .card-container {
width:282px;
height:373px;
display: flex;
Expand All @@ -36,10 +39,16 @@
gap: 16px;
background: #FCFCFC;
}
.allitem .card-container {
width:221px;
height:317px;
}

.item-img {
width:282px;
height:282px;
width:100%;
height:70%;
border-radius: 16px;
object-fit: cover;
}
.title {
color: var(--Secondary-800, #1F2937);
Expand Down Expand Up @@ -74,7 +83,111 @@
font-weight: 500;
line-height: 18px;
}
.allitem {
width:100%;
height:674px;
display:flex;
justify-content: center;
align-items: center;
margin-top:40px;
}
.allitem-header {
width:100%;
height:42px;
display:flex;
justify-content: space-between;
}
.allitem-header-right {
width:612px;
display:flex;
gap:12px;
}
.search-container {
display: flex;
width: 325px;
height: 100%;
justify-content: flex-start;
align-items: center;
gap: 10px;
border-radius: 12px;
background: var(--Secondary-100, #F3F4F6);
}
.search-icon {
width:24px;
height:24px;
margin-left:16px;
background: var(--Secondary-100, #F3F4F6);
}
.search-input {
width: 174px;
height: 24px;
color: var(--Secondary-400, #9CA3AF);
background: var(--Secondary-100, #F3F4F6);
font-family: Pretendard;
font-size: 16px;
font-style: normal;
font-weight: 400;
line-height: 26px;
border:none;
}
.additem-button {
width:133px;
display: flex;
height: 42px;
justify-content: center;
align-items: center;
gap: 10px;

border-radius: 8px;
background: var(--Primary-100, #3692FF);
text-decoration: none;
color: var(--Cool-Gray-100, #F3F4F6);

font-family: Pretendard;
font-size: 16px;
font-style: normal;
font-weight: 600;
line-height: 26px;
}
.dropdown-container {
z-index: 999;
}
.dropdown-button {
display: flex;
width: 130px;
height: 42px;

justify-content: center;
align-items: center;
gap: 10px;
flex-shrink: 0;
border-radius: 12px;
border: 1px solid var(--Cool-Gray-200, #E5E7EB);
background: #FFF;

color: var(--Secondary-800, #1F2937);
font-size: 16px;
font-weight: 400;
line-height: 26px;
}
.dropdown-menu {
z-index:10;
list-style: none;
display: none;
border-radius: 12px;
border: 1px solid var(--Cool-Gray-200, #E5E7EB);

}
.dropdown-menu.show {
display: block;
}
.dropdown-option {
color: var(--Secondary-800, #1F2937);
font-size: 16px;
font-weight: 400;
line-height: 26px;
margin-left:30px;
}
/* tablet */
@media (max-width:1199px) {
.bestitem-container {
Expand All @@ -97,6 +210,9 @@

/* mobile */
@media (max-width:767px) {
.bestitem {
margin-top:16px;
}
.bestitem-container {
max-width:343px;
}
Expand Down
85 changes: 82 additions & 3 deletions src/pages/Market/components/AllItem.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,89 @@
import React, { useState } from 'react'
import React, { useState,useEffect, useCallback } from 'react';
import SearchIcon from '../../../assets/images/searchicon.png';
import { Link } from 'react-router-dom';
import ItemCard from './ItemCard';
import { getProducts } from '../../../api/itemApi';

const getPageSize = () => {
const width = window.innerWidth;
if(width < 767) {
return 4;
} else if (width < 1280) {
return 6;
} else {
return 10;
}
};

function AllItem() {
const [itemList, setItemList] = useState([]);
const [pageSize, setPageSize] = useState(getPageSize());
const [order, setOrder] = useState('recent');
const [selected, setSelected] = useState('최신순');
const [dropdownOpen, setDropdownOpen] = useState(false);

const handleNewestClick = () => {
setOrder('recent');
setSelected('최신순');
setDropdownOpen(false);
};

const handleFavoriteClick = () => {
setOrder('favorite');
setSelected('좋아요순');
setDropdownOpen(false);
};

const fetchSortedData = useCallback(async () => {
const products = await getProducts({ orderBy:order, pageSize});
setItemList(products.list);
},[order, pageSize]);
useEffect(() => {
const handleResize = () => {
setPageSize(getPageSize());
};
window.addEventListener("resize",handleResize);
fetchSortedData();
return () => {
window.removeEventListener("resize", handleResize);
};
},[fetchSortedData])

const toggleDropdown = () => {
setDropdownOpen(!dropdownOpen);
};

return (
<div>AllItem</div>
<div className="allitem">
<div className="allitem-container">
<div className="allitem-header">
<h3 className='list-title'>전체 상품</h3>
<div className="allitem-header-right">
<div className="search-container">
<img className="search-icon" src={SearchIcon} alt="검색"></img>
<input className='search-input' placeholder='검색할 상품을 입력해주세요'></input>
</div>
<Link className="additem-button" to="/additem">상품 등록하기</Link>
<div className="dropdown-container">
<button className="dropdown-button" onClick={toggleDropdown}>
{selected} <span className="dropdown-arrow"></span>
</button>
<ul className={`dropdown-menu ${dropdownOpen ? 'show' : ''}`}>
<li className="dropdown-option" onClick={handleNewestClick}>최신순</li>
<li className="dropdown-option" onClick={handleFavoriteClick}>좋아요순</li>
</ul>
</div>
</div>
</div>
<div className="card-list">
{itemList?.map((item) => (
<ItemCard key={item.id} item={item}/>
))}
</div>

</div>
</div>
)
}

export default AllItem
export default AllItem;

0 comments on commit ba38ee9

Please sign in to comment.