From 598c27c7cb7081a86ebb7fb82fd942da64ba5d90 Mon Sep 17 00:00:00 2001 From: Peter Zimon Date: Tue, 8 Oct 2024 15:59:28 +0100 Subject: [PATCH] Moved themes out of design settings --- .../src/global/chrome/DesktopChrome.tsx | 2 +- .../src/global/layout/PageHeader.tsx | 2 +- .../src/components/Sidebar.tsx | 1 + .../components/settings/site/ChangeTheme.tsx | 24 +++++++ .../components/settings/site/SiteSettings.tsx | 3 + .../components/settings/site/ThemeModal.tsx | 69 +++++++------------ .../settings/site/theme/ThemePreview.tsx | 4 +- 7 files changed, 54 insertions(+), 51 deletions(-) create mode 100644 apps/admin-x-settings/src/components/settings/site/ChangeTheme.tsx diff --git a/apps/admin-x-design-system/src/global/chrome/DesktopChrome.tsx b/apps/admin-x-design-system/src/global/chrome/DesktopChrome.tsx index 223385f905..af408d4aaf 100644 --- a/apps/admin-x-design-system/src/global/chrome/DesktopChrome.tsx +++ b/apps/admin-x-design-system/src/global/chrome/DesktopChrome.tsx @@ -6,7 +6,7 @@ export interface DesktopChromeProps { const DesktopChrome: React.FC> = ({children, ...props}) => { return ( -
+
{children}
diff --git a/apps/admin-x-design-system/src/global/layout/PageHeader.tsx b/apps/admin-x-design-system/src/global/layout/PageHeader.tsx index 8ccbd7745c..43bbd50c2c 100644 --- a/apps/admin-x-design-system/src/global/layout/PageHeader.tsx +++ b/apps/admin-x-design-system/src/global/layout/PageHeader.tsx @@ -28,7 +28,7 @@ const PageHeader: React.FC = ({ children }) => { const containerClasses = clsx( - 'z-50 h-22 min-h-[92px] p-8 px-6 tablet:px-12', + 'z-50 h-22 min-h-[92px] p-8', !children && 'flex items-center justify-between gap-3', sticky && 'sticky top-0', containerClassName diff --git a/apps/admin-x-settings/src/components/Sidebar.tsx b/apps/admin-x-settings/src/components/Sidebar.tsx index 18631f21fa..3574dd20b5 100644 --- a/apps/admin-x-settings/src/components/Sidebar.tsx +++ b/apps/admin-x-settings/src/components/Sidebar.tsx @@ -167,6 +167,7 @@ const Sidebar: React.FC = () => { + diff --git a/apps/admin-x-settings/src/components/settings/site/ChangeTheme.tsx b/apps/admin-x-settings/src/components/settings/site/ChangeTheme.tsx new file mode 100644 index 0000000000..cab6713350 --- /dev/null +++ b/apps/admin-x-settings/src/components/settings/site/ChangeTheme.tsx @@ -0,0 +1,24 @@ +import React from 'react'; +import TopLevelGroup from '../../TopLevelGroup'; +import {Button, withErrorBoundary} from '@tryghost/admin-x-design-system'; +import {useRouting} from '@tryghost/admin-x-framework/routing'; + +const ChangeTheme: React.FC<{ keywords: string[] }> = ({keywords}) => { + const {updateRoute} = useRouting(); + const openPreviewModal = () => { + updateRoute('design/change-theme'); + }; + + return ( + } + description="Browse and install official themes or upload one" + keywords={keywords} + navid='theme' + testId='theme' + title="Change theme" + /> + ); +}; + +export default withErrorBoundary(ChangeTheme, 'Branding and design'); diff --git a/apps/admin-x-settings/src/components/settings/site/SiteSettings.tsx b/apps/admin-x-settings/src/components/settings/site/SiteSettings.tsx index 0daaa1ae54..bb71dd7493 100644 --- a/apps/admin-x-settings/src/components/settings/site/SiteSettings.tsx +++ b/apps/admin-x-settings/src/components/settings/site/SiteSettings.tsx @@ -1,4 +1,5 @@ import AnnouncementBar from './AnnouncementBar'; +import ChangeTheme from './ChangeTheme'; import DesignSetting from './DesignSetting'; import Navigation from './Navigation'; import React from 'react'; @@ -6,6 +7,7 @@ import SearchableSection from '../../SearchableSection'; export const searchKeywords = { design: ['site', 'logo', 'cover', 'colors', 'fonts', 'background', 'themes', 'appearance', 'style', 'design & branding', 'design and branding'], + theme: ['theme', 'template', 'upload'], navigation: ['site', 'navigation', 'menus', 'primary', 'secondary', 'links'], announcementBar: ['site', 'announcement bar', 'important', 'banner'] }; @@ -15,6 +17,7 @@ const SiteSettings: React.FC = () => { <> + diff --git a/apps/admin-x-settings/src/components/settings/site/ThemeModal.tsx b/apps/admin-x-settings/src/components/settings/site/ThemeModal.tsx index 59bbe85229..c79bb4c655 100644 --- a/apps/admin-x-settings/src/components/settings/site/ThemeModal.tsx +++ b/apps/admin-x-settings/src/components/settings/site/ThemeModal.tsx @@ -6,7 +6,7 @@ import React, {useEffect, useState} from 'react'; import ThemeInstalledModal from './theme/ThemeInstalledModal'; import ThemePreview from './theme/ThemePreview'; import useQueryParams from '../../../hooks/useQueryParams'; -import {Breadcrumbs, Button, ConfirmationModal, FileUpload, LimitModal, Modal, PageHeader, TabView, showToast} from '@tryghost/admin-x-design-system'; +import {Button, ConfirmationModal, FileUpload, LimitModal, Modal, PageHeader, TabView, showToast} from '@tryghost/admin-x-design-system'; import {HostLimitError, useLimiter} from '../../../hooks/useLimiter'; import {InstalledTheme, Theme, ThemesInstallResponseType, isDefaultOrLegacyTheme, useActivateTheme, useBrowseThemes, useInstallTheme, useUploadTheme} from '@tryghost/admin-x-framework/api/themes'; import {JSONError} from '@tryghost/admin-x-framework/errors'; @@ -54,11 +54,11 @@ const ThemeToolbar: React.FC = ({ setCurrentTab, themes }) => { + const modal = useModal(); const {updateRoute} = useRouting(); const {mutateAsync: uploadTheme} = useUploadTheme(); const limiter = useLimiter(); const handleError = useHandleError(); - const refParam = useQueryParams().getParam('ref'); const [uploadConfig, setUploadConfig] = useState<{enabled: boolean; error?: string}>(); @@ -80,11 +80,7 @@ const ThemeToolbar: React.FC = ({ }, [limiter]); const onClose = () => { - if (refParam) { - updateRoute(`design/edit?ref=${refParam}`); - } else { - updateRoute('design/edit'); - } + updateRoute('/'); }; const onThemeUpload = async (file: File) => { @@ -169,7 +165,7 @@ const ThemeToolbar: React.FC = ({ title, prompt, fatalErrors, - onRetry: async (modal) => { + onRetry: async () => { modal?.remove(); handleUpload(); } @@ -219,17 +215,18 @@ const ThemeToolbar: React.FC = ({ }; const left = - + ; + onTabChange={(id: string) => { + setCurrentTab(id); + }} /> +
; const handleUpload = () => { if (uploadConfig?.enabled) { @@ -250,19 +247,11 @@ const ThemeToolbar: React.FC = ({ const right =
-
- { - setCurrentTab(id); - }} /> -
+
; @@ -372,11 +361,7 @@ const ChangeThemeModal: React.FC = ({source, themeRef}) = }); } confirmModal?.remove(); - if (refParam) { - updateRoute(`design/edit?ref=${refParam}`); - } else { - updateRoute('design/edit'); - } + updateRoute(''); } catch (e) { handleError(e); } @@ -457,11 +442,7 @@ const ChangeThemeModal: React.FC = ({source, themeRef}) = prompt, installedTheme: installedTheme!, onActivate: () => { - if (refParam) { - updateRoute(`design/edit?ref=${refParam}`); - } else { - updateRoute('design/edit'); - } + updateRoute(''); } }); }; @@ -470,11 +451,7 @@ const ChangeThemeModal: React.FC = ({source, themeRef}) = return ( { - if (refParam) { - updateRoute(`design/edit?ref=${refParam}`); - } else { - updateRoute('design/edit'); - } + updateRoute(''); }} animate={false} cancelLabel='' @@ -500,7 +477,7 @@ const ChangeThemeModal: React.FC = ({source, themeRef}) = setSelectedTheme(null); }} onClose={() => { - updateRoute('design/edit'); + updateRoute(''); }} onInstall={onInstall} /> } diff --git a/apps/admin-x-settings/src/components/settings/site/theme/ThemePreview.tsx b/apps/admin-x-settings/src/components/settings/site/theme/ThemePreview.tsx index e730263a73..72318ff37f 100644 --- a/apps/admin-x-settings/src/components/settings/site/theme/ThemePreview.tsx +++ b/apps/admin-x-settings/src/components/settings/site/theme/ThemePreview.tsx @@ -34,7 +34,6 @@ const ThemePreview: React.FC<{ isInstalling, installedTheme, onBack, - onClose, onInstall }) => { const [previewMode, setPreviewMode] = useState('desktop'); @@ -101,7 +100,6 @@ const ThemePreview: React.FC<{ containerClassName='whitespace-nowrap' itemClassName='hidden md:!block md:!visible' items={[ - {label: 'Design', onClick: onClose}, {label: 'Change theme', onClick: onBack}, {label: selectedTheme.name} ]} @@ -163,7 +161,7 @@ const ThemePreview: React.FC<{ return (
-
+
{previewMode === 'desktop' ?