Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from "react";
import { useState, useEffect } from "react";
import { Routes, Route } from "react-router-dom";
import "./App.css";
import Alert from "./components/Alert";
Expand All @@ -7,8 +7,11 @@ import TextForm from "./components/TextForm";
import About from "./components/About";
import Footer from "./components/Footer";


const defaultMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? "dark" : "light";

function App() {
const [mode, setMode] = useState("light");
const [mode, setMode] = useState(defaultMode);
const [alert, setAlert] = useState(null);

// const removeBodyClasses = () => {
Expand All @@ -20,13 +23,20 @@ function App() {
// document.body.classList.remove("bg-primary");
// };

useEffect(() => {
if (mode === "dark") {
document.body.style.backgroundColor = "#042743";
} else {
document.body.style.backgroundColor = "white";
}
}, [mode]);

const toggleMode = () => {
// removeBodyClasses();
// console.log(cls);
// document.body.classList.add("bg-" + cls);
if (mode === "light") {
setMode("dark");
document.body.style.backgroundColor = "#042743";
showAlert("Dark mode has been enabled", "success");

// document.title = "TextUtils - Dark Mode";
Expand All @@ -38,7 +48,6 @@ function App() {
// }, 1500);
} else {
setMode("light");
document.body.style.backgroundColor = "white";
showAlert("Light mode has been enabled", "success");
// document.title = "TextUtils - Light Mode";
}
Expand Down
1 change: 1 addition & 0 deletions src/components/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export default function Navbar(props) {
onClick={() => {
props.toggleMode("light");
}}
checked={props.mode === "dark"}
role="switch"
id="flexSwitchCheckDefault"
/>
Expand Down