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:
2026-02-18 16:42:13 -05:00
parent 9d2bed92f2
commit ba3d9e4f37
+1 -29
View File
@@ -9,6 +9,7 @@ templ Login(sessionExpired bool) {
<title>Login</title>
<script src="/static/htmx.min.js"></script>
<script src="/static/toast.js"></script>
<script src="/static/theme.js"></script>
<link href="/static/style.css" rel="stylesheet">
</head>
<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>
</p>
</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>
</html>
}