Skip to content

Commit

Permalink
darkmode
Browse files Browse the repository at this point in the history
  • Loading branch information
Stan370 committed Aug 27, 2024
1 parent 17da9f8 commit fbf074f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
9 changes: 0 additions & 9 deletions app/api/chat/google/route.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
import { getServerConfig } from "@/config/server";
import { GoogleGenerativeAI, HarmCategory, HarmBlockThreshold } from "@google/generative-ai";

// Ensure the environment variable is correctly set and decoded
const googleServiceKey = process.env.GOOGLE_SERVICE_KEY;
if (!googleServiceKey) {
throw new Error("Missing GOOGLE_SERVICE_KEY environment variable.");
}

const credentials = JSON.parse(
Buffer.from(googleServiceKey, "base64").toString()
);

export async function POST(req: Request) {
try {
Expand Down
12 changes: 10 additions & 2 deletions app/components/DarkSwitch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ import React, { useState, useEffect } from "react";
// DarkSwitch component
const DarkSwitch = () => {
// State to track dark mode
const [darkMode, setDarkMode] = useState(false);

const [darkMode, setDarkMode] = useState(() => {
if (typeof window !== "undefined" ) {
return localStorage.getItem("theme") === "dark";
}
return false;
});

// Function to toggle dark mode
const toggleDarkMode = () => {
setDarkMode(!darkMode);
Expand All @@ -15,6 +20,9 @@ const DarkSwitch = () => {
// Use effect to update the class on body based on dark mode state
useEffect(() => {
document.body.classList.toggle("dark", darkMode);
if (typeof window !== "undefined") {
localStorage.setItem("theme", darkMode ? "dark" : "light");
}
}, [darkMode]);

return (
Expand Down
2 changes: 1 addition & 1 deletion tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
'./components/**/*.{js,ts,jsx,tsx,mdx}',
'./app/**/*.{js,ts,jsx,tsx,mdx}',
],
darkMode: ["class"],
darkMode: ['selector'],
theme: {
extend: {},
},
Expand Down

0 comments on commit fbf074f

Please sign in to comment.