feat: Implement remaining data widgets for Agro, Grains, and USA Stocks
This commit is contained in:
		| @@ -1,16 +1,6 @@ | ||||
| import { | ||||
|   Box, | ||||
|   CircularProgress, | ||||
|   Alert, | ||||
|   Table, | ||||
|   TableBody, | ||||
|   TableCell, | ||||
|   TableContainer, | ||||
|   TableHead, | ||||
|   TableRow, | ||||
|   Paper, | ||||
|   Typography, | ||||
|   Tooltip | ||||
|   Box, CircularProgress, Alert, Table, TableBody, TableCell, | ||||
|   TableContainer, TableHead, TableRow, Paper, Typography, Tooltip | ||||
| } from '@mui/material'; | ||||
| import type { CotizacionBolsa } from '../models/mercadoModels'; | ||||
| import { useApiData } from '../hooks/useApiData'; | ||||
| @@ -30,7 +20,7 @@ const formatNumber = (num: number) => { | ||||
| const Variacion = ({ value }: { value: number }) => { | ||||
|   const color = value > 0 ? 'success.main' : value < 0 ? 'error.main' : 'text.secondary'; | ||||
|   const Icon = value > 0 ? ArrowUpwardIcon : value < 0 ? ArrowDownwardIcon : RemoveIcon; | ||||
|    | ||||
|  | ||||
|   return ( | ||||
|     <Box component="span" sx={{ display: 'flex', alignItems: 'center', justifyContent: 'center', color }}> | ||||
|       <Icon sx={{ fontSize: '1rem', mr: 0.5 }} /> | ||||
| @@ -84,9 +74,9 @@ export const BolsaLocalWidget = () => { | ||||
|           ))} | ||||
|         </TableBody> | ||||
|       </Table> | ||||
|        <Tooltip title={`Última actualización: ${new Date(data[0].fechaRegistro).toLocaleString('es-AR')}`}> | ||||
|       <Tooltip title={`Última actualización: ${new Date(data[0].fechaRegistro).toLocaleString('es-AR')}`}> | ||||
|         <Typography variant="caption" sx={{ p: 1, display: 'block', textAlign: 'right', color: 'text.secondary' }}> | ||||
|             Fuente: Yahoo Finance | ||||
|           Fuente: Yahoo Finance | ||||
|         </Typography> | ||||
|       </Tooltip> | ||||
|     </TableContainer> | ||||
|   | ||||
| @@ -0,0 +1,82 @@ | ||||
| import { | ||||
|   Box, CircularProgress, Alert, Table, TableBody, TableCell, | ||||
|   TableContainer, TableHead, TableRow, Paper, Typography, Tooltip | ||||
| } from '@mui/material'; | ||||
| import type { CotizacionBolsa } from '../models/mercadoModels'; | ||||
| import { useApiData } from '../hooks/useApiData'; | ||||
| import ArrowUpwardIcon from '@mui/icons-material/ArrowUpward'; | ||||
| import ArrowDownwardIcon from '@mui/icons-material/ArrowDownward'; | ||||
| import RemoveIcon from '@mui/icons-material/Remove'; | ||||
|  | ||||
| const formatNumber = (num: number) => { | ||||
|   return new Intl.NumberFormat('en-US', { // Usamos formato de EEUU | ||||
|     style: 'currency', | ||||
|     currency: 'USD', | ||||
|   }).format(num); | ||||
| }; | ||||
|  | ||||
| const Variacion = ({ value }: { value: number }) => { | ||||
|   const color = value > 0 ? 'success.main' : value < 0 ? 'error.main' : 'text.secondary'; | ||||
|   const Icon = value > 0 ? ArrowUpwardIcon : value < 0 ? ArrowDownwardIcon : RemoveIcon; | ||||
|  | ||||
|   return ( | ||||
|     <Box component="span" sx={{ display: 'flex', alignItems: 'center', justifyContent: 'center', color }}> | ||||
|       <Icon sx={{ fontSize: '1rem', mr: 0.5 }} /> | ||||
|       <Typography variant="body2" component="span" sx={{ fontWeight: 'bold' }}> | ||||
|         {value.toFixed(2)}% | ||||
|       </Typography> | ||||
|     </Box> | ||||
|   ); | ||||
| }; | ||||
|  | ||||
| export const BolsaUsaWidget = () => { | ||||
|   const { data, loading, error } = useApiData<CotizacionBolsa[]>('/mercados/bolsa/eeuu'); | ||||
|  | ||||
|   if (loading) { | ||||
|     return <Box sx={{ display: 'flex', justifyContent: 'center', p: 4 }}><CircularProgress /></Box>; | ||||
|   } | ||||
|  | ||||
|   if (error) { | ||||
|     return <Alert severity="error">{error}</Alert>; | ||||
|   } | ||||
|  | ||||
|   if (!data || data.length === 0) { | ||||
|     return <Alert severity="info">No hay datos disponibles para el mercado de EEUU. (El fetcher puede estar desactivado)</Alert>; | ||||
|   } | ||||
|  | ||||
|   return ( | ||||
|     <TableContainer component={Paper}> | ||||
|       <Table size="small" aria-label="tabla bolsa eeuu"> | ||||
|         <TableHead> | ||||
|           <TableRow> | ||||
|             <TableCell>Símbolo</TableCell> | ||||
|             <TableCell align="right">Precio Actual</TableCell> | ||||
|             <TableCell align="right">Apertura</TableCell> | ||||
|             <TableCell align="right">Cierre Anterior</TableCell> | ||||
|             <TableCell align="center">% Cambio</TableCell> | ||||
|           </TableRow> | ||||
|         </TableHead> | ||||
|         <TableBody> | ||||
|           {data.map((row) => ( | ||||
|             <TableRow key={row.ticker} hover> | ||||
|               <TableCell component="th" scope="row"> | ||||
|                 <Typography variant="body2" sx={{ fontWeight: 'bold' }}>{row.ticker}</Typography> | ||||
|               </TableCell> | ||||
|               <TableCell align="right">{formatNumber(row.precioActual)}</TableCell> | ||||
|               <TableCell align="right">{formatNumber(row.apertura)}</TableCell> | ||||
|               <TableCell align="right">{formatNumber(row.cierreAnterior)}</TableCell> | ||||
|               <TableCell align="center"> | ||||
|                 <Variacion value={row.porcentajeCambio} /> | ||||
|               </TableCell> | ||||
|             </TableRow> | ||||
|           ))} | ||||
|         </TableBody> | ||||
|       </Table> | ||||
|       <Tooltip title={`Última actualización: ${new Date(data[0].fechaRegistro).toLocaleString('es-AR')}`}> | ||||
|         <Typography variant="caption" sx={{ p: 1, display: 'block', textAlign: 'right', color: 'text.secondary' }}> | ||||
|           Fuente: Finnhub | ||||
|         </Typography> | ||||
|       </Tooltip> | ||||
|     </TableContainer> | ||||
|   ); | ||||
| }; | ||||
| @@ -0,0 +1,80 @@ | ||||
| import { | ||||
|   Box, CircularProgress, Alert, Table, TableBody, TableCell, | ||||
|   TableContainer, TableHead, TableRow, Paper, Typography, Tooltip | ||||
| } from '@mui/material'; | ||||
| import type { CotizacionGrano } from '../models/mercadoModels'; | ||||
| import { useApiData } from '../hooks/useApiData'; | ||||
| import ArrowUpwardIcon from '@mui/icons-material/ArrowUpward'; | ||||
| import ArrowDownwardIcon from '@mui/icons-material/ArrowDownward'; | ||||
| import RemoveIcon from '@mui/icons-material/Remove'; | ||||
|  | ||||
| const formatNumber = (num: number) => { | ||||
|   return new Intl.NumberFormat('es-AR', { | ||||
|     minimumFractionDigits: 2, | ||||
|     maximumFractionDigits: 2, | ||||
|   }).format(num); | ||||
| }; | ||||
|  | ||||
| const Variacion = ({ value }: { value: number }) => { | ||||
|   const color = value > 0 ? 'success.main' : value < 0 ? 'error.main' : 'text.secondary'; | ||||
|   const Icon = value > 0 ? ArrowUpwardIcon : value < 0 ? ArrowDownwardIcon : RemoveIcon; | ||||
|  | ||||
|   return ( | ||||
|     <Box component="span" sx={{ display: 'flex', alignItems: 'center', justifyContent: 'center', color }}> | ||||
|       <Icon sx={{ fontSize: '1rem', mr: 0.5 }} /> | ||||
|       <Typography variant="body2" component="span" sx={{ fontWeight: 'bold' }}> | ||||
|         {formatNumber(value)} | ||||
|       </Typography> | ||||
|     </Box> | ||||
|   ); | ||||
| }; | ||||
|  | ||||
| export const GranosWidget = () => { | ||||
|   const { data, loading, error } = useApiData<CotizacionGrano[]>('/mercados/granos'); | ||||
|  | ||||
|   if (loading) { | ||||
|     return <Box sx={{ display: 'flex', justifyContent: 'center', p: 4 }}><CircularProgress /></Box>; | ||||
|   } | ||||
|  | ||||
|   if (error) { | ||||
|     return <Alert severity="error">{error}</Alert>; | ||||
|   } | ||||
|  | ||||
|   if (!data || data.length === 0) { | ||||
|     return <Alert severity="info">No hay datos de granos disponibles en este momento.</Alert>; | ||||
|   } | ||||
|  | ||||
|   return ( | ||||
|     <TableContainer component={Paper}> | ||||
|       <Table size="small" aria-label="tabla granos"> | ||||
|         <TableHead> | ||||
|           <TableRow> | ||||
|             <TableCell>Grano</TableCell> | ||||
|             <TableCell align="right">Precio ($/Tn)</TableCell> | ||||
|             <TableCell align="center">Variación</TableCell> | ||||
|             <TableCell align="right">Fecha Operación</TableCell> | ||||
|           </TableRow> | ||||
|         </TableHead> | ||||
|         <TableBody> | ||||
|           {data.map((row) => ( | ||||
|             <TableRow key={row.nombre} hover> | ||||
|               <TableCell component="th" scope="row"> | ||||
|                 <Typography variant="body2" sx={{ fontWeight: 'bold' }}>{row.nombre}</Typography> | ||||
|               </TableCell> | ||||
|               <TableCell align="right">${formatNumber(row.precio)}</TableCell> | ||||
|               <TableCell align="center"> | ||||
|                 <Variacion value={row.variacionPrecio} /> | ||||
|               </TableCell> | ||||
|               <TableCell align="right">{new Date(row.fechaOperacion).toLocaleDateString('es-AR')}</TableCell> | ||||
|             </TableRow> | ||||
|           ))} | ||||
|         </TableBody> | ||||
|       </Table> | ||||
|       <Tooltip title={`Última actualización: ${new Date(data[0].fechaRegistro).toLocaleString('es-AR')}`}> | ||||
|         <Typography variant="caption" sx={{ p: 1, display: 'block', textAlign: 'right', color: 'text.secondary' }}> | ||||
|           Fuente: Bolsa de Comercio de Rosario | ||||
|         </Typography> | ||||
|       </Tooltip> | ||||
|     </TableContainer> | ||||
|   ); | ||||
| }; | ||||
| @@ -0,0 +1,69 @@ | ||||
| import { | ||||
|   Box, CircularProgress, Alert, Table, TableBody, TableCell, | ||||
|   TableContainer, TableHead, TableRow, Paper, Typography, Tooltip | ||||
| } from '@mui/material'; | ||||
| import type { CotizacionGanado } from '../models/mercadoModels'; | ||||
| import { useApiData } from '../hooks/useApiData'; | ||||
|  | ||||
| const formatNumber = (num: number, fractionDigits = 2) => { | ||||
|   return new Intl.NumberFormat('es-AR', { | ||||
|     minimumFractionDigits: fractionDigits, | ||||
|     maximumFractionDigits: fractionDigits, | ||||
|   }).format(num); | ||||
| }; | ||||
|  | ||||
| export const MercadoAgroWidget = () => { | ||||
|   const { data, loading, error } = useApiData<CotizacionGanado[]>('/mercados/agroganadero'); | ||||
|  | ||||
|   if (loading) { | ||||
|     return <Box sx={{ display: 'flex', justifyContent: 'center', p: 4 }}><CircularProgress /></Box>; | ||||
|   } | ||||
|  | ||||
|   if (error) { | ||||
|     return <Alert severity="error">{error}</Alert>; | ||||
|   } | ||||
|  | ||||
|   if (!data || data.length === 0) { | ||||
|     return <Alert severity="info">No hay datos del mercado agroganadero disponibles.</Alert>; | ||||
|   } | ||||
|  | ||||
|   return ( | ||||
|     <TableContainer component={Paper}> | ||||
|       <Table size="small" aria-label="tabla mercado agroganadero"> | ||||
|         <TableHead> | ||||
|           <TableRow> | ||||
|             <TableCell>Categoría</TableCell> | ||||
|             <TableCell>Especificaciones</TableCell> | ||||
|             <TableCell align="right">Máximo</TableCell> | ||||
|             <TableCell align="right">Mínimo</TableCell> | ||||
|             <TableCell align="right">Mediano</TableCell> | ||||
|             <TableCell align="right">Cabezas</TableCell> | ||||
|             <TableCell align="right">Kilos Totales</TableCell> | ||||
|             <TableCell align="right">Importe Total</TableCell> | ||||
|           </TableRow> | ||||
|         </TableHead> | ||||
|         <TableBody> | ||||
|           {data.map((row) => ( | ||||
|             <TableRow key={row.id} hover> | ||||
|               <TableCell> | ||||
|                 <Typography variant="body2" sx={{ fontWeight: 'bold' }}>{row.categoria}</Typography> | ||||
|               </TableCell> | ||||
|               <TableCell>{row.especificaciones}</TableCell> | ||||
|               <TableCell align="right">${formatNumber(row.maximo)}</TableCell> | ||||
|               <TableCell align="right">${formatNumber(row.minimo)}</TableCell> | ||||
|               <TableCell align="right">${formatNumber(row.mediano)}</TableCell> | ||||
|               <TableCell align="right">{formatNumber(row.cabezas, 0)}</TableCell> | ||||
|               <TableCell align="right">{formatNumber(row.kilosTotales, 0)} Kg</TableCell> | ||||
|               <TableCell align="right">${formatNumber(row.importeTotal)}</TableCell> | ||||
|             </TableRow> | ||||
|           ))} | ||||
|         </TableBody> | ||||
|       </Table> | ||||
|       <Tooltip title={`Última actualización: ${new Date(data[0].fechaRegistro).toLocaleString('es-AR')}`}> | ||||
|         <Typography variant="caption" sx={{ p: 1, display: 'block', textAlign: 'right', color: 'text.secondary' }}> | ||||
|           Fuente: Mercado Agroganadero S.A. | ||||
|         </Typography> | ||||
|       </Tooltip> | ||||
|     </TableContainer> | ||||
|   ); | ||||
| }; | ||||
		Reference in New Issue
	
	Block a user