get saved terminal position

pull/5370/head
Josel95 3 years ago
parent cc5a763083
commit ce5552b767
  1. 16
      libs/remix-ui/terminal/src/lib/custom-hooks/useDragTerminal.tsx
  2. 7
      libs/remix-ui/terminal/src/lib/remix-ui-terminal.tsx

@ -1,11 +1,11 @@
import { useEffect, useState } from 'react'
export const useDragTerminal = (offsetHeight: number) => {
const [isOpen, setIsOpen] = useState(true)
export const useDragTerminal = (minHeight: number, defaultPosition: number) => {
const [isOpen, setIsOpen] = useState(defaultPosition > minHeight)
const [lastYPosition, setLastYPosition] = useState(0)
const [terminalPosition, setTerminalPosition] = useState(offsetHeight)
const [terminalPosition, setTerminalPosition] = useState(defaultPosition)
// Used to save position of the terminal when it is closed
const [lastTerminalPosition, setLastTerminalPosition] = useState(offsetHeight)
const [lastTerminalPosition, setLastTerminalPosition] = useState(defaultPosition)
const [isDragging, setIsDragging] = useState(false)
const handleDraggingStart = (event: React.MouseEvent) => {
@ -31,7 +31,7 @@ export const useDragTerminal = (offsetHeight: number) => {
setIsDragging(false)
// Check terminal position to determine if it should be open or closed
setIsOpen(terminalPosition > offsetHeight)
setIsOpen(terminalPosition > minHeight)
}
const handleToggleTerminal = (event: React.MouseEvent<HTMLElement>) => {
@ -41,9 +41,9 @@ export const useDragTerminal = (offsetHeight: number) => {
if(isOpen) {
setLastTerminalPosition(terminalPosition)
setLastYPosition(0)
setTerminalPosition(offsetHeight)
setTerminalPosition(minHeight)
} else {
setTerminalPosition(lastTerminalPosition)
setTerminalPosition(lastTerminalPosition <= minHeight ? 323 : lastTerminalPosition)
}
setIsOpen(!isOpen)
@ -63,7 +63,7 @@ export const useDragTerminal = (offsetHeight: number) => {
// Reset terminal position
useEffect(() => {
if(!terminalPosition){
setTerminalPosition(offsetHeight)
setTerminalPosition(defaultPosition)
}
}, [terminalPosition, setTerminalPosition])

@ -76,13 +76,16 @@ export const RemixUiTerminal = (props: RemixUiTerminalProps) => {
const panelRef = useRef(null)
const terminalMenu = useRef(null)
const terminalMenuOffsetHeight = (terminalMenu.current && terminalMenu.current.offsetHeight) || 35
const terminalDefaultPosition = config.get('terminal-top-offset')
const {
isOpen,
isDragging,
terminalPosition,
handleDraggingStart,
handleToggleTerminal
} = useDragTerminal((terminalMenu.current && terminalMenu.current.offsetHeight) || 0)
} = useDragTerminal(terminalMenuOffsetHeight, terminalDefaultPosition)
// Check open state
useEffect(() => {
@ -96,7 +99,7 @@ export const RemixUiTerminal = (props: RemixUiTerminalProps) => {
}, [isDragging])
useEffect(() => {
event.trigger('resize', [terminalPosition + 32])
event.trigger('resize', [terminalPosition])
} , [terminalPosition])
const scrollToBottom = () => {

Loading…
Cancel
Save