2021-05-27 11:20:34 +03:00
|
|
|
import * as React from "react";
|
|
|
|
|
|
|
|
import { css } from "@emotion/react";
|
2021-07-20 13:20:49 +03:00
|
|
|
import { H5, P3 } from "~/components/system/components/Typography";
|
2021-05-27 11:20:34 +03:00
|
|
|
import { AspectRatio } from "~/components/system";
|
2021-07-27 15:02:21 +03:00
|
|
|
// import { LikeButton, SaveButton } from "./components";
|
|
|
|
// import { useLikeHandler, useSaveHandler } from "~/common/hooks";
|
|
|
|
import { motion } from "framer-motion";
|
2021-05-27 11:20:34 +03:00
|
|
|
|
|
|
|
import ImageObjectPreview from "./ImageObjectPreview";
|
|
|
|
|
2021-07-20 13:20:49 +03:00
|
|
|
const STYLES_WRAPPER = (theme) => css`
|
|
|
|
position: relative;
|
2021-05-27 11:20:34 +03:00
|
|
|
background-color: ${theme.semantic.bgLight};
|
2021-07-20 13:20:49 +03:00
|
|
|
transition: box-shadow 0.2s;
|
2021-08-04 01:31:49 +03:00
|
|
|
box-shadow: 0 0 0 0.5px ${theme.system.grayLight4}, ${theme.shadow.lightSmall};
|
2021-07-20 13:20:49 +03:00
|
|
|
border-radius: 16px;
|
2021-05-27 11:20:34 +03:00
|
|
|
overflow: hidden;
|
2021-07-26 19:44:50 +03:00
|
|
|
cursor: pointer;
|
2021-05-27 11:20:34 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_DESCRIPTION = (theme) => css`
|
2021-08-04 19:17:59 +03:00
|
|
|
position: relative;
|
2021-08-04 01:31:49 +03:00
|
|
|
box-shadow: 0 -0.5px 0.5px ${theme.system.grayLight4};
|
2021-07-20 13:20:49 +03:00
|
|
|
border-radius: 0px 0px 16px 16px;
|
2021-05-27 11:20:34 +03:00
|
|
|
box-sizing: border-box;
|
|
|
|
width: 100%;
|
2021-08-04 19:17:59 +03:00
|
|
|
background-color: ${theme.semantic.bgLight};
|
|
|
|
border-radius: 16px;
|
|
|
|
height: calc(170px + 61px);
|
|
|
|
padding: 9px 16px 8px;
|
|
|
|
z-index: 1;
|
2021-05-27 11:20:34 +03:00
|
|
|
|
|
|
|
@media (max-width: ${theme.sizes.mobile}px) {
|
|
|
|
padding: 8px;
|
|
|
|
}
|
|
|
|
`;
|
2021-07-20 14:31:47 +03:00
|
|
|
|
2021-07-20 13:20:49 +03:00
|
|
|
const STYLES_PREVIEW = css`
|
|
|
|
overflow: hidden;
|
2021-07-26 19:44:50 +03:00
|
|
|
position: relative;
|
2021-08-04 01:31:49 +03:00
|
|
|
bottom: 0.5px;
|
2021-05-27 11:20:34 +03:00
|
|
|
`;
|
|
|
|
|
2021-07-20 13:20:49 +03:00
|
|
|
const STYLES_SELECTED_RING = (theme) => css`
|
|
|
|
box-shadow: 0 0 0 2px ${theme.system.blue};
|
2021-05-27 11:20:34 +03:00
|
|
|
`;
|
|
|
|
|
2021-07-27 15:02:21 +03:00
|
|
|
// const STYLES_CONTROLS = css`
|
|
|
|
// position: absolute;
|
|
|
|
// z-index: 1;
|
|
|
|
// right: 16px;
|
|
|
|
// top: 16px;
|
|
|
|
// & > * + * {
|
|
|
|
// margin-top: 8px !important;
|
|
|
|
// }
|
|
|
|
// `;
|
2021-05-27 11:20:34 +03:00
|
|
|
|
2021-07-26 19:44:50 +03:00
|
|
|
const STYLES_UPPERCASE = css`
|
|
|
|
text-transform: uppercase;
|
|
|
|
`;
|
|
|
|
|
2021-07-20 13:20:49 +03:00
|
|
|
export default function ObjectPreviewPrimitive({
|
2021-05-27 11:20:34 +03:00
|
|
|
children,
|
2021-07-20 13:20:49 +03:00
|
|
|
tag = "FILE",
|
2021-05-27 11:20:34 +03:00
|
|
|
file,
|
|
|
|
isSelected,
|
2021-07-27 15:02:21 +03:00
|
|
|
// viewer,
|
2021-05-27 11:20:34 +03:00
|
|
|
owner,
|
|
|
|
// NOTE(amine): internal prop used to display
|
|
|
|
isImage,
|
|
|
|
onAction,
|
|
|
|
}) {
|
2021-08-04 19:17:59 +03:00
|
|
|
const { isDescriptionVisible, showDescription, hideDescription } = useShowDescription();
|
2021-07-27 15:02:21 +03:00
|
|
|
// const { like, isLiked, likeCount } = useLikeHandler({ file, viewer });
|
|
|
|
// const { save, isSaved, saveCount } = useSaveHandler({ file, viewer });
|
|
|
|
// const showSaveButton = viewer?.id !== file?.ownerId;
|
2021-07-20 14:31:47 +03:00
|
|
|
|
2021-07-27 15:02:21 +03:00
|
|
|
// const [areControlsVisible, setShowControls] = React.useState(false);
|
|
|
|
// const showControls = () => setShowControls(true);
|
|
|
|
// const hideControls = () => setShowControls(false);
|
2021-05-27 11:20:34 +03:00
|
|
|
|
2021-07-20 14:31:47 +03:00
|
|
|
const body = file?.data?.body;
|
2021-08-04 19:17:59 +03:00
|
|
|
const { isLink } = file;
|
2021-07-20 13:20:49 +03:00
|
|
|
|
2021-05-27 11:20:34 +03:00
|
|
|
const title = file.data.name || file.filename;
|
|
|
|
|
2021-08-04 07:42:31 +03:00
|
|
|
if (file?.data?.coverImage && !isImage && !isLink) {
|
2021-05-27 11:20:34 +03:00
|
|
|
return (
|
2021-07-20 13:20:49 +03:00
|
|
|
<ImageObjectPreview
|
|
|
|
file={file}
|
|
|
|
owner={owner}
|
|
|
|
tag={tag}
|
|
|
|
isSelected={isSelected}
|
|
|
|
onAction={onAction}
|
|
|
|
/>
|
2021-05-27 11:20:34 +03:00
|
|
|
);
|
|
|
|
}
|
2021-07-20 14:31:47 +03:00
|
|
|
|
2021-05-27 11:20:34 +03:00
|
|
|
return (
|
2021-07-26 19:44:50 +03:00
|
|
|
<div css={[STYLES_WRAPPER, isSelected && STYLES_SELECTED_RING]}>
|
2021-07-27 15:02:21 +03:00
|
|
|
<div
|
|
|
|
css={STYLES_PREVIEW}
|
|
|
|
// onMouseEnter={showControls} onMouseLeave={hideControls}
|
|
|
|
>
|
|
|
|
{/* <AnimatePresence>
|
2021-07-26 19:44:50 +03:00
|
|
|
{areControlsVisible && (
|
|
|
|
<motion.div
|
|
|
|
initial={{ opacity: 0 }}
|
|
|
|
animate={{ opacity: 1 }}
|
|
|
|
exit={{ opacity: 0 }}
|
|
|
|
css={STYLES_CONTROLS}
|
|
|
|
>
|
|
|
|
<LikeButton onClick={like} isLiked={isLiked} likeCount={likeCount} />
|
|
|
|
{showSaveButton && (
|
|
|
|
<SaveButton onSave={save} isSaved={isSaved} saveCount={saveCount} />
|
|
|
|
)}
|
|
|
|
</motion.div>
|
|
|
|
)}
|
2021-07-27 15:02:21 +03:00
|
|
|
</AnimatePresence> */}
|
2021-07-26 19:44:50 +03:00
|
|
|
<AspectRatio ratio={248 / 248}>
|
|
|
|
<div>{children}</div>
|
|
|
|
</AspectRatio>
|
|
|
|
</div>
|
2021-08-04 19:17:59 +03:00
|
|
|
<div style={{ maxHeight: 61 }}>
|
|
|
|
<motion.article
|
|
|
|
css={STYLES_DESCRIPTION}
|
|
|
|
onMouseMove={showDescription}
|
|
|
|
onMouseLeave={hideDescription}
|
2021-07-20 14:31:47 +03:00
|
|
|
initial={{ y: 0 }}
|
2021-08-04 19:17:59 +03:00
|
|
|
animate={{
|
|
|
|
y: isDescriptionVisible ? -170 : 0,
|
|
|
|
borderRadius: isDescriptionVisible ? "16px" : "0px",
|
|
|
|
}}
|
2021-07-20 14:31:47 +03:00
|
|
|
transition={{ type: "spring", stiffness: 170, damping: 26 }}
|
|
|
|
>
|
2021-08-04 22:06:38 +03:00
|
|
|
<H5 as="h2" nbrOflines={1} color="textBlack" title={title}>
|
2021-07-20 13:20:49 +03:00
|
|
|
{title}
|
|
|
|
</H5>
|
2021-08-04 19:17:59 +03:00
|
|
|
<div style={{ marginTop: 3, display: "flex" }}>
|
2021-07-28 20:50:49 +03:00
|
|
|
{typeof tag === "string" ? (
|
|
|
|
<P3 as="small" css={STYLES_UPPERCASE} color="textGray">
|
|
|
|
{tag}
|
|
|
|
</P3>
|
|
|
|
) : (
|
|
|
|
tag
|
|
|
|
)}
|
|
|
|
</div>
|
2021-07-20 14:31:47 +03:00
|
|
|
<H5
|
2021-07-26 19:44:50 +03:00
|
|
|
as={motion.p}
|
2021-07-20 14:31:47 +03:00
|
|
|
initial={{ opacity: 0 }}
|
2021-08-04 19:17:59 +03:00
|
|
|
animate={{ opacity: isDescriptionVisible ? 1 : 0 }}
|
2021-07-20 14:31:47 +03:00
|
|
|
style={{ marginTop: 5 }}
|
|
|
|
nbrOflines={8}
|
|
|
|
color="textGrayDark"
|
|
|
|
>
|
2021-08-04 01:31:49 +03:00
|
|
|
{body || ""}
|
2021-07-20 14:31:47 +03:00
|
|
|
</H5>
|
2021-08-04 19:17:59 +03:00
|
|
|
</motion.article>
|
|
|
|
</div>
|
2021-05-27 11:20:34 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2021-08-04 19:17:59 +03:00
|
|
|
|
|
|
|
const useShowDescription = () => {
|
|
|
|
const [isDescriptionVisible, setShowDescription] = React.useState(false);
|
|
|
|
const timeoutId = React.useRef();
|
|
|
|
|
|
|
|
const showDescription = () => {
|
|
|
|
clearTimeout(timeoutId.current);
|
|
|
|
const id = setTimeout(() => setShowDescription(true), 250);
|
|
|
|
timeoutId.current = id;
|
|
|
|
};
|
|
|
|
const hideDescription = () => {
|
|
|
|
clearTimeout(timeoutId.current);
|
|
|
|
setShowDescription(false);
|
|
|
|
};
|
|
|
|
|
|
|
|
return { isDescriptionVisible, showDescription, hideDescription };
|
|
|
|
};
|