All Downloads are FREE. Search and download functionalities are using the official Maven repository.

web.lib.components.generate-project.generate-button.tsx Maven / Gradle / Ivy

There is a newer version: 37
Show newest version
import { MouseEventHandler, useState } from 'react';
import { useAnalytics } from '../../core/analytics';
import { createOnGitHub, getProjectDownloadUrl, Target, existsStoredProject } from '../api/quarkus-project-utils';
import { QuarkusProject } from '../api/model';
import { useHotkeys } from 'react-hotkeys-hook';
import { Button, ButtonGroup, Dropdown } from 'react-bootstrap';
import { FaAngleDown, FaAngleUp, FaDownload, FaGithub, FaBookmark, FaCheck, FaTrashAlt } from 'react-icons/fa';
import './generate-button.scss';
import DropdownToggle from 'react-bootstrap/DropdownToggle';
import { Api } from '../api/code-quarkus-api';

export function GenerateButtonPrimary(props: { onClick: MouseEventHandler, disabled: boolean }) {
  const keyName = window.navigator.userAgent.toLowerCase().indexOf('mac') > -1 ? '⌥' : 'alt';
  return (
    
  );
}

export function GenerateButton(props: { api: Api, project: QuarkusProject, isProjectValid: boolean, generate: (target?: Target) => void, githubClientId?: string, isConfigSaved: boolean, storeAppConfig: () => void, resetAppConfig: () => void }) {

  const [ isMoreOpen , setIsMoreOpen ] = useState(false);
  const [ isResetEnabled, setResetEnabled] = useState(existsStoredProject());

  const analytics = useAnalytics();

  function onMouseEnterFn(e) {
    onToggleFn(true);
  }

  function onMouseLeaveFn(e) {
    onToggleFn(false);
  }

  function onToggleFn(isOpen: boolean) {
    setIsMoreOpen(isOpen);
    analytics.event('Generate app dropdown', { action: isOpen ? 'close': 'open', element: 'generate-button' });
  }
  
  function handleStoreAppConfig() {
    props.storeAppConfig();
    setResetEnabled(true);
    analytics.event('Store app config', { element: 'generate-button' });
  }

  function resetStoredAppConfig() {
    props.resetAppConfig();
    setResetEnabled(false);
    analytics.event('Reset app config', { element: 'generate-button' });
  }

  const downloadZip = (e: any) => {
    e.preventDefault();
    props.generate(Target.DOWNLOAD);
  };

  const defaultGenerate = () => {
    props.generate(Target.GENERATE);
  };

  const downloadUrl = getProjectDownloadUrl(props.api, props.project);

  const githubClick = () => {
    analytics.event('Click', { label: 'Create on Github', element: 'generate-button' });
    createOnGitHub(props.api, props.project, props.githubClientId!);
  };

  useHotkeys('alt+enter', defaultGenerate, [ props.isProjectValid, props.generate ]);

  return (
    
      
      
        {isMoreOpen ?  : }
      
      
        
           Download as a zip
        
        {props.githubClientId && (
          
             Push to GitHub
          
        )}
        
          
{ props.isConfigSaved ? : } Store current app as default
{ isResetEnabled && }
); }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy