All files / src/components Layout.tsx

0% Statements 0/46
0% Branches 0/1
0% Functions 0/1
0% Lines 0/46

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63                                                                                                                             
import React, { useEffect } from 'react'
import { AppBar, Toolbar, Typography, Container, Box, LinearProgress } from '@mui/material'
import { useNavigate, useLocation } from 'react-router-dom'
import { NavigationTabs } from './NavigationTabs'
import { useAppDispatch, useAppSelector } from '../store'
import { extractDocument, analyzeDocument, getContextData, getConseil } from '../store/documentSlice'
 
interface LayoutProps {
  children: React.ReactNode
}
 
export const Layout: React.FC<LayoutProps> = ({ children }) => {
  const navigate = useNavigate()
  const location = useLocation()
  const dispatch = useAppDispatch()
  const { documents, extractionById, loading, currentDocument, contextResult, conseilResult, analysisResult } = useAppSelector((s) => s.document)
 
  // Au chargement/nav: lancer OCR+classification pour tous les documents sans résultat
  useEffect(() => {
    documents.forEach((doc) => {
      if (!extractionById[doc.id]) dispatch(extractDocument(doc.id))
    })
  }, [documents, extractionById, dispatch])
 
  // Déclencher contexte et conseil globaux une fois qu'un document courant existe
  useEffect(() => {
    if (currentDocument) {
      if (!analysisResult) dispatch(analyzeDocument(currentDocument.id))
      if (!contextResult) dispatch(getContextData(currentDocument.id))
      if (!conseilResult) dispatch(getConseil(currentDocument.id))
    }
  }, [currentDocument, analysisResult, contextResult, conseilResult, dispatch])
 
  return (
    <Box sx={{ flexGrow: 1 }}>
      <AppBar position="static">
        <Toolbar>
          <Typography
            variant="h6"
            component="div"
            sx={{ flexGrow: 1, cursor: 'pointer' }}
            onClick={() => navigate('/')}
          >
            4NK IA - Lecoffre.io
          </Typography>
        </Toolbar>
      </AppBar>
 
      <NavigationTabs currentPath={location.pathname} />
 
      {loading && (
        <Box sx={{ px: 2, pt: 1 }}>
          <LinearProgress />
        </Box>
      )}
 
      <Container maxWidth="xl" sx={{ mt: 3, mb: 3 }}>
        {children}
      </Container>
    </Box>
  )
}