1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 21:06:42 +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 };

View file

@ -7,20 +7,24 @@ import { INode } from '~/redux/types';
import classNames from 'classnames';
interface IProps {
node: INode;
node: Partial<INode>;
stack?: boolean;
can_edit: boolean;
can_like: boolean;
can_star: boolean;
onEdit: () => void;
onLike: () => void;
onStar: () => void;
}
const NodePanelInner: FC<IProps> = ({
node: { title, user, is_liked },
node: { title, user, is_liked, is_heroic },
stack,
can_star,
can_edit,
can_like,
onStar,
onEdit,
onLike,
}) => {
@ -35,6 +39,15 @@ const NodePanelInner: FC<IProps> = ({
</Group>
<div className={styles.buttons}>
{can_star && (
<div className={classNames(styles.star, { is_heroic })}>
{is_heroic ? (
<Icon icon="star_full" size={24} onClick={onStar} />
) : (
<Icon icon="star" size={24} onClick={onStar} />
)}
</div>
)}
{can_edit && (
<div>
<Icon icon="edit" size={24} onClick={onEdit} />

View file

@ -166,3 +166,18 @@
animation: pulse 0.75s infinite;
}
}
.star {
transition: fill, stroke 0.25s;
will-change: transform;
&:global(.is_heroic) {
svg {
fill: $orange;
}
}
&:hover {
fill: $orange;
}
}