import * as React from 'react'; import { Messenger, messageHandler } from '@estruyf/vscode/dist/client'; import { DashboardMessage } from '../../DashboardMessage'; import { Settings } from '../../models/Settings'; import { Status } from '../../models/Status'; import { Step } from './Step'; import { useMemo, useState } from 'react'; import { Menu } from '@headlessui/react'; import { MenuItem } from '../Menu'; import { Framework, StaticFolder, Template } from '../../../models'; import { ChevronDownIcon } from '@heroicons/react/24/outline'; import { FrameworkDetectors } from '../../../constants/FrameworkDetectors'; import * as l10n from '@vscode/l10n'; import { LocalizationKey } from '../../../localization'; import { SelectItem } from './SelectItem'; import { GeneralCommands, SETTING_GIT_ENABLED, Templates } from '../../../constants'; import { TemplateItem } from './TemplateItem'; import { Spinner } from '../Common/Spinner'; import { AstroContentTypes } from '../Configuration/Astro/AstroContentTypes'; import { ContentFolders } from '../Configuration/Common/ContentFolders'; import { VSCodeCheckbox } from '@vscode/webview-ui-toolkit/react'; export interface IStepsToGetStartedProps { settings: Settings; } export const StepsToGetStarted: React.FunctionComponent = ({ settings }: React.PropsWithChildren) => { const [loading, setLoading] = useState(false); const [framework, setFramework] = useState(null); const [taxImported, setTaxImported] = useState(false); const [isGitEnabled, setIsGitEnabled] = useState(false); const [isGitRepo, setIsGitRepo] = useState(false); const [templates, setTemplates] = useState([]); const [astroCollectionsStatus, setAstroCollectionsStatus] = useState(Status.Optional); const frameworks: Framework[] = FrameworkDetectors.map((detector: any) => detector.framework); const setFrameworkAndSendMessage = (framework: string) => { setFramework(framework); Messenger.send(DashboardMessage.setFramework, framework); }; const addAssetFolder = (folder: string | StaticFolder) => { Messenger.send(DashboardMessage.addAssetsFolder, folder); } const triggerTemplate = (template: Template) => { setLoading(true); messageHandler.request(DashboardMessage.triggerTemplate, template).then((result) => { setLoading(false); if (result) { reload(); } }); } const showNotification = () => { Messenger.send(DashboardMessage.openConfig); }; const reload = () => { const crntState: any = Messenger.getState() || {}; Messenger.setState({ ...crntState, isWelcomeConfiguring: false }); Messenger.send(DashboardMessage.reload); }; const importTaxonomy = () => { Messenger.send(DashboardMessage.importTaxonomy); setTaxImported(true); }; const updateSetting = (name: string, value: any) => { setIsGitEnabled(value); Messenger.send(DashboardMessage.updateSetting, { name, value, global: true }); } const crntTemplates = useMemo(() => { if (!templates || templates.length === 0 || !settings.crntFramework) { return []; } return templates.filter((t) => t.type === settings.crntFramework); }, [templates, settings.crntFramework]) const steps = useMemo(() => ( [ { id: `welcome-init`, name: l10n.t(LocalizationKey.dashboardStepsStepsToGetStartedInitializeProjectName), description: <>{l10n.t(LocalizationKey.dashboardStepsStepsToGetStartedInitializeProjectDescription)}, show: true, status: settings.initialized ? Status.Completed : Status.NotStarted, onClick: settings.initialized ? undefined : () => { Messenger.send(DashboardMessage.initializeProject); } }, { id: `welcome-framework`, name: l10n.t(LocalizationKey.dashboardStepsStepsToGetStartedFrameworkName), description: (
{l10n.t(LocalizationKey.dashboardStepsStepsToGetStartedFrameworkDescription)}
{framework ? framework : l10n.t(LocalizationKey.dashboardStepsStepsToGetStartedFrameworkSelect)}
setFrameworkAndSendMessage(value)} />
{frameworks.map((f) => ( setFrameworkAndSendMessage(value)} /> ))}
), show: true, status: settings.crntFramework ? Status.Completed : Status.NotStarted, onClick: undefined }, { id: `welcome-template`, name: l10n.t(LocalizationKey.dashboardStepsStepsToGetStartedTemplateName), description: (
{l10n.t(LocalizationKey.dashboardStepsStepsToGetStartedTemplateDescription)}
{ crntTemplates && (crntTemplates || []).map(template => ( triggerTemplate(template)} /> )) }

{l10n.t(LocalizationKey.commonImportant)}: {l10n.t(LocalizationKey.dashboardStepsStepsToGetStartedTemplateWarning)}

), show: (crntTemplates || []).length > 0, status: Status.Optional, }, { id: `astro-content-types`, name: l10n.t(LocalizationKey.dashboardStepsStepsToGetStartedAstroContentTypesName), description: ( setLoading(isLoading)} setStatus={(status) => setAstroCollectionsStatus(status)} /> ), show: settings.crntFramework === 'astro', status: astroCollectionsStatus }, { id: `welcome-content-folders`, name: l10n.t(LocalizationKey.dashboardStepsStepsToGetStartedContentFoldersName), description: ( setLoading(isLoading)} /> ), show: true, status: settings.contentFolders && settings.contentFolders.length > 0 ? Status.Completed : Status.NotStarted }, { id: `welcome-assets`, name: l10n.t(LocalizationKey.dashboardStepsStepsToGetStartedAssetsFolderName), description: (
{l10n.t(LocalizationKey.dashboardStepsStepsToGetStartedAssetsFolderDescription)}
addAssetFolder(`public`)} /> addAssetFolder({ "path": "src/assets", "relative": true })} />

