Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make light/dark mode theme persist on refresh #1065

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion public/data/Sahilll15.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Sahil Sanjay Chalke",
"location": "Mumbai, India 🇮🇳",
"location": "Mumbai, India 🇮🇳",
"bio": "FULL STACK DEV",
"avatar": "https://avatars.githubusercontent.com/u/109215419?v=4",
"portfolio": "https://sahilchalke.online/",
Expand Down
18 changes: 16 additions & 2 deletions public/data/connectaryal.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,24 @@
"bio": "Senior Software Engineer with 5+ years of experience in building scalable applications.",
"avatar": "https://github.com/connectaryal.png",
"portfolio": "https://shivaaryal.com.np/",
"skills": ["HTML", "CSS", "JavaScript", "Tailwind CSS", "TypeScript", "React", "OOP", "Node.js", "PHP", "Laravel", "WordPress", "MYSQL", "Docker"],
"skills": [
"HTML",
"CSS",
"JavaScript",
"Tailwind CSS",
"TypeScript",
"React",
"OOP",
"Node.js",
"PHP",
"Laravel",
"WordPress",
"MYSQL",
"Docker"
],
"social": {
"GitHub": "https://github.com/connectaryal",
"Twitter": "https://twitter.com/connectaryal",
"LinkedIn": "https://www.linkedin.com/in/connectaryal"
}
}
}
2 changes: 1 addition & 1 deletion src/ProfilesList.json
Original file line number Diff line number Diff line change
Expand Up @@ -426,4 +426,4 @@
"Monalisha-Roy.json",
"Sahilll15.json",
"Kritika.json"
]
]
19 changes: 6 additions & 13 deletions src/components/Sidebar/Sidebar.jsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
import React, { useState } from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faCode, faMoon, faSun } from '@fortawesome/free-solid-svg-icons';
import useTheme from '../../hooks/useTheme';

function Sidebar() {
const [theme, setTheme] = useState('dark');
const [theme] = useState('dark');
const { toggle } = useTheme();

function toggleTheme() {
const htmlElement = document.documentElement;
const isDarkModeEnabled = htmlElement.classList.contains('dark');

if (isDarkModeEnabled) {
htmlElement.classList.remove('dark');
setTheme('light');
} else {
htmlElement.classList.add('dark');
setTheme('dark');
}
}
const toggleTheme = () => {
toggle();
};
return (
<div className="my-7 w-full border-r-2 border-borderSecondary px-7 font-spaceMono dark:border-borderColor md:h-[90vh] md:w-[23%]">
<div className="mb-2 flex h-12 items-center gap-2.5">
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useTheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useState, useEffect } from 'react';
const useTheme = () => {
const [theme, setTheme] = useState(localStorage.getItem('theme') || 'dark');

const toogleTheme = () => {
const toggle = () => {
const newTheme = theme === 'light' ? 'dark' : 'light';
setTheme(newTheme);
localStorage.setItem('theme', newTheme);
Expand All @@ -13,7 +13,7 @@ const useTheme = () => {
document.documentElement.className = theme;
}, [theme]);

return { theme, toogleTheme };
return { theme, toggle };
};

export default useTheme;