Skip to content

Commit

Permalink
feat: 메인 검색창 검색결과 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
minSsan committed May 28, 2024
1 parent 3f531bf commit abc6358
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
22 changes: 20 additions & 2 deletions src/app/(default)/main.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"use client";

import React from "react";
import React, { FormEvent, useCallback } from "react";
import styles from "./main.module.css";
import Image from "next/image";
import { Banner, Menu } from "../../../public/svgs";
import { SearchBox, QuickMenu, DataBoard } from "../../components";
import { useIncreaseCount } from "../../hooks";
import { useRouter } from "next/navigation";

const DATA_COUNT = 2379;

Expand Down Expand Up @@ -50,6 +51,22 @@ const QUICK_MENU = [

export default function Main({ populars, news }) {
const dataCount = useIncreaseCount(DATA_COUNT);

const router = useRouter();

// 검색 제출시 실행되는 함수. 파라미터는 search-box 컴포넌트 내에서 전달한다.
const handleSearchSubmit = useCallback(
(event: FormEvent<HTMLFormElement>, keyword: string) => {
event.preventDefault();

if (keyword) {
router.push(`search-result?keyword=${keyword}`);
return;
}
},
[],
);

return (
<div>
{/* 메인페이지 배너 */}
Expand Down Expand Up @@ -78,8 +95,9 @@ export default function Main({ populars, news }) {
backgroundColor: "#ffffff",
borderRadius: "75px",
zIndex: 1,
width: "65.5rem",
width: "70%",
}}
handleSubmit={handleSearchSubmit}
/>
</div>

Expand Down
2 changes: 0 additions & 2 deletions src/utils/search/update-query-string.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"use client";

import { ReadonlyURLSearchParams } from "next/navigation";

interface UpdateQueryStringProps {
type: "create" | "append" | "remove";
name: string;
Expand Down

0 comments on commit abc6358

Please sign in to comment.