{l10n.t(LocalizationKey.commonInformation)}: {l10n.t(LocalizationKey.dashboardStepsStepsToGetStartedAssetsFolderOtherDescription)}

), show: settings.crntFramework === 'astro' || framework === 'astro', status: settings.initialized && settings.staticFolder && settings.staticFolder !== "/" ? Status.Completed : Status.NotStarted, }, { id: `welcome-git`, name: l10n.t(LocalizationKey.dashboardStepsStepsToGetStartedGitName), description: (
) => updateSetting(SETTING_GIT_ENABLED, e.target.checked)} checked={isGitEnabled}> {l10n.t(LocalizationKey.dashboardStepsStepsToGetStartedGitDescription)}
), show: isGitRepo, status: settings.git?.actions ? Status.Completed : Status.NotStarted }, { id: `welcome-import`, name: l10n.t(LocalizationKey.dashboardStepsStepsToGetStartedTagsName), description: <>{l10n.t(LocalizationKey.dashboardStepsStepsToGetStartedTagsDescription)}, show: true, status: taxImported ? Status.Completed : Status.NotStarted, onClick: settings.contentFolders && settings.contentFolders.length > 0 ? importTaxonomy : undefined }, { id: `welcome-show-dashboard`, name: l10n.t(LocalizationKey.dashboardStepsStepsToGetStartedShowDashboardName), description: <>{l10n.t(LocalizationKey.dashboardStepsStepsToGetStartedShowDashboardDescription)}, show: true, status: settings.initialized && settings.contentFolders && settings.contentFolders.length > 0 ? Status.Active : Status.NotStarted, onClick: settings.initialized && settings.contentFolders && settings.contentFolders.length > 0 ? () => { showNotification(); reload(); } : undefined } ] ), [settings, framework, taxImported, templates, astroCollectionsStatus, isGitRepo]); React.useEffect(() => { if (settings.crntFramework || settings.framework?.name) { setFramework(settings.crntFramework || settings.framework?.name || null); } }, [settings.crntFramework, settings.framework]); React.useEffect(() => { messageHandler.request(GeneralCommands.toVSCode.git.isRepo).then((result) => { setIsGitRepo(result); }); setIsGitEnabled(settings.git?.actions || false); }, [settings.git?.actions]); React.useEffect(() => { const fetchTemplates = async () => { try { const response = await fetch(Templates.url); if (response.ok) { const data = await response.json(); setTemplates(data); } } catch (e) { setTemplates([]); } }; fetchTemplates(); }, []); return ( ); };