Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ const App = () => {
display: "flex",
justifyContent: "center",
alignItems: "center",
background: backgroundColor,
minHeight: "calc(100vh - 64px - 70px)", // Adjust for Navbar and Footer height
}}
>
Expand Down
5 changes: 3 additions & 2 deletions src/components/ToggleDarkMode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ const ToggleDarkMode: React.FC = () => {
const [isDarkMode, setIsDarkMode] = useState(backgroundColor === "#121212");

useEffect(() => {
setIsDarkMode(backgroundColor === "#121212");
}, [backgroundColor]);
const savedTheme = localStorage.getItem('theme');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we just get this before initialising the state variable above? We can get rid of this useState?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved @sanketshevkar

setIsDarkMode(savedTheme === 'dark');
}, []);

const handleChange = () => {
toggleDarkMode();
Expand Down
24 changes: 22 additions & 2 deletions src/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@ const useAppStore = create<AppState>()(
init: async () => {
const params = new URLSearchParams(window.location.search);
const compressedData = params.get("data");
const savedTheme = localStorage.getItem('theme');
if (savedTheme === 'dark') {
set(() => ({
backgroundColor: '#121212',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please move all these string values to a constants file? We can reuse as variables across the app.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved @sanketshevkar

textColor: '#ffffff',
}));
document.documentElement.setAttribute("data-theme", "dark");
}
else {
set(() => ({
backgroundColor: '#ffffff',
textColor: '#121212',
}));
document.documentElement.setAttribute("data-theme", "light");
}
if (compressedData) {
await get().loadFromLink(compressedData);
} else {
Expand Down Expand Up @@ -197,9 +212,14 @@ const useAppStore = create<AppState>()(
toggleDarkMode: () => {
set((state) => {
const isDark = state.backgroundColor === '#121212';
const newBackgroundColor = isDark ? '#ffffff' : '#121212';
const newTextColor = isDark ? '#121212' : '#ffffff';

localStorage.setItem('theme', isDark ? 'light' : 'dark');

return {
backgroundColor: isDark ? '#ffffff' : '#121212',
textColor: isDark ? '#121212' : '#ffffff',
backgroundColor: newBackgroundColor,
textColor: newTextColor,
};
});
},
Expand Down