-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import Head from 'next/head'; | ||
import ProductList from '@/components/ProductList'; | ||
import SearchForm from '@/components/SearchForm'; | ||
import axios from '@/lib/axios'; | ||
import styles from "./page.module.css"; | ||
|
||
export default async function Search({ searchParams }) { | ||
const { q } = await searchParams; | ||
|
||
const res = await axios.get(`/products/?q=${q}`); | ||
const products = res.data.results ?? []; | ||
return ( | ||
<> | ||
<Head> | ||
<title>{q} 검색 결과 - Codeitmall</title> | ||
</Head> | ||
<SearchForm initialValue={q} /> | ||
<h2 className={styles.title}> | ||
<span className={styles.keyword}>{q}</span> 검색 결과 | ||
</h2> | ||
<ProductList className={styles.productList} products={products} /> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
.title { | ||
padding: 0 10px; | ||
color: #b5b5b5; | ||
font-weight: 500; | ||
font-size: 26px; | ||
line-height: 38px; | ||
} | ||
|
||
.title > .keyword { | ||
color: #f9f9f9; | ||
font-weight: 700; | ||
} | ||
|
||
:global(.light) .title { | ||
color: #747474; | ||
} | ||
|
||
:global(.light) .keyword { | ||
color: #1f1f1f; | ||
} | ||
|
||
.productList { | ||
margin: 30px 0 60px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import styles from './SearchForm.module.css'; | ||
import { redirect } from 'next/navigation' | ||
|
||
|
||
export default function SearchForm({ initialValue = '' }) { | ||
const handleSubmit = async (formData) => { | ||
'use server' | ||
redirect(`/search?q=${encodeURI(formData.get('q'))}`); | ||
}; | ||
|
||
return ( | ||
<form className={styles.searchForm} action={handleSubmit}> | ||
<input | ||
className={styles.searchInput} | ||
name="q" | ||
defaultValue={initialValue} | ||
placeholder="찾고 싶은 옷을 검색해보세요." | ||
/> | ||
<button type="submit" className={styles.searchButton}>검색</button> | ||
</form> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
.searchForm { | ||
display: flex; | ||
gap: 15px; | ||
} | ||
|
||
.searchInput { | ||
width: 400px; | ||
padding: 0px 30px; | ||
color: #f9f9f9; | ||
font-size: 18px; | ||
background-color: #252525; | ||
border: 1px solid #505050; | ||
border-radius: 10px; | ||
outline: none; | ||
} | ||
|
||
:global(.light) .searchInput { | ||
color: #1f1f1f; | ||
background-color: #f9f9f9; | ||
border: 1px solid #cfcfcf; | ||
} | ||
|
||
.searchButton { | ||
padding: 16px 40px; | ||
font-weight: 700; | ||
font-size: 18px; | ||
line-height: 26px; | ||
border: none; | ||
border-radius: 10px; | ||
} | ||
|
||
:global(.light) .searchButton { | ||
color: #f9f9f9; | ||
background-color: #505050; | ||
} |