import { useSessionActions, useSessionSelector } from '../../context/SessionContext.jsx'; import { useSettingsNamespace } from '../../settings/index.js'; export default function OverseerPreferencePanel() { const { identifySession } = useSessionActions(); const sessionIdentity = useSessionSelector((state) => state.session?.identity || null); const vote = useSessionSelector((state) => state.session?.overseerVote || null); const { value: profile } = useSettingsNamespace('profile', { nickname: '' }); const { value: identity } = useSettingsNamespace('identity', { cookieUserId: '' }); const { value, save } = useSettingsNamespace('overseerPreference', { enabled: true }); const enabled = Boolean(value?.enabled); const running = Boolean(vote?.running); const onToggle = async (event) => { const next = Boolean(event?.target?.checked); await save((current) => ({ ...(current || {}), enabled: next })); await identifySession({ cookieUserId: String(identity?.cookieUserId || '').trim(), nickname: String(profile?.nickname || '').trim(), overseerEnabled: next, }); }; return (
running: {running ? 'yes' : 'no'}
yes {Number(vote?.yesCount || 0)} / no {Number(vote?.noCount || 0)} / online {Number(vote?.onlineCount || 0)}
your vote: {(sessionIdentity?.overseerEnabled ?? enabled) ? 'yes' : 'no'}
); }