refactor(login): remove duplicate theme code from template
- Remove inline theme functions (lines 62-88) - applyTheme, loadTheme, changeTheme functions - Add script tag for /static/theme.js - Theme logic now uses shared theme.ts module - Eliminates code duplication with web/src/theme.ts - Part of TypeScript conversion plan Phase 6.1.1
This commit is contained in:
+1
-29
@@ -9,6 +9,7 @@ templ Login(sessionExpired bool) {
|
|||||||
<title>Login</title>
|
<title>Login</title>
|
||||||
<script src="/static/htmx.min.js"></script>
|
<script src="/static/htmx.min.js"></script>
|
||||||
<script src="/static/toast.js"></script>
|
<script src="/static/toast.js"></script>
|
||||||
|
<script src="/static/theme.js"></script>
|
||||||
<link href="/static/style.css" rel="stylesheet">
|
<link href="/static/style.css" rel="stylesheet">
|
||||||
</head>
|
</head>
|
||||||
<body class="theme-tokyo-night min-h-screen">
|
<body class="theme-tokyo-night min-h-screen">
|
||||||
@@ -58,35 +59,6 @@ templ Login(sessionExpired bool) {
|
|||||||
<a href="/register" class="text-blue-500 hover:underline">Don't have an account? Sign Up</a>
|
<a href="/register" class="text-blue-500 hover:underline">Don't have an account? Sign Up</a>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
|
||||||
function applyTheme(theme) {
|
|
||||||
document.body.className = `theme-${theme} min-h-screen`;
|
|
||||||
localStorage.setItem('theme', theme);
|
|
||||||
}
|
|
||||||
function loadTheme() {
|
|
||||||
const theme = localStorage.getItem('theme') || 'tokyo-night';
|
|
||||||
applyTheme(theme);
|
|
||||||
}
|
|
||||||
function changeTheme() {
|
|
||||||
const theme = document.getElementById('theme-select').value;
|
|
||||||
applyTheme(theme);
|
|
||||||
const token = localStorage.getItem('token');
|
|
||||||
if (token) {
|
|
||||||
fetch('/api/auth/theme', {
|
|
||||||
method: 'PUT',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'Authorization': 'Bearer ' + token
|
|
||||||
},
|
|
||||||
body: JSON.stringify({ theme })
|
|
||||||
}).catch(err => console.log('Theme save failed', err));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
|
||||||
loadTheme();
|
|
||||||
document.getElementById('theme-select').value = localStorage.getItem('theme') || 'tokyo-night';
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user