mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-06-03 08:28:54 -04:00
fix: extract app bar into layout slot
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
18a1e79d9f
commit
b3fb1bbf30
35 changed files with 258 additions and 207 deletions
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
import useResizeObserver from '@react-hook/resize-observer'
|
||||
import type { RefObject } from 'react'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
|
||||
/**
|
||||
* Monitors the height of the referenced {@link HTMLElement} and executes the callback on change.
|
||||
|
@ -18,6 +18,7 @@ export const useOnHeightChange = (
|
|||
onHeightChange: undefined | ((value: number) => void)
|
||||
): void => {
|
||||
const [rendererSize, setRendererSize] = useState<number>(0)
|
||||
const lastPostedSize = useRef<number>(0)
|
||||
useResizeObserver(elementRef, (entry) => {
|
||||
setRendererSize(entry.contentRect.height)
|
||||
})
|
||||
|
@ -29,6 +30,10 @@ export const useOnHeightChange = (
|
|||
setRendererSize(value)
|
||||
}, [elementRef])
|
||||
useEffect(() => {
|
||||
if (lastPostedSize.current === rendererSize) {
|
||||
return
|
||||
}
|
||||
lastPostedSize.current = rendererSize
|
||||
onHeightChange?.(rendererSize + 1)
|
||||
}, [rendererSize, onHeightChange])
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue