From 18306221ed893f54dd854882cb26705fe37e69e7 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 29 Aug 2025 12:27:53 +0000 Subject: [PATCH] Improve mobile rule page with responsive textarea and floating action bar Co-authored-by: raavtube --- app/rule/[slug]/page.tsx | 112 ++++++++++++++++++++++++++++----------- 1 file changed, 82 insertions(+), 30 deletions(-) diff --git a/app/rule/[slug]/page.tsx b/app/rule/[slug]/page.tsx index 1ae2839..6881fee 100644 --- a/app/rule/[slug]/page.tsx +++ b/app/rule/[slug]/page.tsx @@ -1,6 +1,6 @@ "use client" -import { useEffect, useState } from "react" +import { useEffect, useState, useRef } from "react" import { useParams } from "next/navigation" import { Header } from "@/components/header" import { Card } from "@/components/ui/card" @@ -82,6 +82,7 @@ export default function PublicRulePage() { const [tokenCount, setTokenCount] = useState(0) const [copied, setCopied] = useState(false) const [cliCopied, setCliCopied] = useState(false) + const textareaRef = useRef(null) useEffect(() => { const fetchRule = async () => { @@ -120,6 +121,40 @@ export default function PublicRulePage() { } }, [params.slug]) + // Auto-resize textarea on mobile + useEffect(() => { + const textarea = textareaRef.current + if (textarea && rule?.content) { + const isMobile = window.innerWidth < 640 // sm breakpoint + if (isMobile) { + // Reset height to auto to get the correct scrollHeight + textarea.style.height = 'auto' + // Set height to scrollHeight to fit content + textarea.style.height = `${textarea.scrollHeight}px` + } + } + }, [rule?.content]) + + // Handle window resize to re-check mobile state + useEffect(() => { + const handleResize = () => { + const textarea = textareaRef.current + if (textarea && rule?.content) { + const isMobile = window.innerWidth < 640 + if (isMobile) { + textarea.style.height = 'auto' + textarea.style.height = `${textarea.scrollHeight}px` + } else { + // Reset to default height on desktop + textarea.style.height = '' + } + } + } + + window.addEventListener('resize', handleResize) + return () => window.removeEventListener('resize', handleResize) + }, [rule?.content]) + const handleCopy = async () => { if (!rule) return @@ -207,17 +242,18 @@ export default function PublicRulePage() { }} >