2020-10-10 23:32:27 +00:00
|
|
|
import {html} from 'htm/preact';
|
|
|
|
import {useContext, useState} from 'preact/hooks';
|
2022-02-23 13:52:06 +00:00
|
|
|
|
|
|
|
import {AppContext} from '../context.js';
|
|
|
|
import {Setting, SettingProps} from './index.js';
|
2020-10-10 23:32:27 +00:00
|
|
|
|
|
|
|
export function HideVotesSetting(props: SettingProps): TRXComponent {
|
|
|
|
const {settings} = useContext(AppContext);
|
|
|
|
|
|
|
|
const [checked, setChecked] = useState(settings.data.hideVotes);
|
|
|
|
function toggle(target: string) {
|
|
|
|
checked[target] = !checked[target];
|
|
|
|
setChecked(checked);
|
|
|
|
|
|
|
|
settings.data.hideVotes = checked;
|
2022-02-23 13:52:06 +00:00
|
|
|
void settings.save();
|
2020-10-10 23:32:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Checkbox labels and "targets". The targets should match the keys as defined
|
|
|
|
// in the user extension settings.
|
|
|
|
const checkboxes = [
|
|
|
|
{label: 'Your comments', target: 'ownComments'},
|
|
|
|
{label: 'Your topics', target: 'ownTopics'},
|
|
|
|
{label: "Other's comments", target: 'comments'},
|
2022-02-23 13:52:06 +00:00
|
|
|
{label: "Other's topics", target: 'topics'},
|
2020-10-10 23:32:27 +00:00
|
|
|
].map(
|
|
|
|
({label, target}) =>
|
|
|
|
html`
|
|
|
|
<li>
|
|
|
|
<label>
|
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
checked=${checked[target]}
|
2020-12-16 16:46:20 +00:00
|
|
|
onClick=${() => {
|
|
|
|
toggle(target);
|
|
|
|
}}
|
2020-10-10 23:32:27 +00:00
|
|
|
/>
|
|
|
|
${label}
|
|
|
|
</label>
|
|
|
|
</li>
|
2022-02-23 13:52:06 +00:00
|
|
|
`,
|
2020-10-10 23:32:27 +00:00
|
|
|
);
|
|
|
|
|
2022-02-23 13:52:06 +00:00
|
|
|
return html`
|
|
|
|
<${Setting} ...${props}>
|
|
|
|
<p class="info">
|
|
|
|
Hides vote counts from topics and comments of yourself or other people.
|
|
|
|
</p>
|
2020-10-10 23:32:27 +00:00
|
|
|
|
2022-02-23 13:52:06 +00:00
|
|
|
<ul class="checkbox-list">
|
|
|
|
${checkboxes}
|
|
|
|
</ul>
|
|
|
|
<//>
|
|
|
|
`;
|
2020-10-10 23:32:27 +00:00
|
|
|
}
|