From 2d8ff4baf7182e363bfce57d0b80212ae2d1d4b3 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 27 Dec 2021 11:02:47 +0100 Subject: [PATCH] linting --- .../src/lib/custom-hooks/useDragTerminal.tsx | 116 +++++++++--------- .../terminal/src/lib/remix-ui-terminal.tsx | 5 +- 2 files changed, 59 insertions(+), 62 deletions(-) diff --git a/libs/remix-ui/terminal/src/lib/custom-hooks/useDragTerminal.tsx b/libs/remix-ui/terminal/src/lib/custom-hooks/useDragTerminal.tsx index cdd4f6dc6a..1416ff2ddb 100644 --- a/libs/remix-ui/terminal/src/lib/custom-hooks/useDragTerminal.tsx +++ b/libs/remix-ui/terminal/src/lib/custom-hooks/useDragTerminal.tsx @@ -1,77 +1,77 @@ import { useEffect, useState } from 'react' export const useDragTerminal = (minHeight: number, defaultPosition: number) => { - const [isOpen, setIsOpen] = useState(defaultPosition > minHeight) - const [lastYPosition, setLastYPosition] = useState(0) - const [terminalPosition, setTerminalPosition] = useState(defaultPosition) - // Used to save position of the terminal when it is closed - const [lastTerminalPosition, setLastTerminalPosition] = useState(defaultPosition) - const [isDragging, setIsDragging] = useState(false) + const [isOpen, setIsOpen] = useState(defaultPosition > minHeight) + const [lastYPosition, setLastYPosition] = useState(0) + const [terminalPosition, setTerminalPosition] = useState(defaultPosition) + // Used to save position of the terminal when it is closed + const [lastTerminalPosition, setLastTerminalPosition] = useState(defaultPosition) + const [isDragging, setIsDragging] = useState(false) - const handleDraggingStart = (event: React.MouseEvent) => { - setLastYPosition(event.clientY) - setIsDragging(true) - } + const handleDraggingStart = (event: React.MouseEvent) => { + setLastYPosition(event.clientY) + setIsDragging(true) + } - const handleDragging = (event: MouseEvent) => { - event.preventDefault() + const handleDragging = (event: MouseEvent) => { + event.preventDefault() - if (isDragging) { - const mouseYPosition = event.clientY - const difference = lastYPosition - mouseYPosition - const newTerminalPosition = terminalPosition + difference - setTerminalPosition(newTerminalPosition) - setLastYPosition(mouseYPosition) - } + if (isDragging) { + const mouseYPosition = event.clientY + const difference = lastYPosition - mouseYPosition + const newTerminalPosition = terminalPosition + difference + setTerminalPosition(newTerminalPosition) + setLastYPosition(mouseYPosition) } + } - const handleDraggingEnd = () => { - if(!isDragging) return - - setIsDragging(false) + const handleDraggingEnd = () => { + if (!isDragging) return - // Check terminal position to determine if it should be open or closed - setIsOpen(terminalPosition > minHeight) - } + setIsDragging(false) - const handleToggleTerminal = (event: React.MouseEvent) => { - event.preventDefault() - event.stopPropagation() + // Check terminal position to determine if it should be open or closed + setIsOpen(terminalPosition > minHeight) + } - if(isOpen) { - setLastTerminalPosition(terminalPosition) - setLastYPosition(0) - setTerminalPosition(minHeight) - } else { - setTerminalPosition(lastTerminalPosition <= minHeight ? 323 : lastTerminalPosition) - } + const handleToggleTerminal = (event: React.MouseEvent) => { + event.preventDefault() + event.stopPropagation() - setIsOpen(!isOpen) + if (isOpen) { + setLastTerminalPosition(terminalPosition) + setLastYPosition(0) + setTerminalPosition(minHeight) + } else { + setTerminalPosition(lastTerminalPosition <= minHeight ? 323 : lastTerminalPosition) } - // Add event listeners for dragging - useEffect(() => { - document.addEventListener('mousemove', handleDragging) - document.addEventListener('mouseup', handleDraggingEnd) + setIsOpen(!isOpen) + } - return () => { - document.removeEventListener('mousemove', handleDragging) - document.removeEventListener('mouseup', handleDraggingEnd) - } - }, [handleDragging, handleDraggingEnd]) + // Add event listeners for dragging + useEffect(() => { + document.addEventListener('mousemove', handleDragging) + document.addEventListener('mouseup', handleDraggingEnd) - // Reset terminal position - useEffect(() => { - if(!terminalPosition){ - setTerminalPosition(defaultPosition) - } - }, [terminalPosition, setTerminalPosition]) + return () => { + document.removeEventListener('mousemove', handleDragging) + document.removeEventListener('mouseup', handleDraggingEnd) + } + }, [handleDragging, handleDraggingEnd]) - return { - isOpen, - terminalPosition, - isDragging, - handleDraggingStart, - handleToggleTerminal, + // Reset terminal position + useEffect(() => { + if (!terminalPosition) { + setTerminalPosition(defaultPosition) } + }, [terminalPosition, setTerminalPosition]) + + return { + isOpen, + terminalPosition, + isDragging, + handleDraggingStart, + handleToggleTerminal, + } } \ No newline at end of file diff --git a/libs/remix-ui/terminal/src/lib/remix-ui-terminal.tsx b/libs/remix-ui/terminal/src/lib/remix-ui-terminal.tsx index de6de4eb23..8cc0829796 100644 --- a/libs/remix-ui/terminal/src/lib/remix-ui-terminal.tsx +++ b/libs/remix-ui/terminal/src/lib/remix-ui-terminal.tsx @@ -95,7 +95,7 @@ export const RemixUiTerminal = (props: RemixUiTerminalProps) => { useEffect(() => { event.trigger('resize', [terminalPosition]) - } , [terminalPosition]) + }, [terminalPosition]) const scrollToBottom = () => { messagesEndRef.current.scrollIntoView({ behavior: 'smooth' }) @@ -211,9 +211,6 @@ export const RemixUiTerminal = (props: RemixUiTerminalProps) => { } } - - - const focusinput = () => { inputEl.current.focus() }