1
Fork 0

Add a debug setting.

This commit is contained in:
Bauke 2022-02-08 12:19:07 +01:00
parent 1a53885993
commit 9f0f5a46b7
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
3 changed files with 42 additions and 0 deletions

View File

@ -12,5 +12,11 @@
select { select {
margin-bottom: 1rem; margin-bottom: 1rem;
} }
input[type='checkbox'] {
height: 1.75rem;
width: 1.75rem;
margin-right: 0.5rem;
}
} }
} }

View File

@ -2,6 +2,7 @@ import {Component, html} from 'htm/preact';
import ExternalAnchor from '../components/external-anchor.js'; import ExternalAnchor from '../components/external-anchor.js';
import SharedFooter from '../components/shared-footer.js'; import SharedFooter from '../components/shared-footer.js';
import {isDebugEnabled} from '../utilities/debug.js';
import { import {
defaultTheme, defaultTheme,
getThemeByCssClass, getThemeByCssClass,
@ -12,6 +13,7 @@ import {
type Props = Record<string, unknown>; type Props = Record<string, unknown>;
type State = { type State = {
debugChecked: boolean;
selectedTheme: string; selectedTheme: string;
}; };
@ -20,11 +22,17 @@ export default class SettingsPage extends Component<Props, State> {
super(props); super(props);
this.state = { this.state = {
debugChecked: isDebugEnabled(),
selectedTheme: selectedTheme:
window.localStorage.getItem('theme') ?? defaultTheme.cssClass, window.localStorage.getItem('theme') ?? defaultTheme.cssClass,
}; };
} }
onDebugChange = (event: Event) => {
const checked = (event.target as HTMLInputElement).checked;
window.localStorage.setItem('debug', checked.toString());
};
onThemeChange = (event: Event) => { onThemeChange = (event: Event) => {
const theme = getThemeByCssClass((event.target as HTMLSelectElement).value); const theme = getThemeByCssClass((event.target as HTMLSelectElement).value);
setTheme(theme); setTheme(theme);
@ -65,6 +73,21 @@ export default class SettingsPage extends Component<Props, State> {
</p> </p>
</section> </section>
<section class="setting">
<h2>Debug</h2>
<input
checked=${this.state.debugChecked}
id="debug-checkbox"
name="debug-checkbox"
onChange=${this.onDebugChange}
type="checkbox"
/>
<label for="debug-checkbox">
Log debug information to the console.
</label>
</section>
<${SharedFooter} page="settings" /> <${SharedFooter} page="settings" />
</div> </div>
`; `;

View File

@ -0,0 +1,13 @@
export function isDebugEnabled(): boolean {
return window.localStorage.getItem('debug') === 'true';
}
export function debug(...args: any[]): void {
if (!isDebugEnabled()) {
return;
}
for (const argument of args) {
console.debug(argument);
}
}