fix(library): scroll a sección de org al volver del workspace con ?org param
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { useEffect, useState, useMemo } from 'react'
|
||||
import { useNavigate } from '@tanstack/react-router'
|
||||
import { useNavigate, useLocation } from '@tanstack/react-router'
|
||||
import {
|
||||
Upload, Search, Building2, GitBranch,
|
||||
Clock, TrendingUp, BarChart2, FileX2, X, Settings,
|
||||
@@ -508,7 +508,7 @@ function HomeView({
|
||||
const areaGroups = getAreaGroups(orgProcesses)
|
||||
|
||||
return (
|
||||
<div key={orgId} className="border border-border rounded-xl overflow-hidden">
|
||||
<div key={orgId} id={`org-section-${orgId}`} className="border border-border rounded-xl overflow-hidden">
|
||||
{/* Header de org — colapsable */}
|
||||
<button
|
||||
onClick={() => toggleOrg(orgId)}
|
||||
@@ -731,7 +731,7 @@ function GroupView({
|
||||
|
||||
export function LibraryPage() {
|
||||
const navigate = useNavigate()
|
||||
const { load, processes } = useLibraryStore()
|
||||
const { load, processes, isLoading } = useLibraryStore()
|
||||
const { user, isProfileLoaded } = useAuth()
|
||||
const [view, setView] = useState<'home' | 'group'>('home')
|
||||
const [activeGroupId, setActiveGroupId] = useState<string | null>(null)
|
||||
@@ -739,11 +739,26 @@ export function LibraryPage() {
|
||||
const [ownerFilter, setOwnerFilter] = useState<'all' | 'mine'>('all')
|
||||
const { message: toastMessage, show: showToast } = useToast()
|
||||
|
||||
const location = useLocation()
|
||||
const orgParam = useMemo(
|
||||
() => new URLSearchParams(location.search).get('org') ?? undefined,
|
||||
[location.search]
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
if (!user) return // no fetchear hasta tener usuario confirmado (evita race condition con sesión Supabase)
|
||||
load()
|
||||
}, [load, user?.id])
|
||||
|
||||
// Scroll a la sección del org si venimos del workspace
|
||||
useEffect(() => {
|
||||
if (!orgParam || isLoading || processes.length === 0) return
|
||||
requestAnimationFrame(() => {
|
||||
const el = document.getElementById(`org-section-${orgParam}`)
|
||||
el?.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
||||
})
|
||||
}, [orgParam, isLoading, processes.length])
|
||||
|
||||
function navigateHome() {
|
||||
setTransitioning(true)
|
||||
setTimeout(() => {
|
||||
|
||||
@@ -74,6 +74,7 @@ vi.mock('@/components/AppHeader', () => ({ AppHeader: () => null }))
|
||||
vi.mock('@tanstack/react-router', () => ({
|
||||
useNavigate: () => vi.fn(),
|
||||
useRouterState: () => ({ location: { search: '' } }),
|
||||
useLocation: () => ({ search: '' }),
|
||||
Link: ({ children }: { children: React.ReactNode }) => <>{children}</>,
|
||||
}))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user