mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-20 15:09:23 +02:00
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>
60 lines
No EOL
1.7 KiB
TypeScript
60 lines
No EOL
1.7 KiB
TypeScript
import { useState, useCallback } from 'react';
|
|
import { photoStorageOptimizedService } from '../photoStorageOptimized.service';
|
|
|
|
interface UseMemoPhotosReturn {
|
|
hasPhotos: (memoId: string) => boolean;
|
|
loading: boolean;
|
|
checkPhotoStatus: (memoIds: string[]) => Promise<void>;
|
|
}
|
|
|
|
/**
|
|
* Hook to efficiently check photo status for multiple memos
|
|
*/
|
|
export function useMemoPhotos(): UseMemoPhotosReturn {
|
|
const [photoStatus, setPhotoStatus] = useState<{[memoId: string]: boolean}>({});
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
/**
|
|
* Check if a memo has photos
|
|
*/
|
|
const hasPhotos = useCallback((memoId: string): boolean => {
|
|
const result = photoStatus[memoId] || false;
|
|
return result;
|
|
}, [photoStatus]);
|
|
|
|
/**
|
|
* Check photo status for multiple memos using optimized batch query
|
|
*/
|
|
const checkPhotoStatus = useCallback(async (memoIds: string[]) => {
|
|
if (memoIds.length === 0) return;
|
|
|
|
try {
|
|
setLoading(true);
|
|
|
|
console.debug(`checkPhotoStatus: Batch checking ${memoIds.length} memos`);
|
|
|
|
// Use optimized batch check - ONE database call instead of N
|
|
const photoStatusMap = await photoStorageOptimizedService.batchCheckPhotosForMemos(memoIds);
|
|
|
|
// Update state with batch results
|
|
setPhotoStatus(prevStatus => {
|
|
const newStatus = { ...prevStatus };
|
|
photoStatusMap.forEach((hasPhotos, memoId) => {
|
|
newStatus[memoId] = hasPhotos;
|
|
});
|
|
return newStatus;
|
|
});
|
|
|
|
} catch (error) {
|
|
console.debug('Error checking photo status:', error);
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
}, []);
|
|
|
|
return {
|
|
hasPhotos,
|
|
loading,
|
|
checkPhotoStatus,
|
|
};
|
|
} |