1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-26 13:26:40 +07:00

added nodes heroize button

This commit is contained in:
Fedor Katurov 2019-10-23 12:02:35 +07:00
parent c49dbb344d
commit 6b5638b44e
11 changed files with 140 additions and 47 deletions

View file

@ -3,67 +3,77 @@ import * as styles from './styles.scss';
import { INode } from '~/redux/types';
import { createPortal } from 'react-dom';
import { NodePanelInner } from '~/components/node/NodePanelInner';
import pick from 'ramda/es/pick';
interface IProps {
node: INode;
node: Partial<INode>;
layout: {};
can_edit: boolean;
can_like: boolean;
can_star: boolean;
onEdit: () => void;
onLike: () => void;
onStar: () => void;
}
const NodePanel: FC<IProps> = memo(({ node, layout, can_edit, can_like, onEdit, onLike }) => {
const [stack, setStack] = useState(false);
const NodePanel: FC<IProps> = memo(
({ node, layout, can_edit, can_like, can_star, onEdit, onLike, onStar }) => {
const [stack, setStack] = useState(false);
const ref = useRef(null);
const getPlace = useCallback(() => {
if (!ref.current) return;
const ref = useRef(null);
const getPlace = useCallback(() => {
if (!ref.current) return;
const { offsetTop } = ref.current;
const { height } = ref.current.getBoundingClientRect();
const { scrollY, innerHeight } = window;
const { offsetTop } = ref.current;
const { height } = ref.current.getBoundingClientRect();
const { scrollY, innerHeight } = window;
setStack(offsetTop > scrollY + innerHeight - height);
}, [ref]);
setStack(offsetTop > scrollY + innerHeight - height);
}, [ref]);
useEffect(() => {
getPlace();
window.addEventListener('scroll', getPlace);
window.addEventListener('resize', getPlace);
useEffect(() => {
getPlace();
window.addEventListener('scroll', getPlace);
window.addEventListener('resize', getPlace);
return () => {
window.removeEventListener('scroll', getPlace);
window.removeEventListener('resize', getPlace);
};
}, [layout]);
return () => {
window.removeEventListener('scroll', getPlace);
window.removeEventListener('resize', getPlace);
};
}, [layout]);
return (
<div className={styles.place} ref={ref}>
{stack ? (
createPortal(
return (
<div className={styles.place} ref={ref}>
{stack ? (
createPortal(
<NodePanelInner
node={node}
stack
onEdit={onEdit}
onLike={onLike}
onStar={onStar}
can_edit={can_edit}
can_like={can_like}
can_star={can_star}
/>,
document.body
)
) : (
<NodePanelInner
node={node}
stack
onEdit={onEdit}
onLike={onLike}
onStar={onStar}
can_edit={can_edit}
can_like={can_like}
/>,
document.body
)
) : (
<NodePanelInner
node={node}
onEdit={onEdit}
onLike={onLike}
can_edit={can_edit}
can_like={can_like}
/>
)}
</div>
);
});
can_star={can_star}
/>
)}
</div>
);
}
);
export { NodePanel };