feat: preview arbitrary url

This commit is contained in:
Apoorv Mishra
2023-07-24 20:59:32 +05:30
parent b3d8bd1cc8
commit 81bd68380e
3 changed files with 45 additions and 2 deletions

View File

@@ -27,6 +27,10 @@ export const Info: React.FC = ({ children }) => (
</StyledText>
);
export const Description: React.FC = styled(StyledText)`
margin-top: 0.5em;
`;
export const DescriptionContainer = styled.div`
margin-top: 0.5em;
`;

View File

@@ -13,6 +13,7 @@ import useRequest from "~/hooks/useRequest";
import useStores from "~/hooks/useStores";
import { client } from "~/utils/ApiClient";
import HoverPreviewDocument from "./HoverPreviewDocument";
import HoverPreviewLink from "./HoverPreviewLink";
import HoverPreviewMention from "./HoverPreviewMention";
const DELAY_OPEN = 300;
@@ -167,7 +168,14 @@ function HoverPreviewInternal({ element, onClose }: Props) {
description={data.description}
info={data.meta.info}
/>
) : null}
) : (
<HoverPreviewLink
url={data.url}
thumbnailUrl={data.thumbnailUrl}
title={data.title}
description={data.description}
/>
)}
</CardContent>
</Card>
<Pointer offset={leftOffset + elemBounds.width / 2} />
@@ -196,7 +204,7 @@ const Animate = styled(m.div)`
const CardContent = styled.div`
overflow: hidden;
max-height: 20em;
max-height: 20.5em;
user-select: none;
`;

View File

@@ -0,0 +1,31 @@
import * as React from "react";
import Img from "@shared/editor/components/Img";
import Flex from "~/components/Flex";
import { Preview, Title, Description } from "./Components";
type Props = {
/** Link url */
url: string;
/** Title for the preview card */
title: string;
/** Url for thumbnail served by the link provider*/
thumbnailUrl: string;
/** Some description about the link provider */
description: string;
};
function HoverPreviewLink({ url, thumbnailUrl, title, description }: Props) {
return (
<Preview to={url}>
<Flex gap={12} column>
<Img src={thumbnailUrl} alt={""} />
<Flex column>
<Title>{title}</Title>
<Description>{description}</Description>
</Flex>
</Flex>
</Preview>
);
}
export default HoverPreviewLink;