Skip to content

Commit

Permalink
fix(app): move code for setting default theme
Browse files Browse the repository at this point in the history
  • Loading branch information
rhahao committed Dec 1, 2024
1 parent dd747e4 commit 7916b6d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
15 changes: 0 additions & 15 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -439,21 +439,6 @@
}
</style>
</noscript>

<script>
const theme = localStorage.getItem('theme') || 'light';
const color = localStorage.getItem('color') || 'blue';
const newTheme = `${color}-${theme}`;

document.documentElement.setAttribute('data-theme', newTheme);

const themeColor = getComputedStyle(
document.documentElement
).getPropertyValue('--accent-100');
document
.querySelector("meta[name='theme-color']")
.setAttribute('content', themeColor);
</script>
</head>
<body>
<noscript>
Expand Down
13 changes: 13 additions & 0 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@ import React from 'react';
import { createRoot } from 'react-dom/client';
import AppRoot from './RootWrap';

const theme = localStorage.getItem('theme') || 'light';
const color = localStorage.getItem('color') || 'blue';
const newTheme = `${color}-${theme}`;

document.documentElement.setAttribute('data-theme', newTheme);

const themeColor = getComputedStyle(document.documentElement).getPropertyValue(
'--accent-100'
);
document
.querySelector("meta[name='theme-color']")
.setAttribute('content', themeColor);

console.info(`Organized: version ${import.meta.env.PACKAGE_VERSION}`);

createRoot(document.getElementById('root')).render(
Expand Down

0 comments on commit 7916b6d

Please sign in to comment.