Skip to content

Commit 53ede31

Browse files
fix: login screen theme switcher
Signed-off-by: Henry <mail@henrygressmann.de>
1 parent 983c889 commit 53ede31

4 files changed

Lines changed: 15 additions & 12 deletions

File tree

web/src/components/ThemeSwitcher.astro

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
---
22
import { MoonIcon, SunIcon } from "lucide-react";
3+
const { class: className, ...rest } = Astro.props;
34
---
45

5-
<button id="theme-switcher" type="button" aria-label="Toggle dark mode">
6+
<button id="theme-switcher" type="button" aria-label="Toggle dark mode" class={className} {...rest}>
67
<SunIcon className="sun" />
78
<MoonIcon className="moon" />
89
</button>
@@ -58,6 +59,7 @@ import { MoonIcon, SunIcon } from "lucide-react";
5859
const button = document.querySelector(
5960
"#theme-switcher"
6061
) as HTMLButtonElement;
62+
6163
const sun = document.querySelector(
6264
"#theme-switcher .sun"
6365
) as HTMLElement | null;
@@ -75,6 +77,8 @@ import { MoonIcon, SunIcon } from "lucide-react";
7577
}
7678

7779
button.addEventListener("click", () => {
80+
console.log("click");
81+
7882
if (theme === "dark") {
7983
setTheme("light");
8084
sun.style.display = "block";

web/src/layouts/Base.astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import "../global.css";
55
import { ClientRouter } from "astro:transitions";
66
import ThemeSwitcher from "../components/ThemeSwitcher.astro";
77
8-
type Props = { title: string; hideFooter?: boolean };
8+
type Props = { title: string; hideFooter?: boolean; noSwitcher?: boolean };
99
---
1010

1111
<html lang="en" transition:animate="none">
@@ -23,7 +23,7 @@ type Props = { title: string; hideFooter?: boolean };
2323
{
2424
!Astro.props.hideFooter && (
2525
<footer class="container-fluid footer">
26-
<ThemeSwitcher />
26+
{!Astro.props.noSwitcher && <ThemeSwitcher />}
2727
<small>
2828
Powered by&nbsp;
2929
<a href="https://liwan.dev" target="_blank" class="secondary">

web/src/pages/login.astro

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import ThemeSwitcher from "../components/ThemeSwitcher.astro";
33
import Layout from "../layouts/Base.astro";
44
---
55

6-
<Layout title="Login">
6+
<Layout title="Login" noSwitcher>
77
<section class="container">
8-
<ThemeSwitcher class="asdf" />
8+
<ThemeSwitcher class="theme-switcher" />
99
<h1>Sign in</h1>
1010
<form onsubmit="return false;" id="login-form">
1111
<input
@@ -59,9 +59,8 @@ import Layout from "../layouts/Base.astro";
5959
api["/api/dashboard/auth/login"]
6060
.post({ json: { username, password } })
6161
.then((res) => {
62-
if (!res.ok)
62+
if (!(res as {ok: boolean})?.ok)
6363
return Promise.reject(new Error("Invalid username or password"));
64-
6564
document.location.href = "/";
6665
})
6766
.catch((_) => {
@@ -74,7 +73,7 @@ import Layout from "../layouts/Base.astro";
7473
</script>
7574

7675
<style>
77-
:global(#theme-switcher) {
76+
.theme-switcher {
7877
position: absolute;
7978
padding: 1rem;
8079
top: 0;

web/src/pages/setup.astro

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import ThemeSwitcher from "../components/ThemeSwitcher.astro";
33
import Layout from "../layouts/Base.astro";
44
---
55

6-
<Layout title="Setup" hideFooter>
6+
<Layout title="Setup" hideFooter noSwitcher>
77
<section class="container">
8-
<ThemeSwitcher class="asdf" />
8+
<ThemeSwitcher class="theme-switcher" />
99
<h1>Let's get started</h1>
1010
<p>
1111
Enter a new username and password to create your administrator account.
@@ -71,7 +71,7 @@ import Layout from "../layouts/Base.astro";
7171
api["/api/dashboard/auth/setup"]
7272
.post({ json: { username, password, token } })
7373
.then((res) => {
74-
if (!res.ok)
74+
if (!(res as {ok: boolean})?.ok)
7575
return Promise.reject(new Error("Invalid token or username"));
7676

7777
navigate("/login");
@@ -84,7 +84,7 @@ import Layout from "../layouts/Base.astro";
8484
</script>
8585

8686
<style>
87-
:global(#theme-switcher) {
87+
.theme-switcher {
8888
position: absolute;
8989
padding: 1rem;
9090
top: 0;

0 commit comments

Comments
 (0)