mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-05-10 22:46:37 +00:00
56 lines
1.3 KiB
TypeScript
56 lines
1.3 KiB
TypeScript
import { useCallback, useState } from 'react';
|
|
|
|
export function useSessionProtection() {
|
|
const [activeSessions, setActiveSessions] = useState<Set<string>>(new Set());
|
|
const [processingSessions, setProcessingSessions] = useState<Set<string>>(new Set());
|
|
|
|
const markSessionAsActive = useCallback((sessionId?: string | null) => {
|
|
if (!sessionId) {
|
|
return;
|
|
}
|
|
|
|
setActiveSessions((prev) => new Set([...prev, sessionId]));
|
|
}, []);
|
|
|
|
const markSessionAsInactive = useCallback((sessionId?: string | null) => {
|
|
if (!sessionId) {
|
|
return;
|
|
}
|
|
|
|
setActiveSessions((prev) => {
|
|
const next = new Set(prev);
|
|
next.delete(sessionId);
|
|
return next;
|
|
});
|
|
}, []);
|
|
|
|
const markSessionAsProcessing = useCallback((sessionId?: string | null) => {
|
|
if (!sessionId) {
|
|
return;
|
|
}
|
|
|
|
setProcessingSessions((prev) => new Set([...prev, sessionId]));
|
|
}, []);
|
|
|
|
const markSessionAsNotProcessing = useCallback((sessionId?: string | null) => {
|
|
if (!sessionId) {
|
|
return;
|
|
}
|
|
|
|
setProcessingSessions((prev) => {
|
|
const next = new Set(prev);
|
|
next.delete(sessionId);
|
|
return next;
|
|
});
|
|
}, []);
|
|
|
|
return {
|
|
activeSessions,
|
|
processingSessions,
|
|
markSessionAsActive,
|
|
markSessionAsInactive,
|
|
markSessionAsProcessing,
|
|
markSessionAsNotProcessing,
|
|
};
|
|
}
|