Skip to content

Commit

Permalink
we like mobile too
Browse files Browse the repository at this point in the history
  • Loading branch information
kirkas committed Sep 13, 2024
1 parent c5d3733 commit 5b02bd0
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions apps/web/src/components/base-org/Card/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,19 @@ export default function CardsProvider({ children }: CardsProviderProps) {
const [cards, setCards] = useState<Record<string, CardRef>>({});

useEffect(() => {
const handleMouseMove = (ev: MouseEvent) => {
const handleInteraction = (ev: MouseEvent | TouchEvent) => {
const clientX = 'touches' in ev ? ev.touches[0].clientX : ev.clientX;
const clientY = 'touches' in ev ? ev.touches[0].clientY : ev.clientY;

Object.values(cards).forEach(({ blobRef, fakeBlobRef }) => {
if (blobRef.current && fakeBlobRef.current) {
const rec = fakeBlobRef.current.getBoundingClientRect();

blobRef.current.animate(
[
{
transform: `translate(${ev.clientX - rec.left - rec.width / 2}px,${
ev.clientY - rec.top - rec.height / 2
transform: `translate(${clientX - rec.left - rec.width / 2}px,${
clientY - rec.top - rec.height / 2
}px)`,
},
],
Expand All @@ -72,10 +75,12 @@ export default function CardsProvider({ children }: CardsProviderProps) {
});
};

window.addEventListener('mousemove', handleMouseMove);
window.addEventListener('mousemove', handleInteraction);
window.addEventListener('touchmove', handleInteraction);

return () => {
window.removeEventListener('mousemove', handleMouseMove);
window.removeEventListener('mousemove', handleInteraction);
window.removeEventListener('touchmove', handleInteraction);
};
}, [cards]);

Expand Down

0 comments on commit 5b02bd0

Please sign in to comment.