From e910491a3cdaa9096877a5d774eb431994eaaa3e Mon Sep 17 00:00:00 2001 From: yyorkchan Date: Fri, 16 Aug 2024 15:43:52 +0800 Subject: [PATCH 1/6] Make design theme customization update class instead of url param --- authui/src/inline-preview.ts | 5 +++++ portal/src/graphql/portal/DesignScreen/DesignScreen.tsx | 1 - portal/src/graphql/portal/DesignScreen/viewModel.ts | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/authui/src/inline-preview.ts b/authui/src/inline-preview.ts index a3828d1d5b..06f0e37d59 100644 --- a/authui/src/inline-preview.ts +++ b/authui/src/inline-preview.ts @@ -3,6 +3,7 @@ import { PreviewableResourceController } from "./previewable-resource"; import { injectCSSAttrs } from "./cssattrs"; interface PreviewCustomisationMessage { + theme: string; cssVars: Record; images: Record; translations: Record; @@ -15,6 +16,7 @@ function parsePreviewCustomisationMessage( return null; } return { + theme: message.theme ?? "", cssVars: message.cssVars ?? {}, images: message.images ?? {}, translations: message.translations ?? {}, @@ -89,6 +91,9 @@ export class InlinePreviewController extends Controller { outlet?.setValue(value); } + el.classList.remove("light", "dark", "auto"); + el.setAttribute("class", customisationMessage.theme); + injectCSSAttrs(document.documentElement); }; } diff --git a/portal/src/graphql/portal/DesignScreen/DesignScreen.tsx b/portal/src/graphql/portal/DesignScreen/DesignScreen.tsx index bcd3f16980..ca480c1683 100644 --- a/portal/src/graphql/portal/DesignScreen/DesignScreen.tsx +++ b/portal/src/graphql/portal/DesignScreen/DesignScreen.tsx @@ -834,7 +834,6 @@ const Preview: React.VFC = function Preview(props) { const src = useMemo(() => { const url = new URL(effectiveAppConfig.http?.public_origin ?? ""); url.pathname = selectedPreviewPage; - url.searchParams.append("x_color_scheme", designForm.state.selectedTheme); url.searchParams.append("ui_locales", designForm.state.selectedLanguage); return url.toString(); }, [ diff --git a/portal/src/graphql/portal/DesignScreen/viewModel.ts b/portal/src/graphql/portal/DesignScreen/viewModel.ts index fbbccae311..f2c47d0c77 100644 --- a/portal/src/graphql/portal/DesignScreen/viewModel.ts +++ b/portal/src/graphql/portal/DesignScreen/viewModel.ts @@ -59,6 +59,7 @@ export function getSupportedPreviewPagesFromConfig( export interface PreviewCustomisationMessage { type: "PreviewCustomisationMessage"; + theme: string; cssVars: Record; images: Record; translations: Record; @@ -123,6 +124,8 @@ export function mapDesignFormStateToPreviewCustomisationMessage( } } + const theme = state.selectedTheme; + cssVars[CSSVariable.WatermarkDisplay] = state.showAuthgearLogo ? WatermarkEnabledDisplay : WatermarkDisabledDisplay; @@ -142,6 +145,7 @@ export function mapDesignFormStateToPreviewCustomisationMessage( return { type: "PreviewCustomisationMessage", + theme, cssVars, images, translations, From d4b21158a5373b3a20dbc0b7012750f26c3ebc96 Mon Sep 17 00:00:00 2001 From: yyorkchan Date: Fri, 16 Aug 2024 15:44:09 +0800 Subject: [PATCH 2/6] Add loading state when preview is pending change selectedPreviewPage --- portal/src/graphql/portal/DesignScreen/DesignScreen.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/portal/src/graphql/portal/DesignScreen/DesignScreen.tsx b/portal/src/graphql/portal/DesignScreen/DesignScreen.tsx index ca480c1683..1dcb54d90e 100644 --- a/portal/src/graphql/portal/DesignScreen/DesignScreen.tsx +++ b/portal/src/graphql/portal/DesignScreen/DesignScreen.tsx @@ -797,6 +797,8 @@ const Preview: React.VFC = function Preview(props) { const authUIIframeRef = useRef(null); + const [isIframeLoading, setIsIframeLoading] = useState(true); + useEffect(() => { const message = mapDesignFormStateToPreviewCustomisationMessage( designForm.state @@ -827,6 +829,7 @@ const Preview: React.VFC = function Preview(props) { return; } setSelectedPreviewPage(option.key as PreviewPage); + setIsIframeLoading(true); }, [] ); @@ -839,7 +842,6 @@ const Preview: React.VFC = function Preview(props) { }, [ effectiveAppConfig.http?.public_origin, designForm.state.selectedLanguage, - designForm.state.selectedTheme, selectedPreviewPage, ]); @@ -847,6 +849,7 @@ const Preview: React.VFC = function Preview(props) { const message = mapDesignFormStateToPreviewCustomisationMessage( designForm.state ); + setIsIframeLoading(false); authUIIframeRef.current?.contentWindow?.postMessage(message, "*"); }, [designForm.state]); @@ -881,6 +884,7 @@ const Preview: React.VFC = function Preview(props) { /> ) : null} + {isIframeLoading ? : null}