refactor: clean up commented-out code and improve theme handling
This commit is contained in:
@@ -4,7 +4,6 @@ import { useUsers } from "./utils/useUsers";
|
|||||||
import UserTable from "./components/UserTable";
|
import UserTable from "./components/UserTable";
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { loadTheme } from "./utils/functions";
|
import { loadTheme } from "./utils/functions";
|
||||||
import { replaceUsers } from "./utils/functions";
|
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const users = useUsers();
|
const users = useUsers();
|
||||||
|
@@ -23,7 +23,10 @@ const Header: React.FC = () => {
|
|||||||
<ul className="flex space-x-4">
|
<ul className="flex space-x-4">
|
||||||
<li>
|
<li>
|
||||||
<a className="hover:underline">
|
<a className="hover:underline">
|
||||||
<button onClick={() => changeTheme()} className="bg-blue-700 shadow-md hover:bg-blue-800 transition padding px-4 py-2 rounded-md text-white font-semibold">
|
<button
|
||||||
|
onClick={() => changeTheme()}
|
||||||
|
className="bg-blue-700 shadow-md hover:bg-blue-800 transition padding px-4 py-2 rounded-md text-white font-semibold"
|
||||||
|
>
|
||||||
Change Theme
|
Change Theme
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
|
@@ -3,8 +3,6 @@ import React from "react";
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { deleteUser, updateUserFunc } from "../utils/functions.ts";
|
import { deleteUser, updateUserFunc } from "../utils/functions.ts";
|
||||||
|
|
||||||
const selectedUsers: Record<number, boolean> = {};
|
|
||||||
|
|
||||||
interface User {
|
interface User {
|
||||||
id: number;
|
id: number;
|
||||||
username: string;
|
username: string;
|
||||||
@@ -74,7 +72,7 @@ const UserTable: React.FC<UserTableProps> = ({ users }) => {
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody className="bg-white divide-y divide-gray-100">
|
<tbody className="bg-white divide-y divide-gray-100">
|
||||||
{userList.map((user, idx) => (
|
{userList.map((user) => (
|
||||||
<tr key={user.id} className="hover:bg-blue-50 transition">
|
<tr key={user.id} className="hover:bg-blue-50 transition">
|
||||||
<td className="px-4 py-2 whitespace-nowrap">{user.id}</td>
|
<td className="px-4 py-2 whitespace-nowrap">{user.id}</td>
|
||||||
<td className="px-4 py-2 whitespace-nowrap">
|
<td className="px-4 py-2 whitespace-nowrap">
|
||||||
|
@@ -1,7 +1,5 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import Header from "../components/Header";
|
import Header from "../components/Header";
|
||||||
import userIcon from "../assets/circle-user-solid-full.svg";
|
|
||||||
import logoIcon from "../assets/bicycle-solid-full.svg";
|
|
||||||
import Cookies from "js-cookie"; // Add this import
|
import Cookies from "js-cookie"; // Add this import
|
||||||
import Sidebar from "../components/Sidebar";
|
import Sidebar from "../components/Sidebar";
|
||||||
|
|
||||||
|
@@ -10,13 +10,13 @@ export const loadTheme = () => {
|
|||||||
window.matchMedia("(prefers-color-scheme: dark)").matches
|
window.matchMedia("(prefers-color-scheme: dark)").matches
|
||||||
) {
|
) {
|
||||||
// Switch to dark theme
|
// Switch to dark theme
|
||||||
console.log("dark")
|
console.log("dark");
|
||||||
document.documentElement.classList.add("dark");
|
document.documentElement.classList.add("dark");
|
||||||
document.body.classList.add("dark");
|
document.body.classList.add("dark");
|
||||||
Cookies.set("theme", "dark", { expires: 365 });
|
Cookies.set("theme", "dark", { expires: 365 });
|
||||||
} else {
|
} else {
|
||||||
// Switch to light theme
|
// Switch to light theme
|
||||||
console.log("light")
|
console.log("light");
|
||||||
document.documentElement.classList.remove("dark");
|
document.documentElement.classList.remove("dark");
|
||||||
document.body.classList.remove("dark");
|
document.body.classList.remove("dark");
|
||||||
Cookies.set("theme", "light", { expires: 365 });
|
Cookies.set("theme", "light", { expires: 365 });
|
||||||
@@ -26,13 +26,13 @@ export const loadTheme = () => {
|
|||||||
export const changeTheme = () => {
|
export const changeTheme = () => {
|
||||||
if (Cookies.get("theme") === "dark") {
|
if (Cookies.get("theme") === "dark") {
|
||||||
// Switch to light theme
|
// Switch to light theme
|
||||||
console.log("light")
|
console.log("light");
|
||||||
document.documentElement.classList.remove("dark");
|
document.documentElement.classList.remove("dark");
|
||||||
document.body.classList.remove("dark");
|
document.body.classList.remove("dark");
|
||||||
Cookies.set("theme", "light", { expires: 365 });
|
Cookies.set("theme", "light", { expires: 365 });
|
||||||
} else if (Cookies.get("theme") === "light") {
|
} else if (Cookies.get("theme") === "light") {
|
||||||
// Switch to dark theme
|
// Switch to dark theme
|
||||||
console.log("dark")
|
console.log("dark");
|
||||||
document.documentElement.classList.add("dark");
|
document.documentElement.classList.add("dark");
|
||||||
document.body.classList.add("dark");
|
document.body.classList.add("dark");
|
||||||
Cookies.set("theme", "dark", { expires: 365 });
|
Cookies.set("theme", "dark", { expires: 365 });
|
||||||
|
Reference in New Issue
Block a user