mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-16 01:21:20 -04:00
overseer voting stuff yay!
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
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 (
|
||||
<section className="surface p-1 text-xs text-slate-200">
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<label className="inline-flex items-center gap-1.5">
|
||||
<input type="checkbox" checked={enabled} onChange={onToggle} />
|
||||
<span>Overseer vote</span>
|
||||
</label>
|
||||
<span className={running ? 'text-emerald-300' : 'text-slate-400'}>
|
||||
running: {running ? 'yes' : 'no'}
|
||||
</span>
|
||||
</div>
|
||||
<div className="mt-1 text-[0.65rem] text-slate-400">
|
||||
yes {Number(vote?.yesCount || 0)} / no {Number(vote?.noCount || 0)} / online {Number(vote?.onlineCount || 0)}
|
||||
</div>
|
||||
<div className="mt-0.5 text-[0.65rem] text-slate-500">
|
||||
your vote: {(sessionIdentity?.overseerEnabled ?? enabled) ? 'yes' : 'no'}
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import VipPanel from '../VipPanel/index.jsx';
|
||||
import { useSessionSelector } from '../../context/SessionContext.jsx';
|
||||
import { useSettingsNamespace } from '../../settings/index.js';
|
||||
import ButtonBoxPanel from '../ButtonBoxPanel/index.jsx';
|
||||
import OverseerPreferencePanel from '../OverseerPreferencePanel/index.jsx';
|
||||
import { useState } from 'react';
|
||||
import { useManualDockAssist } from '../../features/manualDockAssist/useManualDockAssist.js';
|
||||
|
||||
@@ -177,7 +178,8 @@ export default function RightPaneTabs({ layout, onOpenHelpOverlay }) {
|
||||
</div>
|
||||
<div className="grid items-stretch gap-0.5 grid-cols-[minmax(0,1.3fr)_minmax(0,0.22fr)] h-[14rem]">
|
||||
<ChatPanel fillHeight />
|
||||
<div className="grid min-h-0 gap-0.5 grid-rows-[minmax(0,1fr)_auto]">
|
||||
<div className="grid min-h-0 gap-0.5 grid-rows-[auto_minmax(0,1fr)_auto]">
|
||||
<OverseerPreferencePanel />
|
||||
<RawUserPilePanel compact hideNicknameForm fillHeight />
|
||||
<NicknameEntryPanel compact />
|
||||
</div>
|
||||
|
||||
@@ -155,8 +155,8 @@ export function SessionProvider({ children }) {
|
||||
const actions = useMemo(
|
||||
() => ({
|
||||
login: (username, password) => emitWithAck('auth:login', { username, password }),
|
||||
identifySession: ({ cookieUserId, nickname } = {}) =>
|
||||
emitWithAck('session:identify', { cookieUserId, nickname }),
|
||||
identifySession: ({ cookieUserId, nickname, overseerEnabled } = {}) =>
|
||||
emitWithAck('session:identify', { cookieUserId, nickname, overseerEnabled }),
|
||||
setRole: (role) => emitWithAck('session:setRole', { role }),
|
||||
requestControl: (roverId, options = {}) =>
|
||||
emitWithAck('session:requestControl', { roverId, ...options }),
|
||||
|
||||
@@ -13,14 +13,20 @@ export default function useUserIdentitySync() {
|
||||
cookieUserId: '',
|
||||
});
|
||||
const { value: profile, status: profileStatus } = useSettingsNamespace('profile', { nickname: '' });
|
||||
const { value: overseerPreference, status: overseerPreferenceStatus } = useSettingsNamespace(
|
||||
'overseerPreference',
|
||||
{ enabled: true },
|
||||
);
|
||||
|
||||
const inFlightRef = useRef(false);
|
||||
const lastAckSocketRef = useRef(null);
|
||||
const retryTimerRef = useRef(null);
|
||||
|
||||
const ready = identityStatus === 'ready' && profileStatus === 'ready';
|
||||
const ready =
|
||||
identityStatus === 'ready' && profileStatus === 'ready' && overseerPreferenceStatus === 'ready';
|
||||
const cookieUserId = (identity?.cookieUserId || '').trim();
|
||||
const nickname = (profile?.nickname || '').trim();
|
||||
const overseerEnabled = Boolean(overseerPreference?.enabled);
|
||||
|
||||
const clearRetry = useCallback(() => {
|
||||
if (retryTimerRef.current) {
|
||||
@@ -33,7 +39,7 @@ export default function useUserIdentitySync() {
|
||||
if (!ready || !connected || !socket?.id || inFlightRef.current) return;
|
||||
inFlightRef.current = true;
|
||||
try {
|
||||
const resp = await identifySession({ cookieUserId, nickname });
|
||||
const resp = await identifySession({ cookieUserId, nickname, overseerEnabled });
|
||||
const nextKey = (resp?.cookieUserId || '').trim();
|
||||
if (nextKey && nextKey !== cookieUserId) {
|
||||
saveIdentity((current) => ({ ...(current || {}), cookieUserId: nextKey }));
|
||||
@@ -48,7 +54,17 @@ export default function useUserIdentitySync() {
|
||||
} finally {
|
||||
inFlightRef.current = false;
|
||||
}
|
||||
}, [clearRetry, connected, cookieUserId, identifySession, nickname, ready, saveIdentity, socket?.id]);
|
||||
}, [
|
||||
clearRetry,
|
||||
connected,
|
||||
cookieUserId,
|
||||
identifySession,
|
||||
nickname,
|
||||
overseerEnabled,
|
||||
ready,
|
||||
saveIdentity,
|
||||
socket?.id,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!ready || !connected || !socket?.id) return;
|
||||
@@ -59,7 +75,7 @@ export default function useUserIdentitySync() {
|
||||
useEffect(() => {
|
||||
if (!ready || !connected || !socket?.id) return;
|
||||
sendIdentify();
|
||||
}, [ready, connected, socket?.id, cookieUserId, nickname, sendIdentify]);
|
||||
}, [ready, connected, socket?.id, cookieUserId, nickname, overseerEnabled, sendIdentify]);
|
||||
|
||||
useEffect(() => {
|
||||
const handleOnline = () => {
|
||||
|
||||
Reference in New Issue
Block a user