mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
34 lines
1006 B
TypeScript
34 lines
1006 B
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
import { useProjectsManager } from './useProjectsManager';
|
|
|
|
/**
|
|
* Hook to check if a project is previewable
|
|
* A project is previewable if it has index.html and package.json
|
|
*/
|
|
export function useIsProjectPreviewable(projectId: string) {
|
|
const projectsManager = useProjectsManager();
|
|
|
|
const result = useQuery({
|
|
queryKey: ['project-previewable', projectId],
|
|
queryFn: async () => {
|
|
try {
|
|
// Check for required files
|
|
const hasIndexHtml = await projectsManager.fileExists(projectId, 'index.html');
|
|
|
|
return hasIndexHtml;
|
|
} catch (error) {
|
|
console.error('Failed to check if project is previewable:', error);
|
|
return false;
|
|
}
|
|
},
|
|
enabled: !!projectId,
|
|
staleTime: 5000, // Cache for 5 seconds
|
|
refetchOnWindowFocus: false,
|
|
});
|
|
|
|
// Return false when query is disabled (empty projectId) or when data is undefined
|
|
return {
|
|
...result,
|
|
data: result.data ?? false,
|
|
};
|
|
} |