improved queue, first steps to improve history

This commit is contained in:
Xoconoch
2025-07-28 18:12:59 -06:00
parent 36134bde1f
commit db3eee3c63
6 changed files with 2763 additions and 716 deletions

View File

@@ -1,4 +1,4 @@
import { useState, useCallback, type ReactNode, useEffect, useRef } from "react";
import { useState, useCallback, type ReactNode, useEffect, useRef, useMemo } from "react";
import apiClient from "../lib/api-client";
import {
QueueContext,
@@ -41,6 +41,11 @@ export function QueueProvider({ children }: { children: ReactNode }) {
const [isVisible, setIsVisible] = useState(false);
const pollingIntervals = useRef<Record<string, number>>({});
// Calculate active downloads count
const activeCount = useMemo(() => {
return items.filter(item => !isTerminalStatus(item.status)).length;
}, [items]);
const stopPolling = useCallback((internalId: string) => {
if (pollingIntervals.current[internalId]) {
clearInterval(pollingIntervals.current[internalId]);
@@ -180,7 +185,6 @@ export function QueueProvider({ children }: { children: ReactNode }) {
status: "initializing",
};
setItems(prev => [newItem, ...prev]);
setIsVisible(true);
try {
const response = await apiClient.get<{ task_id: string }>(
@@ -398,6 +402,7 @@ export function QueueProvider({ children }: { children: ReactNode }) {
const value = {
items,
isVisible,
activeCount,
addItem,
removeItem,
retryItem,