mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-16 17:40:46 -04:00
hopefully fixed discord dock / undock alerts?
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -5,8 +5,8 @@
|
|||||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>webui</title>
|
<title>webui</title>
|
||||||
<script type="module" crossorigin src="/assets/index-DAo0n__B.js"></script>
|
<script type="module" crossorigin src="/assets/index-Dsw_Z9n0.js"></script>
|
||||||
<link rel="stylesheet" crossorigin href="/assets/index-BjMfmH4X.css">
|
<link rel="stylesheet" crossorigin href="/assets/index-CCqAmxiE.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="root"></div>
|
<div id="root"></div>
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ function getState(roverId) {
|
|||||||
lastPercent: null,
|
lastPercent: null,
|
||||||
warned: false,
|
warned: false,
|
||||||
urgent: false,
|
urgent: false,
|
||||||
|
onDock: false,
|
||||||
dockedCharging: false,
|
dockedCharging: false,
|
||||||
charging: false,
|
charging: false,
|
||||||
batteryLocked: false,
|
batteryLocked: false,
|
||||||
@@ -64,6 +65,21 @@ function handleSensorEvent({ roverId, sensors, batteryState }) {
|
|||||||
const chargingState = sensors?.chargingState?.code;
|
const chargingState = sensors?.chargingState?.code;
|
||||||
const chargingSources = sensors?.chargingSources;
|
const chargingSources = sensors?.chargingSources;
|
||||||
const onDock = Boolean(chargingSources?.homeBase);
|
const onDock = Boolean(chargingSources?.homeBase);
|
||||||
|
if (onDock && !state.onDock) {
|
||||||
|
state.onDock = true;
|
||||||
|
publishEvent({
|
||||||
|
source: 'batteryManager',
|
||||||
|
type: 'battery.docked',
|
||||||
|
payload: { roverId, batteryState },
|
||||||
|
});
|
||||||
|
} else if (!onDock && state.onDock) {
|
||||||
|
state.onDock = false;
|
||||||
|
publishEvent({
|
||||||
|
source: 'batteryManager',
|
||||||
|
type: 'battery.undocked',
|
||||||
|
payload: { roverId, batteryState },
|
||||||
|
});
|
||||||
|
}
|
||||||
const isCharging = chargingState === 1 || chargingState === 2 || chargingState === 3;
|
const isCharging = chargingState === 1 || chargingState === 2 || chargingState === 3;
|
||||||
if (isCharging && !state.charging) {
|
if (isCharging && !state.charging) {
|
||||||
state.charging = true;
|
state.charging = true;
|
||||||
@@ -83,18 +99,8 @@ function handleSensorEvent({ roverId, sensors, batteryState }) {
|
|||||||
const dockedCharging = onDock && isCharging;
|
const dockedCharging = onDock && isCharging;
|
||||||
if (dockedCharging && !state.dockedCharging) {
|
if (dockedCharging && !state.dockedCharging) {
|
||||||
state.dockedCharging = true;
|
state.dockedCharging = true;
|
||||||
publishEvent({
|
|
||||||
source: 'batteryManager',
|
|
||||||
type: 'battery.docked',
|
|
||||||
payload: { roverId, batteryState },
|
|
||||||
});
|
|
||||||
} else if (!dockedCharging && state.dockedCharging) {
|
} else if (!dockedCharging && state.dockedCharging) {
|
||||||
state.dockedCharging = false;
|
state.dockedCharging = false;
|
||||||
publishEvent({
|
|
||||||
source: 'batteryManager',
|
|
||||||
type: 'battery.undocked',
|
|
||||||
payload: { roverId, batteryState },
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const fullThreshold =
|
const fullThreshold =
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ import { useEffect, useMemo, useRef, useState } from 'react';
|
|||||||
import { useChat } from '../context/ChatContext.jsx';
|
import { useChat } from '../context/ChatContext.jsx';
|
||||||
import { useSession } from '../context/SessionContext.jsx';
|
import { useSession } from '../context/SessionContext.jsx';
|
||||||
|
|
||||||
function roleColors(role) {
|
function roleColors(role, fromDiscord) {
|
||||||
|
if (fromDiscord) return 'text-indigo-200';
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case 'admin':
|
case 'admin':
|
||||||
case 'lockdown':
|
case 'lockdown':
|
||||||
@@ -73,11 +74,15 @@ export default function ChatPanel() {
|
|||||||
<div
|
<div
|
||||||
key={msg.id}
|
key={msg.id}
|
||||||
className={`surface-muted text-sm flex items-start gap-1 ${
|
className={`surface-muted text-sm flex items-start gap-1 ${
|
||||||
isAdmin ? 'border border-amber-400/30' : msg.fromDiscord? 'border border-indigo-400/30' : ''
|
isAdmin
|
||||||
|
? 'border border-amber-400/30'
|
||||||
|
: msg.fromDiscord
|
||||||
|
? 'border border-indigo-400/30 bg-indigo-900/20'
|
||||||
|
: ''
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<span className="text-[0.75rem] text-slate-400">{formatTime(msg.ts)}</span>
|
<span className="text-[0.75rem] text-slate-400">{formatTime(msg.ts)}</span>
|
||||||
<span className={`font-semibold text-[0.85rem] ${roleColors(msg.role)}`}>
|
<span className={`font-semibold text-[0.85rem] ${roleColors(msg.role, msg.fromDiscord)}`}>
|
||||||
{displayName(msg)}
|
{displayName(msg)}
|
||||||
</span>
|
</span>
|
||||||
{msg.fromDiscord && (
|
{msg.fromDiscord && (
|
||||||
|
|||||||
Reference in New Issue
Block a user