diff --git a/src/components/molecules/InterpretationLog.tsx b/src/components/molecules/InterpretationLog.tsx index e16a9314..5fe30d2e 100644 --- a/src/components/molecules/InterpretationLog.tsx +++ b/src/components/molecules/InterpretationLog.tsx @@ -20,33 +20,17 @@ import TableRow from '@mui/material/TableRow'; import Paper from '@mui/material/Paper'; import StorageIcon from '@mui/icons-material/Storage'; -function createData( - name: string, - calories: number, - fat: number, - carbs: number, - protein: number, -) { - return { name, calories, fat, carbs, protein }; -} - -const rows = [ - createData('Frozen yoghurt', 159, 6.0, 24, 4.0), - createData('Ice cream sandwich', 237, 9.0, 37, 4.3), - createData('Eclair', 262, 16.0, 24, 6.0), - createData('Cupcake', 305, 3.7, 67, 4.3), - createData('Gingerbread', 356, 16.0, 49, 3.9), -]; - export const InterpretationLog = () => { const [open, setOpen] = useState(false); const [log, setLog] = useState(''); const [selectedOption, setSelectedOption] = useState('10'); const [customValue, setCustomValue] = useState(''); + const [tableData, setTableData] = useState([]); // State for table data const logEndRef = useRef(null); const { width } = useBrowserDimensionsStore(); + const { socket } = useSocketStore(); const toggleDrawer = (newOpen: boolean) => (event: React.KeyboardEvent | React.MouseEvent) => { if ( @@ -59,8 +43,6 @@ export const InterpretationLog = () => { setOpen(newOpen); }; - const { socket } = useSocketStore(); - const scrollLogToBottom = () => { if (logEndRef.current) { logEndRef.current.scrollIntoView({ behavior: "smooth" }); @@ -76,10 +58,16 @@ export const InterpretationLog = () => { scrollLogToBottom(); }, [log, scrollLogToBottom]); - const handleSerializableCallback = useCallback((data: string) => { + const handleSerializableCallback = useCallback((data: any) => { setLog((prevState) => prevState + '\n' + '---------- Serializable output data received ----------' + '\n' + JSON.stringify(data, null, 2) + '\n' + '--------------------------------------------------'); + + // Set table data + if (Array.isArray(data)) { + setTableData(data); + } + scrollLogToBottom(); }, [log, scrollLogToBottom]); @@ -108,8 +96,11 @@ export const InterpretationLog = () => { socket?.off('serializableCallback', handleSerializableCallback); socket?.off('binaryCallback', handleBinaryCallback); }; - }, [socket, handleLog]); + }, [socket, handleLog, handleSerializableCallback, handleBinaryCallback]); + // Extract columns dynamically from the first item of tableData + const columns = tableData.length > 0 ? Object.keys(tableData[0]) : []; + return (