diff --git a/stardew_archive/src/components/FishDetailForm.css b/stardew_archive/src/components/FishDetailForm.css new file mode 100644 index 0000000..e41a666 --- /dev/null +++ b/stardew_archive/src/components/FishDetailForm.css @@ -0,0 +1,19 @@ +.detail-overlay { + position: fixed; /*페이지 내려도 배경은 항상 화면에 있음*/ + inset: 0; /*화면 전체 채우기*/ + background: rgba(0, 0, 0, 0.45); /*마지막 숫자 투명도*/ + display: flex; /*정렬 모드-> 아래 두개까지 팝업박스(내용물)를 화면 정중앙에 놓아라*/ + align-items: center; /*세로 가운데*/ + justify-content: center; /*가로 가운데*/ + z-index: 200;/*레이어 정하는 숫자->숫자 높을 수록 더 위에 쌓임*/ +} + +.detail-form { /*팝업*/ + background: #fff; + border-radius: 12px;/*모서리 둥글게*/ + width: 400px; /*박스 가로 폭 고정*/ + max-height: 70vh;/*세로 높이는 화면 높이의 70%까지만 커지게 제한 -> 내용이 그거보다 많아지면?*/ + overflow-y: auto;/*넘기면, 세로 스크롤바가 자동으로 생김*/ + padding: 24px;/*박스 안쪽 여백*/ + box-shadow: 0 8px 32px rgba(0,0,0,0.25);/*떠있는 느낌*/ +} \ No newline at end of file diff --git a/stardew_archive/src/components/FishDetailForm.jsx b/stardew_archive/src/components/FishDetailForm.jsx new file mode 100644 index 0000000..8f80d2d --- /dev/null +++ b/stardew_archive/src/components/FishDetailForm.jsx @@ -0,0 +1,30 @@ +import {useState} from 'react' +import './FishDetailForm.css' + +const SEASONS = ['봄','여름','가을','겨울'] + +export default function FishDetailForm({fish, onClose}){ + const[seasons, setSeasons ]=useState([]) + return( +
+
e.stopPropagation()}> +

{fish.name}

+ {fish.name} +

계절

+ {SEASONS.map((season) => ( + + ))} + +
+
+ ) +} \ No newline at end of file diff --git a/stardew_archive/src/components/ItemSelectModal.jsx b/stardew_archive/src/components/ItemSelectModal.jsx index 201ddf1..6630f61 100644 --- a/stardew_archive/src/components/ItemSelectModal.jsx +++ b/stardew_archive/src/components/ItemSelectModal.jsx @@ -1,7 +1,7 @@ import { useState } from 'react' import './ItemSelectModal.css' -export default function ItemSelectModal({ data, onClose }) { +export default function ItemSelectModal({ data, onClose, onSelect }) { const [query, setQuery] = useState('') const filtered = data.filter((item) => @@ -29,7 +29,8 @@ export default function ItemSelectModal({ data, onClose }) {
{filtered.length > 0 ? ( filtered.map((item) => ( -
+
onSelect(item)}> {item.name} {item.name}
diff --git a/stardew_archive/src/hooks/useLocalStorageState.js b/stardew_archive/src/hooks/useLocalStorageState.js new file mode 100644 index 0000000..601bb41 --- /dev/null +++ b/stardew_archive/src/hooks/useLocalStorageState.js @@ -0,0 +1,15 @@ +import { useState, useEffect } from "react"; + +// useLocalStorageState : 브라우저에서 같이 저장해서 새로고침해도 안 사라짐 +export function useLocalStorageState(key, initialValue) { + const [value, setValue] = useState(() => { + const saved = localStorage.getItem(key); // 저장소에서 예전에서 저장해둔 값 꺼내오기 + return saved ? JSON.parse(saved) : initialValue; // 있으면 객체로 복원 + }); + + useEffect(() => { + localStorage.setItem(key, JSON.stringify(value)); + }, [key, value]); + + return [value, setValue]; +} diff --git a/stardew_archive/src/pages/FishingPage.jsx b/stardew_archive/src/pages/FishingPage.jsx index f6a4a12..cef801b 100644 --- a/stardew_archive/src/pages/FishingPage.jsx +++ b/stardew_archive/src/pages/FishingPage.jsx @@ -1,3 +1,5 @@ +import FishDetailForm from '../components/FishDetailForm' +import { useLocalStorageState } from '../hooks/useLocalStorageState' import { useState } from 'react' import ItemSelectModal from '../components/ItemSelectModal' import { fishData } from '../data/fishData' @@ -5,11 +7,18 @@ import './PageCommon.css' export default function FishingPage() { const [showModal, setShowModal] = useState(false) - + const [caughtFish, setCaughtFish] = useLocalStorageState('caughtFish', []) + const [editingFish, setEditingFish] = useState(null) // 상세 폼에 띄울 물고기 뭔지 저장 return (
+ {caughtFish.map((fish) =>( +
setEditingFish(fish)}> + {fish.name} +

{fish.name}

+
+ ))} @@ -20,8 +29,15 @@ export default function FishingPage() { setShowModal(false)} + onSelect = {(item)=> { + setCaughtFish((prev)=>[...prev,item]) + setShowModal(false) + }} /> )} + {editingFish && ( + setEditingFish(null)} /> // 보여줄 물고기 -> editingFish / 닫힐때는 다시 비우기 + )}
) }