From 39f35f7d5f8ecda172d6c15bb118683e2836c240 Mon Sep 17 00:00:00 2001 From: killerboss Date: Thu, 31 Oct 2024 22:16:00 +0100 Subject: [PATCH] Add support for multilanguage blog --- blog/more-stories.tsx | 7 ++++--- cursor.jsx | 46 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/blog/more-stories.tsx b/blog/more-stories.tsx index 17191da..1fd5e96 100644 --- a/blog/more-stories.tsx +++ b/blog/more-stories.tsx @@ -3,9 +3,10 @@ import { PostPreview } from "./post-preview"; type Props = { posts: Post[]; + lang: string; }; -export function MoreStories({ posts }: Props) { +export function MoreStories({ posts, lang }: Props) { return (

@@ -15,12 +16,12 @@ export function MoreStories({ posts }: Props) { {posts.map((post) => ( ))} diff --git a/cursor.jsx b/cursor.jsx index 29a7b3d..0f5abe8 100644 --- a/cursor.jsx +++ b/cursor.jsx @@ -36,18 +36,56 @@ export function CursorProvider ({ hidden, enabled, children }) { } }; + const handlePointer = (event) => { + switch (event.pointerType) { + case "mouse": + setIsCursorEnabled(true); + break; + case "pen": + setIsCursorEnabled(false); + break; + case "touch": + setIsCursorEnabled(false); + break; + default: + setIsCursorEnabled(false); + console.log(`pointerType ${event.pointerType} is not supported`); + } + }; + + window.addEventListener( + "pointerdown", + handlePointer, + false, + ); + + const handleMouseEnter = () => { + setIsCursorInViewport(true); + }; + + const handleMouseLeave = () => { + setIsCursorInViewport(false); + }; + + // Aggiungi gli eventi di mouse + window.addEventListener('mouseenter', handleMouseEnter); + window.addEventListener('mouseleave', handleMouseLeave); + window.addEventListener('mousemove', moveCursor); return () => { + window.removeEventListener('mouseenter', handleMouseEnter); + window.removeEventListener('mouseleave', handleMouseLeave); + window.removeEventListener('mousemove', moveCursor); + + window.removeEventListener('pointerdown', handlePointer, false) }; }, []); - const isTouchDevice = "ontouchstart" in window; - useEffect(() => { const htmlElement = document.documentElement; - if (isCursorEnabled & !isTouchDevice) { + if (isCursorEnabled) { htmlElement.classList.add('custom-cursor-enabled-env'); } else { htmlElement.classList.remove('custom-cursor-enabled-env'); @@ -57,7 +95,7 @@ export function CursorProvider ({ hidden, enabled, children }) { return ( <> - {isCursorEnabled & !isTouchDevice ? + {isCursorEnabled ?