mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import { useState, useEffect } from 'react';
|
|
import { useSessionManager } from '@/hooks/useSessionManager';
|
|
|
|
/**
|
|
* Hook to get session status for a specific project
|
|
*/
|
|
export function useProjectSessionStatus(projectId: string) {
|
|
const sessionManager = useSessionManager();
|
|
const [hasActiveSessions, setHasActiveSessions] = useState(false);
|
|
const [hasRunningSessions, setHasRunningSessions] = useState(false);
|
|
|
|
useEffect(() => {
|
|
const updateStatus = () => {
|
|
const projectSession = sessionManager.getSession(projectId);
|
|
|
|
setHasActiveSessions(!!projectSession);
|
|
setHasRunningSessions(!!projectSession?.isLoading);
|
|
};
|
|
|
|
// Initial update
|
|
updateStatus();
|
|
|
|
// Subscribe to session changes
|
|
sessionManager.on('sessionCreated', updateStatus);
|
|
sessionManager.on('sessionDeleted', updateStatus);
|
|
sessionManager.on('loadingChanged', updateStatus);
|
|
|
|
return () => {
|
|
sessionManager.off('sessionCreated', updateStatus);
|
|
sessionManager.off('sessionDeleted', updateStatus);
|
|
sessionManager.off('loadingChanged', updateStatus);
|
|
};
|
|
}, [sessionManager, projectId]);
|
|
|
|
return {
|
|
hasActiveSessions,
|
|
hasRunningSessions
|
|
};
|
|
} |