From c656b5782a61571066947a82ec763a8836aea974 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 22 Aug 2024 05:37:25 +0530 Subject: [PATCH] feat: use Swipeable Drawer instead of Accordian --- .../molecules/InterpretationLog.tsx | 86 ++++++++++--------- 1 file changed, 44 insertions(+), 42 deletions(-) diff --git a/src/components/molecules/InterpretationLog.tsx b/src/components/molecules/InterpretationLog.tsx index 02592511..296acc97 100644 --- a/src/components/molecules/InterpretationLog.tsx +++ b/src/components/molecules/InterpretationLog.tsx @@ -1,30 +1,34 @@ import * as React from 'react'; -import Accordion from '@mui/material/Accordion'; -import AccordionDetails from '@mui/material/AccordionDetails'; -import AccordionSummary from '@mui/material/AccordionSummary'; +import SwipeableDrawer from '@mui/material/SwipeableDrawer'; import Typography from '@mui/material/Typography'; -import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; -import Highlight from 'react-highlight' +import Highlight from 'react-highlight'; import { useCallback, useEffect, useRef, useState } from "react"; import { useSocketStore } from "../../context/socket"; export const InterpretationLog = () => { - const [expanded, setExpanded] = useState(false); + const [open, setOpen] = useState(false); const [log, setLog] = useState(''); const logEndRef = useRef(null); - const handleChange = (isExpanded: boolean) => (event: React.SyntheticEvent) => { - setExpanded(isExpanded); + const toggleDrawer = (newOpen: boolean) => (event: React.KeyboardEvent | React.MouseEvent) => { + if ( + event.type === 'keydown' && + ((event as React.KeyboardEvent).key === 'Tab' || + (event as React.KeyboardEvent).key === 'Shift') + ) { + return; + } + setOpen(newOpen); }; const { socket } = useSocketStore(); const scrollLogToBottom = () => { if (logEndRef.current) { - logEndRef.current.scrollIntoView({ behavior: "smooth" }) + logEndRef.current.scrollIntoView({ behavior: "smooth" }); } - } + }; const handleLog = useCallback((msg: string, date: boolean = true) => { if (!date) { @@ -33,14 +37,14 @@ export const InterpretationLog = () => { setLog((prevState) => prevState + '\n' + `[${new Date().toLocaleString()}] ` + msg); } scrollLogToBottom(); - }, [log, scrollLogToBottom]) + }, [scrollLogToBottom]); const handleSerializableCallback = useCallback((data: string) => { setLog((prevState) => prevState + '\n' + '---------- Serializable output data received ----------' + '\n' + JSON.stringify(data, null, 2) + '\n' + '--------------------------------------------------'); scrollLogToBottom(); - }, [log, scrollLogToBottom]) + }, [scrollLogToBottom]); const handleBinaryCallback = useCallback(({ data, mimetype }: any) => { setLog((prevState) => @@ -48,7 +52,7 @@ export const InterpretationLog = () => { + `mimetype: ${mimetype}` + '\n' + `data: ${JSON.stringify(data)}` + '\n' + '------------------------------------------------'); scrollLogToBottom(); - }, [log, scrollLogToBottom]) + }, [scrollLogToBottom]); useEffect(() => { socket?.on('log', handleLog); @@ -58,41 +62,39 @@ export const InterpretationLog = () => { socket?.off('log', handleLog); socket?.off('serializableCallback', handleSerializableCallback); socket?.off('binaryCallback', handleBinaryCallback); - } - }, [socket, handleLog]) + }; + }, [socket, handleLog]); return (
- + Interpretation Log + + - } - aria-controls="panel1bh-content" - id="panel1bh-header" - > - - Interpretation Log - - - + Interpretation Log + +
-
- - {log} - -
-
- - + + {log} + +
+
+
); }