fix: hide scroll depth and trend chart when rate-limited
Frustration APIs and dashboard API are separate — when frustration calls fail, Scroll Depth still rendered from cached SWR data, creating a broken mixed state. Now tracks error state and hides the bottom section entirely on failure.
This commit is contained in:
@@ -53,6 +53,7 @@ export default function BehaviorPage() {
|
|||||||
const [deadClicks, setDeadClicks] = useState<{ items: FrustrationElement[]; total: number }>({ items: [], total: 0 })
|
const [deadClicks, setDeadClicks] = useState<{ items: FrustrationElement[]; total: number }>({ items: [], total: 0 })
|
||||||
const [byPage, setByPage] = useState<FrustrationByPage[]>([])
|
const [byPage, setByPage] = useState<FrustrationByPage[]>([])
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
|
const [error, setError] = useState(false)
|
||||||
const refreshRef = useRef<ReturnType<typeof setInterval> | null>(null)
|
const refreshRef = useRef<ReturnType<typeof setInterval> | null>(null)
|
||||||
|
|
||||||
// Fetch dashboard data for scroll depth (goal_counts + stats)
|
// Fetch dashboard data for scroll depth (goal_counts + stats)
|
||||||
@@ -70,7 +71,9 @@ export default function BehaviorPage() {
|
|||||||
setRageClicks(rageData)
|
setRageClicks(rageData)
|
||||||
setDeadClicks(deadData)
|
setDeadClicks(deadData)
|
||||||
setByPage(pageData)
|
setByPage(pageData)
|
||||||
|
setError(false)
|
||||||
} catch {
|
} catch {
|
||||||
|
setError(true)
|
||||||
toast.error('Failed to load behavior data')
|
toast.error('Failed to load behavior data')
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
@@ -185,14 +188,16 @@ export default function BehaviorPage() {
|
|||||||
{/* By page breakdown */}
|
{/* By page breakdown */}
|
||||||
<FrustrationByPageTable pages={byPage} loading={loading} />
|
<FrustrationByPageTable pages={byPage} loading={loading} />
|
||||||
|
|
||||||
{/* Scroll depth + Frustration trend */}
|
{/* Scroll depth + Frustration trend — hide when data failed to load */}
|
||||||
<div className="grid gap-6 lg:grid-cols-2 mb-8">
|
{!error && (
|
||||||
<ScrollDepth
|
<div className="grid gap-6 lg:grid-cols-2 mb-8">
|
||||||
goalCounts={dashboard?.goal_counts ?? []}
|
<ScrollDepth
|
||||||
totalPageviews={dashboard?.stats?.pageviews ?? 0}
|
goalCounts={dashboard?.goal_counts ?? []}
|
||||||
/>
|
totalPageviews={dashboard?.stats?.pageviews ?? 0}
|
||||||
<FrustrationTrend summary={summary} loading={loading} />
|
/>
|
||||||
</div>
|
<FrustrationTrend summary={summary} loading={loading} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<DatePicker
|
<DatePicker
|
||||||
isOpen={isDatePickerOpen}
|
isOpen={isDatePickerOpen}
|
||||||
|
|||||||
Reference in New Issue
Block a user