From c185c75a78fb1770e972ee4bed38ef49f3c69f2b Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Nov 2026 11:05:14 +0500 Subject: [PATCH 01/14] =?UTF-8?q?feat(ui):=20add=20useScrollToResult=20hoo?= =?UTF-8?q?k=20for=20result=20visibility=20=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/ui/use-scroll-to-result.ts | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 components/ui/use-scroll-to-result.ts diff --git a/components/ui/use-scroll-to-result.ts b/components/ui/use-scroll-to-result.ts new file mode 100644 index 0000000..c5954d7 --- /dev/null +++ b/components/ui/use-scroll-to-result.ts @@ -0,0 +1,30 @@ +'use client'; + +import { useEffect, useRef } from 'react'; + +/** + * Brings the attached element into view when `result` changes to a new value, + * but only when it is not already fully visible. On desktop the user keeps + * their place; on phones and tablets the result is no longer lost below the + * fold after pressing "calculate". + */ +export function useScrollToResult(result: T | null) { + const ref = useRef(null); + + useEffect(() => { + const element = ref.current; + if (!result || !element) return; + + const rect = element.getBoundingClientRect(); + const fullyVisible = rect.top >= 0 && rect.bottom <= window.innerHeight; + if (fullyVisible) return; + + const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches; + element.scrollIntoView({ + behavior: prefersReducedMotion ? 'auto' : 'smooth', + block: 'start', + }); + }, [result]); + + return ref; +} From 9c7ad6766a8cee17fddfb54318d4b8ddf7af5063 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Nov 2026 11:05:14 +0500 Subject: [PATCH 02/14] =?UTF-8?q?fix(sweep):=20scroll=20to=20result=20afte?= =?UTF-8?q?r=20calculation=20and=20keep=20inputs=20in=20sticky,=20scrollab?= =?UTF-8?q?le=20panel=20=F0=9F=90=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/sweep-method.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/components/sweep-method.tsx b/components/sweep-method.tsx index ad88ddf..a141e28 100644 --- a/components/sweep-method.tsx +++ b/components/sweep-method.tsx @@ -6,6 +6,7 @@ import 'katex/dist/katex.min.css'; import { ArrowUpRight, Calculator, Check, Info } from 'lucide-react'; import { useI18n } from '@/components/i18n-provider'; import { ResultActions } from '@/components/ui/result-actions'; +import { useScrollToResult } from '@/components/ui/use-scroll-to-result'; import { PsHero, PsMap, @@ -109,6 +110,7 @@ export function SweepMethod() { const [precision, setPrecision] = useState(6); const [rows, setRows] = useState(() => makeDefaultRows(4)); const [result, setResult] = useState(null); + const resultRef = useScrollToResult(result); const [error, setError] = useState(''); const clearResult = () => { @@ -203,7 +205,7 @@ export function SweepMethod() { />
-