Skip to content
Open
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@emotion/react": "^11.10.5",
"@emotion/styled": "^11.10.5",
"@types/node": "^18.11.19",
"axios": "^1.3.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-query": "^3.39.3",
Expand Down
162 changes: 162 additions & 0 deletions public/mockdata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
[
{
"id": 1,
"imageUrl": "https://item.kakaocdn.net/do/493188dee481260d5c89790036be0e66f604e7b0e6900f9ac53a43965300eb9a",
"title": "test1",
"text": "test1",
"category": "test",
"limitDate": 7
},
{
"id": 2,
"imageUrl": "https://item.kakaocdn.net/do/493188dee481260d5c89790036be0e66effd194bae87d73dd00522794070855d",
"title": "test2",
"text": "test2",
"category": "test",
"limitDate": 7
},
{
"id": 3,
"imageUrl": "https://item.kakaocdn.net/do/493188dee481260d5c89790036be0e66b3a18fdf58bc66ec3f4b6084b7d0b570",
"title": "test3",
"text": "test3",
"category": "test",
"limitDate": 7
},
{
"id": 4,
"imageUrl": "https://item.kakaocdn.net/do/493188dee481260d5c89790036be0e668f324a0b9c48f77dbce3a43bd11ce785",
"title": "test4",
"text": "test4",
"category": "test",
"limitDate": 7
},
{
"id": 5,
"imageUrl": "https://item.kakaocdn.net/do/493188dee481260d5c89790036be0e66effd194bae87d73dd00522794070855d",
"title": "test5",
"text": "test5",
"category": "test",
"limitDate": 7
},
{
"id": 6,
"imageUrl": "https://item.kakaocdn.net/do/493188dee481260d5c89790036be0e669cbcbe2de7f4969efc79ab353e0c19e8",
"title": "test6",
"text": "test6",
"category": "test",
"limitDate": 7
},
{
"id": 7,
"imageUrl": "https://item.kakaocdn.net/do/493188dee481260d5c89790036be0e6671b950f0a05bd8dba8b11dbe535ebe4b",
"title": "test7",
"text": "test7",
"category": "test",
"limitDate": 7
},
{
"id": 8,
"imageUrl": "https://item.kakaocdn.net/do/493188dee481260d5c89790036be0e66f604e7b0e6900f9ac53a43965300eb9a",
"title": "test8",
"text": "test8",
"category": "test",
"limitDate": 7
},
{
"id": 9,
"imageUrl": "https://item.kakaocdn.net/do/493188dee481260d5c89790036be0e669f5287469802eca457586a25a096fd31",
"title": "test9",
"text": "test9",
"category": "test",
"limitDate": 7
},
{
"id": 10,
"imageUrl": "https://item.kakaocdn.net/do/493188dee481260d5c89790036be0e66f604e7b0e6900f9ac53a43965300eb9a",
"title": "test10",
"text": "test10",
"category": "test",
"limitDate": 7
},
{
"id": 11,
"imageUrl": "https://item.kakaocdn.net/do/493188dee481260d5c89790036be0e66f604e7b0e6900f9ac53a43965300eb9a",
"title": "test11",
"text": "test11",
"category": "test",
"limitDate": 7
},
{
"id": 12,
"imageUrl": "https://item.kakaocdn.net/do/493188dee481260d5c89790036be0e668b566dca82634c93f811198148a26065",
"title": "test12",
"text": "test12",
"category": "test",
"limitDate": 7
},
{
"id": 13,
"imageUrl": "https://item.kakaocdn.net/do/493188dee481260d5c89790036be0e66f604e7b0e6900f9ac53a43965300eb9a",
"title": "test13",
"text": "test13",
"category": "test",
"limitDate": 7
},
{
"id": 14,
"imageUrl": "https://item.kakaocdn.net/do/493188dee481260d5c89790036be0e66b3a18fdf58bc66ec3f4b6084b7d0b570",
"title": "test14",
"text": "test14",
"category": "test",
"limitDate": 7
},
{
"id": 15,
"imageUrl": "https://item.kakaocdn.net/do/493188dee481260d5c89790036be0e66effd194bae87d73dd00522794070855d",
"title": "test15",
"text": "test15",
"category": "test",
"limitDate": 7
},
{
"id": 16,
"imageUrl": "https://item.kakaocdn.net/do/493188dee481260d5c89790036be0e669cbcbe2de7f4969efc79ab353e0c19e8",
"title": "test16",
"text": "test16",
"category": "test",
"limitDate": 7
},
{
"id": 17,
"imageUrl": "https://item.kakaocdn.net/do/493188dee481260d5c89790036be0e668f324a0b9c48f77dbce3a43bd11ce785",
"title": "test17",
"text": "test17",
"category": "test",
"limitDate": 7
},
{
"id": 18,
"imageUrl": "https://item.kakaocdn.net/do/493188dee481260d5c89790036be0e668b566dca82634c93f811198148a26065",
"title": "test18",
"text": "test18",
"category": "test",
"limitDate": 7
},
{
"id": 19,
"imageUrl": "https://item.kakaocdn.net/do/493188dee481260d5c89790036be0e66b3a18fdf58bc66ec3f4b6084b7d0b570",
"title": "test19",
"text": "test19",
"category": "test",
"limitDate": 7
},
{
"id": 20,
"imageUrl": "https://item.kakaocdn.net/do/493188dee481260d5c89790036be0e66c37d537a8f2c6f426591be6b8dc7b36a",
"title": "test20",
"text": "test20",
"category": "test",
"limitDate": 7
}
]
25 changes: 23 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
import { BrowserRouter, Route, Routes } from 'react-router-dom';
import { QueryClientProvider } from 'react-query';
import { ReactQueryDevtools } from 'react-query/devtools';
import { getClient } from '@/config/queryClient';
import { Home, ProductDetail, ProductList } from '@/pages';
import { Header } from '@/components/Header';

