diff --git a/components/Lanyard.tsx b/components/Lanyard.tsx index eae08d1..fedcef0 100644 --- a/components/Lanyard.tsx +++ b/components/Lanyard.tsx @@ -3,41 +3,63 @@ import { useLanyard } from "use-lanyard"; import styles from "styles/Lanyard.module.sass"; import Image from "next/image"; import { useTheme } from 'next-themes' - +import useWindowSize from "utils/shared/hooks/useWindowSize"; +import Icon from "./Icon"; const Lanyard = () => { const id = process.env.NEXT_DISCORD_ID || "318044130796109825"; const lanyard = useLanyard(id).data; const { resolvedTheme: theme } = useTheme() + const windowSize = useWindowSize() if (!lanyard?.listening_to_spotify) return; + + + let artists; + if (lanyard.spotify.artist.split(";").length > 2) { artists = [ lanyard.spotify.artist.split(";")[0], lanyard.spotify.artist.split(";")[1], ].join(","); } else { - artists = lanyard.spotify.artist.split(";").join(","); + artists = lanyard.spotify.artist.split(";").join(" &"); + } - console.log("lanyard", theme) return ( <> -
- -
-

{lanyard.spotify.song}

-

{artists}

-
-
+ {(windowSize.width <= 550 || windowSize.height <= 800) ? + (<> +
+ +
+

+ + {lanyard.spotify.song} by {artists} +

+
+
+ ) + : + (<> +
+ +
+

{lanyard.spotify.song}

+

{artists}

+
+
+ + )} ); }; diff --git a/styles/Lanyard.module.sass b/styles/Lanyard.module.sass index 97c91d1..cd33495 100644 --- a/styles/Lanyard.module.sass +++ b/styles/Lanyard.module.sass @@ -1,6 +1,5 @@ @import "./_variables" - .container position: absolute bottom: 0 @@ -15,7 +14,6 @@ background: $background-light-lanyard color: $text-light-lanyard - .albumart border-radius: 20px padding: 10px !important @@ -28,20 +26,20 @@ font-size: .8rem .badge:after - content: '' - position: absolute - top: -5px - right: -5px - font-size: .7em - background: #8cff96b4 - color: white - width: 18px - height: 18px - text-align: center - line-height: 18px - border-radius: 50% + content: '' + position: absolute + top: -5px + right: -5px + font-size: .7em + background: #8cff96b4 + color: white + width: 18px + height: 18px + text-align: center + line-height: 18px + border-radius: 50% // box-shadow: 0 0 1px #333 - animation: pulse 4s linear infinite alternate + animation: pulse 4s linear infinite alternate @keyframes pulse 0% @@ -57,3 +55,27 @@ 100% background-color: #222 + +.np_mobile + position: absolute + top: 0 + left: 0 + width: 100% + text-align: center + background: $background-dark-lanyard + color: $text-dark-lanyard + &[data-theme="light"] + background: $background-light-lanyard + color: $text-light-lanyard + +.np_icon + align-content: center + translate: trans + transform-origin: center center + animation: load 5s infinite cubic-bezier(0.81,-0.73, 0.32, 1.28) + +@keyframes load + 0% + rotate: 0deg + 100% + rotate: 360deg diff --git a/utils/shared/hooks/useWindowSize.ts b/utils/shared/hooks/useWindowSize.ts new file mode 100644 index 0000000..eeadef0 --- /dev/null +++ b/utils/shared/hooks/useWindowSize.ts @@ -0,0 +1,15 @@ +import { useLayoutEffect, useState } from "react"; + +const useWindowSize = () => { + const [windowSize, setWindowSize] = useState({ width: 0, height: 0 }) + const handleSize = () => setWindowSize({ width: window.innerWidth, height: window.innerHeight }) + useLayoutEffect(() => { + handleSize() + window.addEventListener("resize", handleSize); + return () => window.removeEventListener("resize", handleSize); + }, []) + return windowSize +} + + +export default useWindowSize \ No newline at end of file