From 80539188ef6814b4202d677d62b761bd5b670574 Mon Sep 17 00:00:00 2001 From: Max Nanis Date: Tue, 24 Jun 2025 19:04:01 +0700 Subject: Dynamic height adjustment for widget size. CSS inject by JS for single file --- src/Widget.tsx | 52 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 15 deletions(-) (limited to 'src/Widget.tsx') diff --git a/src/Widget.tsx b/src/Widget.tsx index 192e4e0..4f4556b 100644 --- a/src/Widget.tsx +++ b/src/Widget.tsx @@ -1,5 +1,5 @@ -import {useEffect} from 'react' -import {AppSidebar} from "@/components/app-sidebar" +import { useEffect, useState, useRef } from "react" + import {SiteHeader} from "@/components/site-header" import {SidebarInset, SidebarProvider} from "@/components/ui/sidebar" import {Offerwall} from "@/pages/Offerwall.tsx" @@ -8,6 +8,7 @@ import {Demographics} from "@/pages/Demographics.tsx" import {CashoutMethodsPage} from "@/pages/CashoutMethods.tsx"; import {TransactionHistoryPage} from "@/pages/TransactionHistory.tsx" import {TaskAttemptHistoryPage} from "@/pages/TaskAttemptHistory.tsx"; +import {AppSidebar} from "@/components/app-sidebar" import {useAppDispatch, useAppSelector} from "@/hooks.ts"; import { @@ -33,11 +34,34 @@ import {setMarketplaceAnswers} from "@/models/userMarketplaceAnswerSlice.ts"; import {setUserProfile} from "@/models/userProfileSlice.ts"; import {setTaskStatuses} from "@/models/taskStatusSlice.ts" import {App} from "@/models/app.ts" +import {ScrollArea} from "@/components/ui/scroll-area" import './index.css'; +export function useParentHeight() { + const ref = useRef(null) + const [height, setHeight] = useState(null) + + useEffect(() => { + if (!ref.current) return + + const observer = new ResizeObserver(() => { + if (ref.current?.parentElement) { + const h = ref.current.parentElement.getBoundingClientRect().height + setHeight(h) + } + }) + + observer.observe(ref.current.parentElement!) + + return () => observer.disconnect() + }, []) + + return { ref, height } +} const Widget = () => { + const { ref, height } = useParentHeight() const dispatch = useAppDispatch() const app: App = useAppSelector(state => state.app) @@ -103,31 +127,29 @@ const Widget = () => { }, []); // ← empty array means "run once" - return ( - - - - +
+ + -
-
+ + +
-
+
{app.currentPage === 'offerwall' && } {app.currentPage === 'questions' && } {app.currentPage === 'cashout_methods' && } {app.currentPage === 'task_attempts' && } - {app.currentPage === 'demographics' && } {app.currentPage === 'transaction_history' && }
-
-
+ - - + + +
) } -- cgit v1.2.3