diff --git a/src/components/Card.tsx b/src/components/Card.tsx
index 384cd40..d03e89f 100644
--- a/src/components/Card.tsx
+++ b/src/components/Card.tsx
@@ -14,7 +14,7 @@ const Card = ({ directory }: CardProps) => {
return (
@@ -27,7 +27,7 @@ const Card = ({ directory }: CardProps) => {
className="absolute -top-4 left-8 self-end rounded-2xl"
/>
-
+
{directory.name}{" "}
{directory.verified ? (
@@ -55,12 +55,12 @@ export function SkeletonCard() {
return (
-
-
-
+
+
+
-
-
- {" "}
-
+
+
+ {" "}
+
);
diff --git a/src/components/DarkModeSwitch.tsx b/src/components/DarkModeSwitch.tsx
new file mode 100644
index 0000000..41f1dc6
--- /dev/null
+++ b/src/components/DarkModeSwitch.tsx
@@ -0,0 +1,57 @@
+import { useEffect, useState } from "react";
+import { TbSun, TbMoon } from "react-icons/tb";
+
+const iconDiv =
+ "absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 transform cursor-pointer transition-opacity duration-200";
+
+function DarkModeSwitch() {
+ //Set light theme by default
+ const [theme, setTheme] = useState("theme");
+
+ useEffect(() => {
+ //Set theme on device
+ if (typeof window !== "undefined") {
+ const _theme =
+ localStorage.theme === "dark" ||
+ (!("theme" in localStorage) &&
+ window.matchMedia("(prefers-color-scheme: dark)").matches)
+ ? "dark"
+ : "light";
+ changeTheme(_theme);
+ }
+ }, [theme]);
+
+ function changeTheme(_theme: string) {
+ //Set theme on the html tag.
+ if (_theme === "dark") {
+ document.documentElement.classList.add("dark");
+ } else {
+ document.documentElement.classList.remove("dark");
+ }
+ setTheme(_theme);
+ localStorage.setItem("theme", _theme);
+ }
+
+ return (
+
+
changeTheme("light")}
+ >
+
+
+
changeTheme("dark")}
+ >
+
+
+
+ );
+}
+
+export default DarkModeSwitch;
diff --git a/src/pages/index.tsx b/src/pages/index.tsx
index eb05862..ed81633 100755
--- a/src/pages/index.tsx
+++ b/src/pages/index.tsx
@@ -1,6 +1,7 @@
import type { NextPage } from "next";
import { useState } from "react";
import Card, { SkeletonCard } from "@/components/Card";
+import DarkModeSwitch from "@/components/DarkModeSwitch";
import Seo from "@/components/Seo";
import { Directory } from "@/interface";
import { useGetDirectories } from "@/queries";
@@ -21,21 +22,24 @@ const Home: NextPage = () => {
}
return (
-
+
@@ -77,8 +81,8 @@ const Home: NextPage = () => {
rel="noopener noreferrer"
>
Web3 Philippines
-
- {" "}&{" "}
+ {" "}
+ &{" "}