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 { useEffect, useState, useMemo } from 'react'
|
||||||
import { useNavigate } from '@tanstack/react-router'
|
import { useNavigate, useLocation } from '@tanstack/react-router'
|
||||||
import {
|
import {
|
||||||
Upload, Search, Building2, GitBranch,
|
Upload, Search, Building2, GitBranch,
|
||||||
Clock, TrendingUp, BarChart2, FileX2, X, Settings,
|
Clock, TrendingUp, BarChart2, FileX2, X, Settings,
|
||||||
@@ -508,7 +508,7 @@ function HomeView({
|
|||||||
const areaGroups = getAreaGroups(orgProcesses)
|
const areaGroups = getAreaGroups(orgProcesses)
|
||||||
|
|
||||||
return (
|
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 */}
|
{/* Header de org — colapsable */}
|
||||||
<button
|
<button
|
||||||
onClick={() => toggleOrg(orgId)}
|
onClick={() => toggleOrg(orgId)}
|
||||||
@@ -731,7 +731,7 @@ function GroupView({
|
|||||||
|
|
||||||
export function LibraryPage() {
|
export function LibraryPage() {
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const { load, processes } = useLibraryStore()
|
const { load, processes, isLoading } = useLibraryStore()
|
||||||
const { user, isProfileLoaded } = useAuth()
|
const { user, isProfileLoaded } = useAuth()
|
||||||
const [view, setView] = useState<'home' | 'group'>('home')
|
const [view, setView] = useState<'home' | 'group'>('home')
|
||||||
const [activeGroupId, setActiveGroupId] = useState<string | null>(null)
|
const [activeGroupId, setActiveGroupId] = useState<string | null>(null)
|
||||||
@@ -739,11 +739,26 @@ export function LibraryPage() {
|
|||||||
const [ownerFilter, setOwnerFilter] = useState<'all' | 'mine'>('all')
|
const [ownerFilter, setOwnerFilter] = useState<'all' | 'mine'>('all')
|
||||||
const { message: toastMessage, show: showToast } = useToast()
|
const { message: toastMessage, show: showToast } = useToast()
|
||||||
|
|
||||||
|
const location = useLocation()
|
||||||
|
const orgParam = useMemo(
|
||||||
|
() => new URLSearchParams(location.search).get('org') ?? undefined,
|
||||||
|
[location.search]
|
||||||
|
)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!user) return // no fetchear hasta tener usuario confirmado (evita race condition con sesión Supabase)
|
if (!user) return // no fetchear hasta tener usuario confirmado (evita race condition con sesión Supabase)
|
||||||
load()
|
load()
|
||||||
}, [load, user?.id])
|
}, [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() {
|
function navigateHome() {
|
||||||
setTransitioning(true)
|
setTransitioning(true)
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ vi.mock('@/components/AppHeader', () => ({ AppHeader: () => null }))
|
|||||||
vi.mock('@tanstack/react-router', () => ({
|
vi.mock('@tanstack/react-router', () => ({
|
||||||
useNavigate: () => vi.fn(),
|
useNavigate: () => vi.fn(),
|
||||||
useRouterState: () => ({ location: { search: '' } }),
|
useRouterState: () => ({ location: { search: '' } }),
|
||||||
|
useLocation: () => ({ search: '' }),
|
||||||
Link: ({ children }: { children: React.ReactNode }) => <>{children}</>,
|
Link: ({ children }: { children: React.ReactNode }) => <>{children}</>,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user