/** * Copyright 2022 Design Barn Inc. */ import { Appearance, Size, TextColor } from '@lottiefiles/react-ui-kit'; import { useContext, useEffect } from '@wordpress/element'; import * as React from 'react'; import { useQuery } from 'urql'; import { Button } from '../../../../../_components'; import { CloseIcon, CrownIcon } from '../../../../../assets/Icons'; import { LottiePlayer } from '../../../../../components/LottiePlayer'; import { LottieContext } from '../../../../../context/lottie-provider'; import { useWorkspace } from '../../../../../context/workspace-provider'; import { URLS } from '../../../../../helpers/consts'; import { queries } from '../../../../../helpers/query-strings'; import { saveToMediaLibrary } from '../../../../../utility'; import { isDotLottie, extractDotLottie } from '../../../../../utils'; export const FileModal: React.FC = () => { const { file, setFile, workspace } = useWorkspace(); const { appData, closeModal, setAttributes } = useContext(LottieContext); const [fileUrl, setFileUrl] = React.useState(''); const [{ data, fetching }] = useQuery({ query: queries.fileVersions, variables: { fileId: file, first: 30, orderBy: JSON.stringify({ updatedAt: 'DESC' }) }, }); const fileVersions = (data && data.fileVersions.edges) || []; useEffect(() => { if (!fetching && fileVersions.length > 0) { const defaultUrl = fileVersions[0].node.fileObject.url; setFileUrl(defaultUrl); } }, [fetching]); const isPremium = workspace && workspace.features ? workspace.features['use-private-share'] : false; const onFileSave = (src: string, jsonSrc?: Record | null): void => { setAttributes({ src, jsonSrc }); closeModal(false); // eslint-disable-next-line no-secrets/no-secrets /* tracker.pluginTracking({ eventType: eventsConst.click.insertAnimation, userId: appData.userData.id, eventProperties: { animationId: id, type: eventEnums.animationsType.lottie }, resourceId: id, method: HitCountEvents.DOWNLOAD_LOTTIE_JSON, });*/ }; const onInsert = (lottieUrl: string): void => { if (isPremium) { if (appData.copyLottieToMedia) { saveToMediaLibrary({ url: lottieUrl, onFileSave: (src: string, jsonSrc?: Record) => onFileSave(src, jsonSrc), onError: (error: unknown) => { console.log(error); }, }); } else { if (isDotLottie(lottieUrl)) { const getLottie = async () => { try { const lottieJson = await extractDotLottie(lottieUrl); onFileSave(lottieUrl, lottieJson); } catch (error) { console.log(error); } }; getLottie(); return; } onFileSave(lottieUrl); } } else { saveToMediaLibrary({ url: lottieUrl, onFileSave: (src: string, jsonSrc?: Record) => onFileSave(src, jsonSrc), onError: (error: unknown) => { console.log(error); }, }); } }; const renderDropdown = () => { if (!fetching && fileVersions) { return ( ); } else return
; }; return ( fileUrl && (
{isPremium && renderDropdown()} {!isPremium && (

This animation will be copied to your media library and inserted as a local Lottie JSON.

Upgrade to link this animation directly with custom embed
  • · Changes to the animation will be reflected immediately
  • · Improve your website's performance
)}
) ); };