diff --git a/src/App.jsx b/src/App.jsx index b7709f6..99be4af 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -9,14 +9,15 @@ import restaurantsData from "./data/restaurantsData.js"; function App() { const [category, setCategory] = useState("전체"); + const [restaurants, setRestaurants] = useState(restaurantsData); const filterRestaurants = (category) => { - if (category === "전체") return restaurantsData; - else return restaurantsData.filter((restaurant) => restaurant.category === category); + if (category === "전체") return restaurants; + else return restaurants.filter((restaurant) => restaurant.category === category); }; const filteredRestaurants = filterRestaurants(category); - + const [modal, setModal] = useState({ isOpen: false, restaurant: { @@ -25,16 +26,26 @@ function App() { }, }); + const [isAddModalOpen, setIsAddModalOpen] = useState(false); + const handleAddRestaurant = (newRestaurant) => { + setRestaurants((prevRestaurants) => [...prevRestaurants, newRestaurant]); + }; + return ( <> -
+
); diff --git a/src/components/AddRestaurantModal.jsx b/src/components/AddRestaurantModal.jsx index 89f5ba7..ea78c28 100644 --- a/src/components/AddRestaurantModal.jsx +++ b/src/components/AddRestaurantModal.jsx @@ -1,36 +1,73 @@ import "../styles/AddRestaurantModalStyle.css"; import { CATEGORY_DATA } from "../data/categoryData"; +import { useState } from "react"; + +function AddRestaurantModal({ setIsAddModalOpen, handleAddRestaurant }) { + const [newRestaurant, setNewRestaurant] = useState({ + id: Date.now(), + name: "", + description: "", + category: "", + }); + + const handleAddBtnClick = () => { + handleAddRestaurant(newRestaurant); + setIsAddModalOpen(false); + }; -function AddRestaurantModal() { return (
-
+
setIsAddModalOpen(false)}>

새로운 음식점

- + setNewRestaurant({ ...newRestaurant, category: event.target.value }) + } + > {CATEGORY_DATA.slice(1).map((category) => ( ))} -
+
- + setNewRestaurant({ ...newRestaurant, name: event.target.value })} + />
- + 메뉴 등 추가 정보를 입력해 주세요.
- +
diff --git a/src/components/CategoryFilter.jsx b/src/components/CategoryFilter.jsx index 457ac47..4ae26c6 100644 --- a/src/components/CategoryFilter.jsx +++ b/src/components/CategoryFilter.jsx @@ -11,7 +11,7 @@ function CategoryFilter({ category, onChangeCategory }) { className="restaurant-filter" aria-label="음식점 카테고리 필터" value={category} - onChange={() => onChangeCategory(event.target.value)} + onChange={(event) => onChangeCategory(event.target.value)} > {CATEGORY_DATA.map((category) => ( diff --git a/src/components/Header.jsx b/src/components/Header.jsx index c15ef5b..6955f5c 100644 --- a/src/components/Header.jsx +++ b/src/components/Header.jsx @@ -1,11 +1,16 @@ import "../styles/HeaderStyle.css"; -function Header() { +function Header({ setIsAddModalOpen }) { return ( <>

점심 뭐 먹지

-
diff --git a/src/components/RestaurantList.jsx b/src/components/RestaurantList.jsx index f15a60b..980afab 100644 --- a/src/components/RestaurantList.jsx +++ b/src/components/RestaurantList.jsx @@ -34,7 +34,7 @@ function RestaurantList({ restaurants, setModal, modal }) {
한식