Skip to content

Commit

Permalink
Try fixing build
Browse files Browse the repository at this point in the history
  • Loading branch information
ajnart committed Oct 10, 2024
1 parent f553c92 commit bd902d6
Showing 1 changed file with 43 additions and 57 deletions.
100 changes: 43 additions & 57 deletions src/components/ui/link-preview.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
"use client";
import * as HoverCardPrimitive from "@radix-ui/react-hover-card";
import {
AnimatePresence,
motion,
useMotionValue,
useSpring,
} from "framer-motion";
import Image from "next/image";
import Link from "next/link";
import { encode } from "qss";
import React from "react";
import { cn } from "~/lib/utils";
'use client'
import * as HoverCardPrimitive from '@radix-ui/react-hover-card'
import { AnimatePresence, motion, useMotionValue, useSpring } from 'framer-motion'
import Image from 'next/image'
import Link from 'next/link'
import { encode } from 'qss'
import React from 'react'
import { cn } from '~/lib/utils'

type LinkPreviewProps = {
children: React.ReactNode;
url: string;
className?: string;
width?: number;
height?: number;
quality?: number;
} & (
| { isStatic: true; imageSrc: string }
| { isStatic?: false; imageSrc?: never }
);
children: React.ReactNode
url: string
className?: string
width?: number
height?: number
quality?: number
} & ({ isStatic: true; imageSrc: string } | { isStatic?: false; imageSrc?: never })

export const LinkPreview = ({
children,
Expand All @@ -32,71 +24,65 @@ export const LinkPreview = ({
height = 125,
quality = 50,
isStatic = false,
imageSrc = "",
imageSrc = '',
}: LinkPreviewProps) => {
let src;
let src
if (!isStatic) {
const params = encode({
url,
screenshot: true,
meta: false,
embed: "screenshot.url",
colorScheme: "dark",
"viewport.isMobile": true,
"viewport.deviceScaleFactor": 1,
"viewport.width": width * 3,
"viewport.height": height * 3,
});
src = `https://api.microlink.io/?${params}`;
embed: 'screenshot.url',
colorScheme: 'dark',
'viewport.isMobile': true,
'viewport.deviceScaleFactor': 1,
'viewport.width': width * 3,
'viewport.height': height * 3,
})
src = `https://api.microlink.io/?${params}`
} else {
src = imageSrc;
src = imageSrc
}

const [isOpen, setOpen] = React.useState(false);
const [isOpen, setOpen] = React.useState(false)

const [isMounted, setIsMounted] = React.useState(false);
const [isMounted, setIsMounted] = React.useState(false)

React.useEffect(() => {
setIsMounted(true);
}, []);
setIsMounted(true)
}, [])

const springConfig = { stiffness: 100, damping: 15 };
const x = useMotionValue(0);
const springConfig = { stiffness: 100, damping: 15 }
const x = useMotionValue(0)

const translateX = useSpring(x, springConfig);
const translateX = useSpring(x, springConfig)

const handleMouseMove = (event: any) => {
const targetRect = event.target.getBoundingClientRect();
const handleMouseMove = (event: React.MouseEvent<HTMLAnchorElement>) => {
const target = event.currentTarget;
const targetRect = target.getBoundingClientRect();
const eventOffsetX = event.clientX - targetRect.left;
const offsetFromCenter = (eventOffsetX - targetRect.width / 2) / 2; // Reduce the effect to make it subtle
const offsetFromCenter = (eventOffsetX - targetRect.width / 2) / 2;
x.set(offsetFromCenter);
};

return (
<>
{isMounted ? (
<div className="hidden">
<Image
src={src}
width={width}
height={height}
quality={quality}
priority={true}
alt="hidden image"
/>
<Image src={src} width={width} height={height} quality={quality} priority={true} alt="hidden image" />
</div>
) : null}

<HoverCardPrimitive.Root
openDelay={50}
closeDelay={100}
onOpenChange={(open) => {
setOpen(open);
setOpen(open)
}}
>
<HoverCardPrimitive.Trigger
onMouseMove={handleMouseMove}
className={cn("text-black dark:text-white", className)}
className={cn('text-black dark:text-white', className)}
href={url}
>
{children}
Expand All @@ -118,7 +104,7 @@ export const LinkPreview = ({
y: 0,
scale: 1,
transition: {
type: "spring",
type: 'spring',
stiffness: 260,
damping: 20,
},
Expand Down Expand Up @@ -150,5 +136,5 @@ export const LinkPreview = ({
</HoverCardPrimitive.Content>
</HoverCardPrimitive.Root>
</>
);
};
)
}

0 comments on commit bd902d6

Please sign in to comment.