mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 00:27:24 +00:00
Don't show preview tab for projects that are not buildable
This commit is contained in:
4 files changed
+196
-16
No files matched your search
@@ -0,0 +1,38 @@
|
||||
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, package.json, and package-lock.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, hasPackageJson, hasPackageLock] = await Promise.all([
|
||||
projectsManager.fileExists(projectId, 'index.html'),
|
||||
projectsManager.fileExists(projectId, 'package.json'),
|
||||
projectsManager.fileExists(projectId, 'package-lock.json'),
|
||||
]);
|
||||
|
||||
return hasIndexHtml && hasPackageJson && hasPackageLock;
|
||||
} 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,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user