From 409e755e7d93e827860e42ae2698059550e89c6a Mon Sep 17 00:00:00 2001 From: ljpark Date: Thu, 26 Feb 2026 16:56:31 +0900 Subject: [PATCH] =?UTF-8?q?dm=5Fnew:=20main=ED=99=94=EB=A9=B4=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20=EC=99=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../(landing)/reuse/_hooks/useScrollSpy.ts | 22 ++++++++++----- .../app/(landing)/reuse/apply/status/page.tsx | 2 +- apps/dm_new/app/(landing)/reuse/page.tsx | 4 ++- .../app/(with-layout)/apply/status/page.tsx | 2 +- apps/dm_new/app/main/_hooks/useScrollSpy.ts | 22 ++++++++++----- apps/dm_new/app/main/_sections/Cases.tsx | 10 ++++--- apps/dm_new/app/main/_sections/Hero.tsx | 11 ++++++-- apps/dm_new/app/main/_sections/IntroCards.tsx | 27 ++++++++++++------- apps/dm_new/app/main/page.tsx | 4 ++- 9 files changed, 71 insertions(+), 33 deletions(-) diff --git a/apps/dm_new/app/(landing)/reuse/_hooks/useScrollSpy.ts b/apps/dm_new/app/(landing)/reuse/_hooks/useScrollSpy.ts index 3a253e95d..8274f277d 100644 --- a/apps/dm_new/app/(landing)/reuse/_hooks/useScrollSpy.ts +++ b/apps/dm_new/app/(landing)/reuse/_hooks/useScrollSpy.ts @@ -1,9 +1,19 @@ "use client"; import { useEffect, useRef, useState } from "react"; +const DEFAULT_THRESHOLD = [0, 0.01, 0.1, 0.25, 0.5, 0.75]; + export function useScrollSpy(sectionIds: string[], options?: IntersectionObserverInit) { const [activeId, setActiveId] = useState(sectionIds[0] ?? ""); const ratiosRef = useRef>(new Map()); + const activeIdRef = useRef(activeId); + + useEffect(() => { + activeIdRef.current = activeId; + }, [activeId]); + + const threshold = options?.threshold ?? DEFAULT_THRESHOLD; + const thresholdKey = Array.isArray(threshold) ? threshold.join("|") : String(threshold); useEffect(() => { const els = sectionIds @@ -26,7 +36,7 @@ export function useScrollSpy(sectionIds: string[], options?: IntersectionObserve } // ✅ 전체 섹션 중 가장 ratio 큰 항목을 active로 - let bestId = activeId; + let bestId = activeIdRef.current; let bestRatio = -1; for (const [id, ratio] of ratiosRef.current.entries()) { @@ -39,17 +49,15 @@ export function useScrollSpy(sectionIds: string[], options?: IntersectionObserve if (bestId) setActiveId(bestId); }, { - root: null, - threshold: [0, 0.01, 0.1, 0.25, 0.5, 0.75], - rootMargin: DEFAULT_ROOT_MARGIN, - ...options, + root: options?.root ?? null, + threshold, + rootMargin: options?.rootMargin ?? DEFAULT_ROOT_MARGIN, } ); els.forEach((el) => io.observe(el)); return () => io.disconnect(); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [sectionIds.join("|"), options?.rootMargin, JSON.stringify(options?.threshold)]); + }, [sectionIds, options?.root, options?.rootMargin, threshold, thresholdKey]); return activeId; } diff --git a/apps/dm_new/app/(landing)/reuse/apply/status/page.tsx b/apps/dm_new/app/(landing)/reuse/apply/status/page.tsx index b7493f844..19d3dd3b4 100644 --- a/apps/dm_new/app/(landing)/reuse/apply/status/page.tsx +++ b/apps/dm_new/app/(landing)/reuse/apply/status/page.tsx @@ -227,7 +227,7 @@ export default function DemandStatusPage() { return ( onSelectRow(r.id)} onKeyDown={(e) => { diff --git a/apps/dm_new/app/(landing)/reuse/page.tsx b/apps/dm_new/app/(landing)/reuse/page.tsx index 442878365..ac6dcc9ac 100644 --- a/apps/dm_new/app/(landing)/reuse/page.tsx +++ b/apps/dm_new/app/(landing)/reuse/page.tsx @@ -1,6 +1,7 @@ // apps/dm/app/(landing)/reuse/page.tsx "use client"; +import { useMemo } from "react"; import TopNav from "./_components/TopNav"; import SideIndicator from "./_components/SideIndicator"; import { useScrollSpy } from "./_hooks/useScrollSpy"; @@ -30,7 +31,8 @@ const LANDING_SECTIONS = [ ]; export default function ReuseLandingPage() { - const activeId = useScrollSpy(LANDING_SECTIONS.map((s) => s.id)); + const sectionIds = useMemo(() => LANDING_SECTIONS.map((s) => s.id), []); + const activeId = useScrollSpy(sectionIds); return (
diff --git a/apps/dm_new/app/(with-layout)/apply/status/page.tsx b/apps/dm_new/app/(with-layout)/apply/status/page.tsx index cb3210da7..f5bd8d85d 100644 --- a/apps/dm_new/app/(with-layout)/apply/status/page.tsx +++ b/apps/dm_new/app/(with-layout)/apply/status/page.tsx @@ -227,7 +227,7 @@ export default function DemandStatusPage() { return ( onSelectRow(r.id)} onKeyDown={(e) => { diff --git a/apps/dm_new/app/main/_hooks/useScrollSpy.ts b/apps/dm_new/app/main/_hooks/useScrollSpy.ts index 3a253e95d..8274f277d 100644 --- a/apps/dm_new/app/main/_hooks/useScrollSpy.ts +++ b/apps/dm_new/app/main/_hooks/useScrollSpy.ts @@ -1,9 +1,19 @@ "use client"; import { useEffect, useRef, useState } from "react"; +const DEFAULT_THRESHOLD = [0, 0.01, 0.1, 0.25, 0.5, 0.75]; + export function useScrollSpy(sectionIds: string[], options?: IntersectionObserverInit) { const [activeId, setActiveId] = useState(sectionIds[0] ?? ""); const ratiosRef = useRef>(new Map()); + const activeIdRef = useRef(activeId); + + useEffect(() => { + activeIdRef.current = activeId; + }, [activeId]); + + const threshold = options?.threshold ?? DEFAULT_THRESHOLD; + const thresholdKey = Array.isArray(threshold) ? threshold.join("|") : String(threshold); useEffect(() => { const els = sectionIds @@ -26,7 +36,7 @@ export function useScrollSpy(sectionIds: string[], options?: IntersectionObserve } // ✅ 전체 섹션 중 가장 ratio 큰 항목을 active로 - let bestId = activeId; + let bestId = activeIdRef.current; let bestRatio = -1; for (const [id, ratio] of ratiosRef.current.entries()) { @@ -39,17 +49,15 @@ export function useScrollSpy(sectionIds: string[], options?: IntersectionObserve if (bestId) setActiveId(bestId); }, { - root: null, - threshold: [0, 0.01, 0.1, 0.25, 0.5, 0.75], - rootMargin: DEFAULT_ROOT_MARGIN, - ...options, + root: options?.root ?? null, + threshold, + rootMargin: options?.rootMargin ?? DEFAULT_ROOT_MARGIN, } ); els.forEach((el) => io.observe(el)); return () => io.disconnect(); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [sectionIds.join("|"), options?.rootMargin, JSON.stringify(options?.threshold)]); + }, [sectionIds, options?.root, options?.rootMargin, threshold, thresholdKey]); return activeId; } diff --git a/apps/dm_new/app/main/_sections/Cases.tsx b/apps/dm_new/app/main/_sections/Cases.tsx index 077d05cfe..757950369 100644 --- a/apps/dm_new/app/main/_sections/Cases.tsx +++ b/apps/dm_new/app/main/_sections/Cases.tsx @@ -1,6 +1,9 @@ // apps/dm/app/(landing)/reuse/_sections/Cases.tsx "use client"; +import Image from "next/image"; +import section03 from "@/public/images/landing/section_03.png"; + export default function Cases() { return (
@@ -50,10 +53,11 @@ export default function Cases() { w-full max-w-[720px] " > - 물 재이용 현황 데이터 테이블 @@ -62,4 +66,4 @@ export default function Cases() {
); -} \ No newline at end of file +} diff --git a/apps/dm_new/app/main/_sections/Hero.tsx b/apps/dm_new/app/main/_sections/Hero.tsx index 47f939aec..fa3c525de 100644 --- a/apps/dm_new/app/main/_sections/Hero.tsx +++ b/apps/dm_new/app/main/_sections/Hero.tsx @@ -1,4 +1,5 @@ // app/main/_sections/Hero.tsx +import Image from "next/image"; import styles from "../../reuse.module.css"; export default function Hero() { @@ -21,9 +22,15 @@ export default function Hero() {
- + scroll down
); -} \ No newline at end of file +} diff --git a/apps/dm_new/app/main/_sections/IntroCards.tsx b/apps/dm_new/app/main/_sections/IntroCards.tsx index e7153d721..c8c69ad7b 100644 --- a/apps/dm_new/app/main/_sections/IntroCards.tsx +++ b/apps/dm_new/app/main/_sections/IntroCards.tsx @@ -1,12 +1,17 @@ // apps/dm/app/(landing)/reuse/_sections/IntroCards.tsx "use client"; +import Image, { type StaticImageData } from "next/image"; import Link from "next/link"; +import card01 from "@/public/images/landing/card_01.jpg"; +import card02 from "@/public/images/landing/card_02.jpg"; +import card03 from "@/public/images/landing/card_03.jpg"; +import card04 from "@/public/images/landing/card_04.jpg"; type IntroCardItem = { title: string; desc: string; - image: string; + image: StaticImageData; href: string; }; @@ -14,25 +19,25 @@ const INTRO_CARDS: IntroCardItem[] = [ { title: "물 재이용 법", desc: "물의 재이용 촉진 및 지원에 관한 법률을 시행하고, 일부 법률은 개정되었습니다.", - image: "/images/landing/card_01.jpg", + image: card01, href: "/reuse/intro/law", }, { title: "친환경 수자원 빗물", desc: "가뭄을 극복하고 홍수를 예방하기 위해 비가 내릴 때 빗물을 모아두었다가 사용합니다.", - image: "/images/landing/card_02.jpg", + image: card02, href: "/reuse/intro/rain", }, { title: "알뜰하게 재이용되는 중수", desc: "한번 사용한 물을 중수도 시설을 통해 재생하여 개별적 또는 지역적으로 재이용할 수 있습니다.", - image: "/images/landing/card_03.jpg", + image: card03, href: "/reuse/intro/greywater", }, { title: "하수처리수 재이용", desc: "사용하고 버려진 공공하수처리장으로 모여진 물을 용도에 맞는 처리 후 재이용 할 수 있습니다.", - image: "/images/landing/card_04.jpg", + image: card04, href: "/reuse/intro/treated", }, ]; @@ -61,10 +66,12 @@ export default function IntroCards() { className="group relative h-[280px] md:h-[320px] lg:h-[500px] overflow-hidden rounded-2xl cursor-pointer focus:outline-none focus:ring-2 focus:ring-sky-400/60" > {/* 배경 이미지 (이미 그라디언트 포함) */} - {card.title} {/* 텍스트 영역 */} @@ -83,4 +90,4 @@ export default function IntroCards() { ); -} \ No newline at end of file +} diff --git a/apps/dm_new/app/main/page.tsx b/apps/dm_new/app/main/page.tsx index cab0e2658..2ab2b3c7f 100644 --- a/apps/dm_new/app/main/page.tsx +++ b/apps/dm_new/app/main/page.tsx @@ -1,6 +1,7 @@ // apps/dm/app/(landing)/reuse/page.tsx "use client"; +import { useMemo } from "react"; import TopNav from "@/components/TopNav"; import SideIndicator from "./SideIndicator"; import { useScrollSpy } from "./_hooks/useScrollSpy"; @@ -30,7 +31,8 @@ const LANDING_SECTIONS = [ ]; export default function ReuseLandingPage() { - const activeId = useScrollSpy(LANDING_SECTIONS.map((s) => s.id)); + const sectionIds = useMemo(() => LANDING_SECTIONS.map((s) => s.id), []); + const activeId = useScrollSpy(sectionIds); return (