Hey is a decentralized and permissionless social media app built with Lens Protocol 馃尶
1import type { AnyPostFragment } from "@hey/indexer";
2import type { ReactNode } from "react";
3import { memo, useRef } from "react";
4import { useNavigate } from "react-router";
5import { usePostLinkStore } from "@/store/non-persisted/navigation/usePostLinkStore";
6
7interface PostWrapperProps {
8 children: ReactNode | ReactNode[];
9 className?: string;
10 post: AnyPostFragment;
11}
12
13const PostWrapper = ({ children, className = "", post }: PostWrapperProps) => {
14 const navigate = useNavigate();
15 const { setCachedPost } = usePostLinkStore();
16 const rootRef = useRef<HTMLElement>(null);
17
18 const handleClick = () => {
19 const selection = window.getSelection();
20 if (!selection || !selection.toString().length) {
21 setCachedPost(post);
22 navigate(`/posts/${post.slug}`);
23 }
24 };
25
26 return (
27 <article className={className} onClick={handleClick} ref={rootRef}>
28 {children}
29 </article>
30 );
31};
32
33export default memo(PostWrapper);