dm_new: main화면 수정 외
This commit is contained in:
@@ -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<Map<string, number>>(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;
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ export default function DemandStatusPage() {
|
||||
return (
|
||||
<tr
|
||||
key={r.id}
|
||||
role="button"
|
||||
role="row"
|
||||
tabIndex={0}
|
||||
onClick={() => onSelectRow(r.id)}
|
||||
onKeyDown={(e) => {
|
||||
|
||||
@@ -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 (
|
||||
<main className="bg-white">
|
||||
|
||||
@@ -227,7 +227,7 @@ export default function DemandStatusPage() {
|
||||
return (
|
||||
<tr
|
||||
key={r.id}
|
||||
role="button"
|
||||
role="row"
|
||||
tabIndex={0}
|
||||
onClick={() => onSelectRow(r.id)}
|
||||
onKeyDown={(e) => {
|
||||
|
||||
@@ -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<Map<string, number>>(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;
|
||||
}
|
||||
|
||||
@@ -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 (
|
||||
<section id="cases" className="bg-[#EAF6F6]">
|
||||
@@ -50,10 +53,11 @@ export default function Cases() {
|
||||
w-full max-w-[720px]
|
||||
"
|
||||
>
|
||||
<img
|
||||
src="/images/landing/section_03.png"
|
||||
<Image
|
||||
src={section03}
|
||||
alt="물 재이용 현황 데이터 테이블"
|
||||
className="w-full h-auto object-cover"
|
||||
style={{ width: "100%", height: "auto" }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -62,4 +66,4 @@ export default function Cases() {
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
</div>
|
||||
</div>
|
||||
<div className="absolute inset-x-0 bottom-[120px] flex flex-col items-center justify-items-center gap-2 mt-10">
|
||||
<img src="/images/landing/scroll_down.svg" alt="" className="w-[26px] h-[40px]" />
|
||||
<Image
|
||||
src="/images/landing/scroll_down.svg"
|
||||
alt=""
|
||||
width={26}
|
||||
height={40}
|
||||
className="w-[26px] h-[40px]"
|
||||
/>
|
||||
<span className="text-white/80 text-base tracking-[.25em]">scroll down</span>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
>
|
||||
{/* 배경 이미지 (이미 그라디언트 포함) */}
|
||||
<img
|
||||
src={card.image}
|
||||
alt={card.title}
|
||||
className="absolute inset-0 h-full w-full object-cover transition-transform duration-500 hover:scale-105"
|
||||
<Image
|
||||
src={card.image}
|
||||
alt={card.title}
|
||||
fill
|
||||
sizes="(min-width: 1024px) 25vw, (min-width: 768px) 50vw, 100vw"
|
||||
className="absolute inset-0 h-full w-full object-cover transition-transform duration-500 hover:scale-105"
|
||||
/>
|
||||
|
||||
{/* 텍스트 영역 */}
|
||||
@@ -83,4 +90,4 @@ export default function IntroCards() {
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 (
|
||||
<main className="bg-white">
|
||||
|
||||
Reference in New Issue
Block a user