const queryClient = getClient();

function App() {
return <div>hello rentive</div>
return (
<BrowserRouter>
<QueryClientProvider client={queryClient}>
<Header />
<Routes>
<Route path="/" element={<Home />} />
<Route path="/home/item-list" element={<ProductList />} />
<Route path="/home/item-list/*" element={<ProductDetail />} />
</Routes>
<ReactQueryDevtools />
</QueryClientProvider>
</BrowserRouter>
);
}

export default App
export default App;
54 changes: 54 additions & 0 deletions src/components/Product/ProductCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Link } from 'react-router-dom';
import styled from '@emotion/styled';
import { Product } from '@/pages/ProductList';

const StyledList = styled.li`
display: flex;
justify-content: center;
align-items: center;

& a:visited,
a {
color: #000;
}

& .product-list__image-bg {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
background-color: #eaeaea;
border-radius: 5px;
margin: 1rem 0 0.3rem 0;
}

& .product-list__image {
}

& .product-list__title {
font-weight: 600;
margin-bottom: 0.5rem;
}
`;

function ProductCard({
id,
title,
imageUrl,
limitDate,
}: Omit<Product, 'category' | 'text' | 'favorite'>) {
return (
<StyledList>
<Link to={`./item-${id}`}>
<div className="product-list__image-bg">
<img className="product-list__image" src={imageUrl} alt={title} />
</div>
<p className="product-list__title">{title}</p>
<p>{limitDate}일 ν›„ λŒ€μ—¬ κ°€λŠ₯</p>
</Link>
</StyledList>
);
}

export default ProductCard;
1 change: 1 addition & 0 deletions src/components/Product/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as ProductCard } from './ProductCard';
22 changes: 22 additions & 0 deletions src/config/queryClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { QueryClient } from 'react-query';

export const getClient = (() => {
let client: QueryClient | null = null;

return () => {
if (!client)
client = new QueryClient({
defaultOptions: {
queries: {
cacheTime: 1000 * 60 * 60 * 24, // query μΈμŠ€ν„΄μŠ€κ°€ unmount된 ν›„ μΊμ‹œ 데이터λ₯Ό μœ μ§€ν•˜λŠ” μ‹œκ°„
staleTime: 1000, // 데이터가 mount된 ν›„, stale μƒνƒœλ‘œ λ³€κ²½λ˜κΈ°κΉŒμ§€μ˜ μ‹œκ°„
refetchOnMount: false, // 쿼리에 μƒˆ μΈμŠ€ν„΄μŠ€κ°€ 마운트될 λ•Œ
refetchOnReconnect: false, // λ„€νŠΈμ›Œν¬κ°€ λŠμ–΄μ‘Œλ‹€ λ‹€μ‹œ 연결될 λ•Œ
refetchOnWindowFocus: false, // Window에 λ‹€μ‹œ Focus 될 λ•Œ
},
},
});

return client;
};
})();
1 change: 1 addition & 0 deletions src/constants/baseUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const BASE_URL = 'http://39.118.50.38:400';
3 changes: 3 additions & 0 deletions src/constants/queryKeys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const QueryKeys = {
PRODUCT: 'PRODUCT',
};
38 changes: 38 additions & 0 deletions src/hook/queries/fetcher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import axios from 'axios';

type AnyOBJ = { [key: string]: any };

// const BASE_URL = `39.118.50.38:400`;

export async function fetcher({
method,
path,
params = {},
body = {},
}: {
method: 'get' | 'post' | 'put' | 'delete' | 'patch';
path: string;
params?: AnyOBJ;
body?: AnyOBJ;
}) {
try {
const url = `${path}`;

const { data } = await axios({
url,
method,
data: { body },
params: { params },
withCredentials: true,
headers: {
'Content-Type': 'application/json',
},
});

return data;
} catch (err) {
console.error(err);

return null;
}
}
61 changes: 61 additions & 0 deletions src/pages/ProductList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { useQuery } from 'react-query';
import { useSearchParams } from 'react-router-dom';
import styled from '@emotion/styled';
import { QueryKeys } from '../constants/queryKeys';
import { fetcher } from '../hook/queries/fetcher';
import { ProductCard } from '@/components/Product';

export type ProductPostType = {
title: string;
text: string;
imageUrl: string;
category: string;
limitDate: number;
};
export type Product = ProductPostType & { id: number; favorite: number };

const ProductListWrapper = styled.ul`
margin: 0 auto;
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 10px;
place-items: center;

& li {
list-style: none;
}

& img {
margin: 0;
}
`;

function ProductList() {
const [searchParams] = useSearchParams();
const page = Number(searchParams.get('page')) as number;

if (!page) return null;

const { data: productData } = useQuery<Product[]>(QueryKeys.PRODUCT, () =>
fetcher({
method: 'get',
path: `http://localhost:5173/mockdata.json`,
}),
);

return (
<ProductListWrapper>
{productData?.map(({ title, imageUrl, limitDate, id }) => (
<ProductCard
key={id}
id={id}
imageUrl={imageUrl}
title={title}
limitDate={limitDate}
/>
))}
</ProductListWrapper>
);
}

export default ProductList;