/**
* Copyright 2021 Design Barn Inc.
*/
/* eslint-disable @typescript-eslint/no-explicit-any */
import React from 'react';
import { useParams } from 'react-router-dom';
import { useQuery } from 'urql';
import { useWorkspace } from '../../../../context/workspace-provider';
import { queries } from '../../../../helpers/query-strings';
import { Empty } from './components/empty';
import { ErrorView } from './components/error-view';
import { FileCard } from './components/file-card';
import { FolderCard } from './components/folder-card';
import { Loading } from './components/loading';
export const Project = () => {
const { setProject } = useWorkspace();
const params = useParams<{ projectId: string }>();
const [{ data: projectData, error: projectError, fetching: projectLoading }] = useQuery({
query: queries.project,
variables: {
id: params.projectId,
},
});
const [{ data: folderData, error: folderError, fetching: folderLoading }] = useQuery({
query: queries.projectFiles,
requestPolicy: 'network-only',
variables: {
id: params.projectId,
type: 'folders',
orderBy: JSON.stringify({ updatedAt: 'DESC' }),
},
});
const [{ data: fileData, error: fileError, fetching: fileLoading }] = useQuery({
query: queries.projectFiles,
requestPolicy: 'network-only',
variables: {
id: params.projectId,
type: 'animations',
orderBy: JSON.stringify({ updatedAt: 'DESC' }),
},
});
// const onFileSave = (src: string): void => {
// setAttributes({ src });
// exploreLottie(false);
// // tracker.pluginTracking({
// // eventType: eventsConst.click.insertAnimation,
// // userId: appData.userData.id,
// // eventProperties: { animationId: id, type: eventEnums.animationsType.lottie },
// // resourceId: id,
// eslint-disable-next-line no-secrets/no-secrets
// // method: HitCountEvents.DOWNLOAD_LOTTIE_JSON,
// // });
// };
// const onInsert = (lottieUrl: string): void => {
// if (appData.copyLottieToMedia) {
// saveToMediaLibrary({
// url: lottieUrl,
// onFileSave: (src: string) => onFileSave(src),
// });
// } else {
// onFileSave(lottieUrl);
// }
// };
const folders = (folderData && folderData.projectFiles.edges) || [];
const files = (fileData && fileData.projectFiles.edges) || [];
const project = projectData && projectData.project;
React.useEffect(() => {
if (project) {
setProject(project);
}
}, [projectData]);
const renderContent = () => {
const noFolders = folders.length === 0;
const noFiles = files.length === 0;
const noProject = params.projectId === '';
if (folderLoading || fileLoading || projectLoading) {
return