managarten/memoro/apps/mobile/features/storage/hooks/useUploadProgress.ts
Till-JS e7f5f942f3 chore: initial commit - consolidate 4 projects into monorepo
Projects included:
- maerchenzauber (NestJS backend + Expo mobile + SvelteKit web + Astro landing)
- manacore (Expo mobile + SvelteKit web + Astro landing)
- manadeck (NestJS backend + Expo mobile + SvelteKit web)
- memoro (Expo mobile + SvelteKit web + Astro landing)

This commit preserves the current state before monorepo restructuring.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-22 23:38:24 +01:00

43 lines
1.4 KiB
TypeScript

import { useUploadStatusStore } from '../store/uploadStatusStore';
import { UploadStatus } from '../uploadStatus.types';
interface UploadProgressState {
status: UploadStatus;
error?: string;
attemptCount: number;
memoId?: string;
isUploading: boolean;
isPending: boolean;
isFailed: boolean;
isSuccess: boolean;
}
/**
* Hook to track upload status for a specific audio file using Zustand subscriptions.
* No polling - updates automatically when upload status changes.
* Safe from memory leaks as Zustand handles subscription cleanup.
*
* @param audioFileId - The ID of the audio file being uploaded
* @returns Upload state with status, error, and boolean helpers
*/
export function useUploadProgress(audioFileId: string | undefined): UploadProgressState {
// Subscribe directly to Zustand store - no manual cleanup needed
const status = useUploadStatusStore((state) =>
audioFileId ? state.getStatus(audioFileId) : UploadStatus.SUCCESS
);
const metadata = useUploadStatusStore((state) =>
audioFileId ? state.getMetadata(audioFileId) : undefined
);
return {
status,
error: metadata?.lastError,
attemptCount: metadata?.attemptCount || 0,
memoId: metadata?.memoId,
isUploading: status === UploadStatus.UPLOADING,
isPending: status === UploadStatus.PENDING,
isFailed: status === UploadStatus.FAILED,
isSuccess: status === UploadStatus.SUCCESS,
};
}