Bladeren bron

improve: optimize first loading speed

rriecc 2 jaren geleden
bovenliggende
commit
7e81ac167c
5 gewijzigde bestanden met toevoegingen van 86 en 1 verwijderingen
  1. 50 0
      components/animation-swith.tsx
  2. 9 1
      components/home.tsx
  3. 27 0
      components/mini-pic.tsx
  4. BIN
      public/mini-dark.jpg
  5. BIN
      public/mini-light.jpg

+ 50 - 0
components/animation-swith.tsx

@@ -0,0 +1,50 @@
+"use client";
+
+import { Button } from "@nextui-org/button";
+import { Dispatch, FC, SetStateAction } from "react";
+import { FaMagic } from "react-icons/fa";
+import { FaImage } from "react-icons/fa6";
+
+import { cn } from "@/lib/utils";
+
+export interface AnimationSwitchProps {
+  className?: string;
+  animated: boolean;
+  setAnimated: Dispatch<SetStateAction<boolean>>;
+}
+
+export const AnimationSwitch: FC<AnimationSwitchProps> = ({
+  className,
+  animated,
+  setAnimated,
+}) => {
+  const onChange = () => {
+    setAnimated((prev) => !prev);
+  };
+
+  return (
+    <div className={cn(className)}>
+      {!animated ? (
+        <Button
+          isIconOnly
+          className="dark:border-knight dark:bg-transparent dark:border-2 bg-midnight border-0"
+          radius="full"
+          variant="bordered"
+          onPress={onChange}
+        >
+          <FaMagic size={16} />
+        </Button>
+      ) : (
+        <Button
+          isIconOnly
+          className="dark:border-knight dark:bg-transparent dark:border-2 bg-midnight border-0"
+          radius="full"
+          variant="bordered"
+          onPress={onChange}
+        >
+          <FaImage size={16} />
+        </Button>
+      )}
+    </div>
+  );
+};

+ 9 - 1
components/home.tsx

@@ -6,6 +6,8 @@ import { useState } from "react";
 import { useRouter } from "next/navigation";
 
 import Paper from "./paper";
+import { AnimationSwitch } from "./animation-swith";
+import MiniPic from "./mini-pic";
 
 import { cn } from "@/lib/utils";
 import AvatarTransition from "@/components/avatar";
@@ -46,6 +48,7 @@ const Home = ({
 }: HomeProps) => {
   const width = useWindowWidth();
   const [tabSelected, setTabSelected] = useState("all");
+  const [animated, setAnimated] = useState(false);
   const router = useRouter();
 
   if (!width) {
@@ -195,7 +198,12 @@ const Home = ({
               : "opacity-50",
           )}
         >
-          <MiniModel />
+          {animated ? <MiniModel /> : <MiniPic />}
+          <AnimationSwitch
+            animated={animated}
+            className="absolute top-4 right-4 z-50"
+            setAnimated={setAnimated}
+          />
         </div>
         <div
           key="actions"

+ 27 - 0
components/mini-pic.tsx

@@ -0,0 +1,27 @@
+import { useTheme } from "next-themes";
+import { Image } from "@nextui-org/react";
+
+const MiniPic = () => {
+  const { theme } = useTheme();
+  const isDark = theme === "dark";
+
+  return (
+    <div>
+      {isDark ? (
+        <Image
+          alt="cover"
+          className="rounded-b-none object-cover"
+          src="mini-dark.jpg"
+        />
+      ) : (
+        <Image
+          alt="cover"
+          className="rounded-b-none object-cover"
+          src="mini-light.jpg"
+        />
+      )}
+    </div>
+  );
+};
+
+export default MiniPic;

BIN
public/mini-dark.jpg


BIN
public/mini-light.jpg