Implement active client on status
Some checks failed
Lint Pull Request / lint (push) Successful in 20s
release-image / release-image (push) Has been cancelled

This commit is contained in:
Logan Cusano
2025-06-29 22:42:20 -04:00
parent a1fda6fe87
commit 464f37adda
2 changed files with 24 additions and 19 deletions

View File

@@ -3,7 +3,7 @@
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { Button } from '@/components/ui/button'; import { Button } from '@/components/ui/button';
import { Card, CardHeader, CardTitle, CardContent } from '@/components/ui/card'; import { Card, CardHeader, CardTitle, CardContent } from '@/components/ui/card';
import { ErrorResponse, NodeStatusResponse, System } from '@/types'; import { ActiveClient, ErrorResponse, NodeStatusResponse, System } from '@/types';
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from '@/components/ui/dialog'; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from '@/components/ui/dialog';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
import { Label } from '@/components/ui/label'; import { Label } from '@/components/ui/label';
@@ -37,6 +37,9 @@ const IndividualClientPage: React.FC<IndividualClientPageProps> = ({ clientId, t
const [isLeaveDiscordDialogOpen, setIsLeaveDiscordDialogOpen] = useState<boolean>(false); const [isLeaveDiscordDialogOpen, setIsLeaveDiscordDialogOpen] = useState<boolean>(false);
const [leaveGuildId, setLeaveGuildId] = useState<string>(''); const [leaveGuildId, setLeaveGuildId] = useState<string>('');
// Active Client States
const [activeClient, setActiveClient] = useState<ActiveClient | null>(null);
const fetchClientStatus = async () => { const fetchClientStatus = async () => {
if (!token) { if (!token) {
@@ -51,6 +54,7 @@ const IndividualClientPage: React.FC<IndividualClientPageProps> = ({ clientId, t
if (response.ok) { if (response.ok) {
const data: NodeStatusResponse = await response.json(); const data: NodeStatusResponse = await response.json();
console.log(data) console.log(data)
setActiveClient(data.active_client);
setCurrentClientDiscordStatus(data.status.discord_status); setCurrentClientDiscordStatus(data.status.discord_status);
setCurrentClientOp25Status(data.status.op25_status) setCurrentClientOp25Status(data.status.op25_status)
} else { } else {
@@ -58,10 +62,10 @@ const IndividualClientPage: React.FC<IndividualClientPageProps> = ({ clientId, t
setCurrentClientOp25Status('Failed to fetch status'); setCurrentClientOp25Status('Failed to fetch status');
} }
} catch (err: any) { } catch (err: any) {
if (err.message === 'Unauthorized: Session expired or invalid token.') { if (err.message === 'Unauthorized: Session expired or invalid token.') {
setLoading(false); // already handled by authAwareFetch setLoading(false); // already handled by authAwareFetch
return; return;
} }
setCurrentClientDiscordStatus('Error fetching status'); setCurrentClientDiscordStatus('Error fetching status');
setCurrentClientOp25Status('Error fetching status'); setCurrentClientOp25Status('Error fetching status');
} finally { } finally {
@@ -92,14 +96,14 @@ const IndividualClientPage: React.FC<IndividualClientPageProps> = ({ clientId, t
setError(errorMsg); setError(errorMsg);
} }
} catch (err: any) { } catch (err: any) {
if (err.message === 'Unauthorized: Session expired or invalid token.') { if (err.message === 'Unauthorized: Session expired or invalid token.') {
setLoading(false); // already handled by authAwareFetch setLoading(false); // already handled by authAwareFetch
return; return;
} }
setError('Failed to fetch systems. Check server connection or console.'); setError('Failed to fetch systems. Check server connection or console.');
console.error(err); console.error(err);
} finally { } finally {
setLoading(false); setLoading(false);
} }
}; };
@@ -109,8 +113,8 @@ const IndividualClientPage: React.FC<IndividualClientPageProps> = ({ clientId, t
fetchClientStatus(); fetchClientStatus();
fetchSystems(); fetchSystems();
} else { } else {
setLoading(false); setLoading(false);
setError('Please log in to manage this client.'); setError('Please log in to manage this client.');
} }
}, [clientId, token, logoutUser]); // Added logoutUser to dependencies to avoid lint warnings }, [clientId, token, logoutUser]); // Added logoutUser to dependencies to avoid lint warnings
@@ -181,10 +185,10 @@ const IndividualClientPage: React.FC<IndividualClientPageProps> = ({ clientId, t
setError(`Failed to ${action} client "${clientId}": ${errorData.message || (typeof errorData.detail === 'string' ? errorData.detail : JSON.stringify(errorData.detail)) || response.statusText}`); setError(`Failed to ${action} client "${clientId}": ${errorData.message || (typeof errorData.detail === 'string' ? errorData.detail : JSON.stringify(errorData.detail)) || response.statusText}`);
} }
} catch (err: any) { } catch (err: any) {
if (err.message === 'Unauthorized: Session expired or invalid token.') { if (err.message === 'Unauthorized: Session expired or invalid token.') {
setLoading(false); // already handled by authAwareFetch setLoading(false); // already handled by authAwareFetch
return; return;
} }
setError(`Network error during ${action} client: ${err.message}`); setError(`Network error during ${action} client: ${err.message}`);
console.error(err); console.error(err);
} finally { } finally {
@@ -215,7 +219,7 @@ const IndividualClientPage: React.FC<IndividualClientPageProps> = ({ clientId, t
return ( return (
<Card className="w-full max-w-md mx-auto mt-8"> <Card className="w-full max-w-md mx-auto mt-8">
<CardHeader> <CardHeader>
<CardTitle>Manage Client: {clientId}</CardTitle> <CardTitle>Manage Client: {activeClient?.nickname} - {clientId}</CardTitle>
</CardHeader> </CardHeader>
<CardContent className="space-y-4"> <CardContent className="space-y-4">
{error && <p className="text-red-500 text-sm">{error}</p>} {error && <p className="text-red-500 text-sm">{error}</p>}

View File

@@ -49,14 +49,15 @@ export enum DemodTypes {
} }
export interface NodeStatusResponse { export interface NodeStatusResponse {
active_client: ActiveClient;
status: { status: {
op25_status: string; op25_status: string;
discord_status: string; discord_status: string;
} };
} }
export interface ActiveClient { export interface ActiveClient {
active_token: string; active_token: DiscordId;
nickname: string; nickname: string;
client_id: string; client_id: string;
} }