adding new files
parent
2af9d9e15d
commit
c98fdec10e
@ -0,0 +1,28 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { useFocus } from "../../hooks/useFocus"
|
||||||
|
import { InView } from 'react-intersection-observer';
|
||||||
|
|
||||||
|
type ReadableMessageProps = {
|
||||||
|
children: React.ReactNode;
|
||||||
|
id: string;
|
||||||
|
className: string;
|
||||||
|
onChange: (inView: boolean) => void;
|
||||||
|
onContextMenu: (e: any) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ReadableMessage = (props: ReadableMessageProps) => {
|
||||||
|
|
||||||
|
const { onChange } = props;
|
||||||
|
useFocus(onChange);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<InView
|
||||||
|
{...props}
|
||||||
|
as="div"
|
||||||
|
threshold={1}
|
||||||
|
delay={200}
|
||||||
|
triggerOnce={true}
|
||||||
|
>
|
||||||
|
{props.children}
|
||||||
|
</InView>);
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
import { useEffect } from "react";
|
||||||
|
|
||||||
|
export const useFocus = (action: (param: any) => void) => {
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
window.addEventListener("focus", action);
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("focus", action);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue