Upload updates

This commit is contained in:
2026-09-21 09:01:01 -05:00
parent 98025e9e6d
commit 474403ffe2
18 changed files with 2539 additions and 796 deletions
+30
View File
@@ -0,0 +1,30 @@
import { useQuery } from "@tanstack/react-query";
import { api } from "@/lib/api";
import { hasBackend } from "@/lib/backend";
import type { UploadStatus } from "@/lib/types";
import { useAuth } from "@/store/auth";
export const uploadStatusQueryKey = ["upload-status"] as const;
/**
* Poll the server-side upload pipeline while it has work and stop once it is
* idle. Shared by the Upload page and the shell indicator so both show the
* same state without extra requests.
*/
export function useUploadStatus(enabled = true) {
const user = useAuth((state) => state.user);
return useQuery({
queryKey: uploadStatusQueryKey,
queryFn: () => api<UploadStatus>("/api/uploads/status/"),
enabled: enabled && hasBackend() && Boolean(user?.can_upload),
// TanStack takes the smallest interval across the observers, so the
// Upload page and the shell pill can safely share this query.
refetchInterval: (query) => (query.state.data?.active ? 2_000 : false),
});
}
/** Ask the server to (re)start processing the caller's staged uploads. */
export function postProcessUploads(): Promise<UploadStatus> {
return api<UploadStatus>("/api/uploads/process/", { method: "POST" });
}