Add a debug setting.
This commit is contained in:
parent
1a53885993
commit
9f0f5a46b7
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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>
|
||||||
`;
|
`;
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue