diff --git a/l10n/bundle.l10n.json b/l10n/bundle.l10n.json index 3ee4a2e7..25d3f0ef 100644 --- a/l10n/bundle.l10n.json +++ b/l10n/bundle.l10n.json @@ -50,6 +50,8 @@ "settings.diagnostic": "Diagnostic", "settings.diagnostic.description": "You can run the diagnostics to check the whole Front Matter CMS configuration.", "settings.diagnostic.link": "Run full diagnostics", + "settings.git.enabled": "Git synchronization", + "settings.git.enabled.description": "Enable Git synchronization to easily sync your changes with your repository.", "settings.commonSettings.website.title": "Website and SSG settings", "settings.commonSettings.previewUrl": "Preview URL", @@ -278,6 +280,8 @@ "dashboard.steps.stepsToGetStarted.contentFolders.information.description": "You can also perform this action by right-clicking on the folder in the explorer view, and selecting register folder", "dashboard.steps.stepsToGetStarted.tags.name": "Import all tags and categories (optional)", "dashboard.steps.stepsToGetStarted.tags.description": "Now that Front Matter knows all the content folders. Would you like to import all tags and categories from the available content?", + "dashboard.steps.stepsToGetStarted.git.name": "Do you want to enable Git synchronization?", + "dashboard.steps.stepsToGetStarted.git.description": "Enable Git synchronization to eaily sync your changes with your repository.", "dashboard.steps.stepsToGetStarted.showDashboard.name": "Show the dashboard", "dashboard.steps.stepsToGetStarted.showDashboard.description": "Once all actions are completed, the dashboard can be loaded.", "dashboard.steps.stepsToGetStarted.template.name": "Use a configuration template", diff --git a/src/constants/GeneralCommands.ts b/src/constants/GeneralCommands.ts index ccb77129..bd641174 100644 --- a/src/constants/GeneralCommands.ts +++ b/src/constants/GeneralCommands.ts @@ -8,6 +8,7 @@ export const GeneralCommands = { toVSCode: { openLink: 'openLink', gitSync: 'gitSync', + gitIsRepo: 'gitIsRepo', getLocalization: 'getLocalization', openOnWebsite: 'openOnWebsite' } diff --git a/src/dashboardWebView/components/SettingsView/CommonSettings.tsx b/src/dashboardWebView/components/SettingsView/CommonSettings.tsx index 33c2ce91..75acd3a9 100644 --- a/src/dashboardWebView/components/SettingsView/CommonSettings.tsx +++ b/src/dashboardWebView/components/SettingsView/CommonSettings.tsx @@ -6,15 +6,16 @@ import { useRecoilValue } from 'recoil'; import { SettingsSelector } from '../../state'; import { SettingsInput } from './SettingsInput'; import { VSCodeButton } from '@vscode/webview-ui-toolkit/react'; -import { FrameworkDetectors, SETTING_FRAMEWORK_START, SETTING_PREVIEW_HOST, SETTING_WEBSITE_URL } from '../../../constants'; +import { FrameworkDetectors, SETTING_FRAMEWORK_START, SETTING_GIT_ENABLED, SETTING_PREVIEW_HOST, SETTING_WEBSITE_URL } from '../../../constants'; import { messageHandler } from '@estruyf/vscode/dist/client'; import { DashboardMessage } from '../../DashboardMessage'; +import { SettingsCheckbox } from './SettingsCheckbox'; export interface ICommonSettingsProps { } interface Config { name: string; - value: string; + value: string | boolean; } export const CommonSettings: React.FunctionComponent = (props: React.PropsWithChildren) => { @@ -22,7 +23,7 @@ export const CommonSettings: React.FunctionComponent = (pr const [config, setConfig] = React.useState([]); const [updated, setUpdated] = React.useState(false); - const onSettingChange = React.useCallback((name: string, value: string) => { + const onSettingChange = React.useCallback((name: string, value: string | boolean) => { setConfig((prev) => { const setting = prev.find((c) => c.name === name); if (setting) { @@ -39,7 +40,12 @@ export const CommonSettings: React.FunctionComponent = (pr }, [config]); const retrieveSettings = () => { - messageHandler.request(DashboardMessage.getSettings, [SETTING_PREVIEW_HOST, SETTING_WEBSITE_URL, SETTING_FRAMEWORK_START]).then((config) => { + messageHandler.request(DashboardMessage.getSettings, [ + SETTING_PREVIEW_HOST, + SETTING_WEBSITE_URL, + SETTING_FRAMEWORK_START, + SETTING_GIT_ENABLED + ]).then((config) => { setConfig(config); setUpdated(false); }); @@ -65,6 +71,19 @@ export const CommonSettings: React.FunctionComponent = (pr +
+

{l10n.t(LocalizationKey.settingsGitEnabled)}

+ +
+ c.name === SETTING_GIT_ENABLED)?.value || false) as boolean} + onChange={onSettingChange} + /> +
+
+

{l10n.t(LocalizationKey.settingsCommonSettingsWebsiteTitle)}

@@ -72,21 +91,21 @@ export const CommonSettings: React.FunctionComponent = (pr c.name === SETTING_PREVIEW_HOST)?.value || ""} + value={(config.find((c) => c.name === SETTING_PREVIEW_HOST)?.value || "") as string} onChange={onSettingChange} /> c.name === SETTING_WEBSITE_URL)?.value || ""} + value={(config.find((c) => c.name === SETTING_WEBSITE_URL)?.value || "") as string} onChange={onSettingChange} /> c.name === SETTING_FRAMEWORK_START)?.value || ""} + value={(config.find((c) => c.name === SETTING_FRAMEWORK_START)?.value || "") as string} onChange={onSettingChange} fallback={FrameworkDetectors.find((f) => f.framework.name === settings?.crntFramework)?.commands.start || ""} /> diff --git a/src/dashboardWebView/components/SettingsView/SettingsCheckbox.tsx b/src/dashboardWebView/components/SettingsView/SettingsCheckbox.tsx new file mode 100644 index 00000000..71f2ee67 --- /dev/null +++ b/src/dashboardWebView/components/SettingsView/SettingsCheckbox.tsx @@ -0,0 +1,35 @@ +import { VSCodeCheckbox } from '@vscode/webview-ui-toolkit/react'; +import * as React from 'react'; + +export interface ISettingsCheckboxProps { + label: string; + name: string; + value: boolean; + onChange: (key: string, value: boolean) => void; +} + +export const SettingsCheckbox: React.FunctionComponent = ({ + label, + name, + value, + onChange +}: React.PropsWithChildren) => { + const [isEnabled, setIsEnabled] = React.useState(false); + + const updateValue = (value: boolean) => { + setIsEnabled(value); + onChange(name, value); + } + + React.useEffect(() => { + setIsEnabled(value); + }, [value]); + + return ( + ) => updateValue(e.target.checked)} + checked={isEnabled}> + {label} + + ); +}; \ No newline at end of file diff --git a/src/dashboardWebView/components/Steps/StepsToGetStarted.tsx b/src/dashboardWebView/components/Steps/StepsToGetStarted.tsx index 5b873d64..2e1c3fc5 100644 --- a/src/dashboardWebView/components/Steps/StepsToGetStarted.tsx +++ b/src/dashboardWebView/components/Steps/StepsToGetStarted.tsx @@ -13,11 +13,12 @@ import { FrameworkDetectors } from '../../../constants/FrameworkDetectors'; import * as l10n from '@vscode/l10n'; import { LocalizationKey } from '../../../localization'; import { SelectItem } from './SelectItem'; -import { Templates } from '../../../constants'; +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; @@ -29,6 +30,8 @@ export const StepsToGetStarted: React.FunctionComponent 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); @@ -73,6 +76,15 @@ export const StepsToGetStarted: React.FunctionComponent 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 []; @@ -230,6 +242,21 @@ export const StepsToGetStarted: React.FunctionComponent 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), @@ -257,7 +284,7 @@ export const StepsToGetStarted: React.FunctionComponent : undefined } ] - ), [settings, framework, taxImported, templates, astroCollectionsStatus]); + ), [settings, framework, taxImported, templates, astroCollectionsStatus, isGitRepo]); React.useEffect(() => { if (settings.crntFramework || settings.framework?.name) { @@ -265,6 +292,14 @@ export const StepsToGetStarted: React.FunctionComponent } }, [settings.crntFramework, settings.framework]); + React.useEffect(() => { + messageHandler.request(GeneralCommands.toVSCode.gitIsRepo).then((result) => { + setIsGitRepo(result); + }); + + setIsGitEnabled(settings.git.actions); + }, [settings.git.actions]); + React.useEffect(() => { const fetchTemplates = async () => { try { diff --git a/src/listeners/dashboard/SettingsListener.ts b/src/listeners/dashboard/SettingsListener.ts index 74492212..030f1102 100644 --- a/src/listeners/dashboard/SettingsListener.ts +++ b/src/listeners/dashboard/SettingsListener.ts @@ -127,9 +127,9 @@ export class SettingsListener extends BaseListener { * Update a setting from the dashboard * @param data */ - private static async update(data: { name: string; value: any }) { + private static async update(data: { name: string; value: any; global?: boolean }) { if (data.name) { - await Settings.update(data.name, data.value); + await Settings.update(data.name, data.value, data.global); this.getSettings(true); } } diff --git a/src/listeners/general/GitListener.ts b/src/listeners/general/GitListener.ts index e4e76537..32813c07 100644 --- a/src/listeners/general/GitListener.ts +++ b/src/listeners/general/GitListener.ts @@ -65,12 +65,24 @@ export class GitListener { */ public static process(msg: PostMessageData) { switch (msg.command) { + case GeneralCommands.toVSCode.gitIsRepo: + this.checkIsGitRepo(msg.command, msg.requestId); + break; case GeneralCommands.toVSCode.gitSync: this.sync(); break; } } + public static async checkIsGitRepo(command: string, requestId?: string) { + if (!command || !requestId) { + return; + } + + const isRepo = await GitListener.isGitRepository(); + Dashboard.postWebviewMessage({ command: command as any, payload: isRepo, requestId }); + } + /** * Run the sync */ diff --git a/src/localization/localization.enum.ts b/src/localization/localization.enum.ts index 8fac4179..bcc85994 100644 --- a/src/localization/localization.enum.ts +++ b/src/localization/localization.enum.ts @@ -191,6 +191,14 @@ export enum LocalizationKey { * Run full diagnostics */ settingsDiagnosticLink = 'settings.diagnostic.link', + /** + * Git synchronization + */ + settingsGitEnabled = 'settings.git.enabled', + /** + * Enable Git synchronization to easily sync your changes with your repository. + */ + settingsGitEnabledDescription = 'settings.git.enabled.description', /** * Website and SSG settings */ @@ -919,6 +927,14 @@ export enum LocalizationKey { * Now that Front Matter knows all the content folders. Would you like to import all tags and categories from the available content? */ dashboardStepsStepsToGetStartedTagsDescription = 'dashboard.steps.stepsToGetStarted.tags.description', + /** + * Do you want to enable Git synchronization? + */ + dashboardStepsStepsToGetStartedGitName = 'dashboard.steps.stepsToGetStarted.git.name', + /** + * Enable Git synchronization to eaily sync your changes with your repository. + */ + dashboardStepsStepsToGetStartedGitDescription = 'dashboard.steps.stepsToGetStarted.git.description', /** * Show the dashboard */