diff --git a/components/ContentLink.tsx b/components/ContentLink.tsx index 12853d5..7673e7a 100644 --- a/components/ContentLink.tsx +++ b/components/ContentLink.tsx @@ -1,4 +1,4 @@ -import { PropsWithChildren, useContext } from 'react'; +import { forwardRef, useContext } from 'react'; import { Content } from 'data/graphql-generated'; import { Link } from 'components'; @@ -6,35 +6,41 @@ import { LinkProps } from '@mui/material'; import UserContext from 'app/UserContext'; import { contentUrl } from 'util/url-factory'; -const ContentLink: React.FC< - PropsWithChildren<{ - item: Pick; - currentContent?: Content; - rel?: string; - url?: string; - className?: string; - sx?: LinkProps['sx']; - }> -> = (props) => { - const { user } = useContext(UserContext); +const ContentLink = forwardRef( + ( + props: { + children: JSX.Element; + item: Pick; + currentContent?: Content; + rel?: string; + url?: string; + className?: string; + sx?: LinkProps['sx']; + }, + ref + ) => { + const { user } = useContext(UserContext); - const item = props.item; - const currentContent = props.currentContent || { forceRefresh: false }; - const isOwnerViewing = user?.username === item.username; - const { rel, url } = props; + const item = props.item; + const currentContent = props.currentContent || { forceRefresh: false }; + const isOwnerViewing = user?.username === item.username; + const { rel, url } = props; - return ( - - {props.children} - - ); -}; + return ( + + {props.children} + + ); + } +); +ContentLink.displayName = 'ContentLink'; export default ContentLink; diff --git a/components/ItemWrapper.tsx b/components/ItemWrapper.tsx index 59f12f1..d8eaa82 100644 --- a/components/ItemWrapper.tsx +++ b/components/ItemWrapper.tsx @@ -1,4 +1,4 @@ -import { PropsWithChildren } from 'react'; +import { forwardRef } from 'react'; import { styled } from '@mui/material/styles'; const StyledItemWrapper = styled('div', { label: 'ItemWrapper' })` @@ -86,8 +86,14 @@ const StyledItemWrapper = styled('div', { label: 'ItemWrapper' })` } `; -const ItemWrapper: React.FC> = ({ children, className }) => { - return {children}; -}; +const ItemWrapper = forwardRef(({ children, className }: { children: JSX.Element; className?: string }, ref) => { + // @ts-ignore this is fine. + return ( + + {children} + + ); +}); +ItemWrapper.displayName = 'ItemWrapper'; export default ItemWrapper; diff --git a/components/Link.tsx b/components/Link.tsx index 6a4e837..a96f59b 100644 --- a/components/Link.tsx +++ b/components/Link.tsx @@ -2,13 +2,22 @@ import { ForwardedRef, forwardRef } from 'react'; import { Link as MuiLink, LinkProps as MuiLinkProps } from '@mui/material'; import NextLink, { LinkProps } from 'next/link'; -const BaseLink: React.FC = ({ children, as, href, shallow, target, ...props }) => ( - - - {children} - - +const BaseLink: React.FC = forwardRef( + ({ children, as, href, shallow, target, ...props }, ref) => ( + + + {children} + + + ) ); +BaseLink.displayName = 'BaseLink'; // @ts-ignore const Link = forwardRef(function ForwardedLink(props: MuiLinkProps & LinkProps, ref: ForwardedRef) { diff --git a/components/content/Item.tsx b/components/content/Item.tsx index 5e13978..8f761d9 100644 --- a/components/content/Item.tsx +++ b/components/content/Item.tsx @@ -9,7 +9,8 @@ import Footer from './Footer'; import Header from './Header'; import Latest from './templates/Latest'; import Simple from './templates/Simple'; -//import { animated, useTransition } from 'react-spring'; +import { forwardRef } from 'react'; +import { animated, useTransition } from 'react-spring'; const StyledItem = styled('article', { label: 'Item' })` display: flex; @@ -30,44 +31,58 @@ const COMPONENT_TYPE_MAP = { links: Album, }; -export default function Item(props: { - className?: string; - content: Content; - contentOwner: UserPublic; - comments?: Comment[]; - favorites?: Favorite[]; - isFeed?: boolean; -}) { - // const transitions = useTransition(props.content, { - // from: { opacity: 0 }, - // enter: { opacity: 1 }, - // leave: { display: 'none', opacity: 0 }, - // }); +const Item = forwardRef( + ( + props: { + className?: string; + content: Content; + contentOwner: UserPublic; + comments?: Comment[]; + favorites?: Favorite[]; + isFeed?: boolean; + }, + ref + ) => { + const transitions = useTransition(props.content, { + from: { opacity: 0 }, + enter: { opacity: 1 }, + leave: { display: 'none', opacity: 0 }, + }); - // TODO - //const template = useRef(null); + // TODO + //const template = useRef(null); - // useImperativeHandle(ref, () => ({ - // getEditor: () => { - // return template.current?.getEditor && template.current.getEditor(); - // }, - // })); + // useImperativeHandle(ref, () => ({ + // getEditor: () => { + // return template.current?.getEditor && template.current.getEditor(); + // }, + // })); - const { className, content, contentOwner, comments, favorites, isFeed } = props; - /* @ts-ignore */ - const TemplateComponent = COMPONENT_TYPE_MAP[content.template] || Simple; - const contentComponent = ; + const { className, content, contentOwner, comments, favorites, isFeed } = props; + /* @ts-ignore */ + const TemplateComponent = COMPONENT_TYPE_MAP[content.template] || Simple; + const contentComponent = ; - return ( - - -
- {/* @ts-ignore */} - {COMPONENT_TYPE_MAP[content.template] ? contentComponent : {contentComponent}} -