Enhance connection status display: add bridge connection status and last update time
This commit is contained in:
@@ -12,10 +12,25 @@ import './App.css';
|
|||||||
function App() {
|
function App() {
|
||||||
const connect = useInventoryStore((state) => state.connect);
|
const connect = useInventoryStore((state) => state.connect);
|
||||||
const connected = useInventoryStore((state) => state.connected);
|
const connected = useInventoryStore((state) => state.connected);
|
||||||
|
const bridgeConnected = useInventoryStore((state) => state.bridgeConnected);
|
||||||
|
const lastUpdate = useInventoryStore((state) => state.lastUpdate);
|
||||||
const commandResult = useInventoryStore((state) => state.commandResult);
|
const commandResult = useInventoryStore((state) => state.commandResult);
|
||||||
const alerts = useInventoryStore((state) => state.alerts) || [];
|
const alerts = useInventoryStore((state) => state.alerts) || [];
|
||||||
const [panelTab, setPanelTab] = useState('inventory');
|
const [panelTab, setPanelTab] = useState('inventory');
|
||||||
const [showAlerts, setShowAlerts] = useState(false);
|
const [showAlerts, setShowAlerts] = useState(false);
|
||||||
|
const [, forceRender] = useState(0);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
connect();
|
||||||
|
}, [connect]);
|
||||||
|
|
||||||
|
// Re-render every 5s so the "last updated" text stays fresh
|
||||||
|
useEffect(() => {
|
||||||
|
const id = setInterval(() => forceRender((n) => n + 1), 5000);
|
||||||
|
return () => clearInterval(id);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const staleSecs = lastUpdate ? Math.floor((Date.now() - lastUpdate) / 1000) : null;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
connect();
|
connect();
|
||||||
@@ -58,6 +73,17 @@ function App() {
|
|||||||
<span className="status-dot"></span>
|
<span className="status-dot"></span>
|
||||||
{connected ? 'Connected' : 'Disconnected'}
|
{connected ? 'Connected' : 'Disconnected'}
|
||||||
</div>
|
</div>
|
||||||
|
{connected && (
|
||||||
|
<div className={`connection-status ${bridgeConnected ? 'connected' : 'disconnected'}`} title="Minecraft CC:Tweaked bridge">
|
||||||
|
<span className="status-dot"></span>
|
||||||
|
{bridgeConnected ? 'Bridge OK' : 'Bridge Off'}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{staleSecs !== null && staleSecs > 0 && (
|
||||||
|
<span className="last-update-text" title="Time since last data update">
|
||||||
|
{staleSecs < 60 ? `${staleSecs}s ago` : `${Math.floor(staleSecs / 60)}m ago`}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user