From 004fa936794ed82f29c0768e4eff47a2165dac38 Mon Sep 17 00:00:00 2001 From: Yuki Takei Date: Mon, 17 Apr 2023 10:20:00 +0000 Subject: [PATCH 1/3] omit useDrawioUri and inject data into RendererConfig --- .../src/components/PageEditor/DrawioModal.tsx | 16 +++++++------- .../components/Script/DrawioViewerScript.tsx | 22 ++++++++++++------- apps/app/src/interfaces/services/renderer.ts | 1 + apps/app/src/pages/[[...path]].page.tsx | 4 ++-- .../src/pages/_private-legacy-pages.page.tsx | 9 ++------ apps/app/src/pages/_search.page.tsx | 9 ++------ apps/app/src/pages/share/[[...path]].page.tsx | 4 ++-- apps/app/src/server/service/config-loader.ts | 2 +- apps/app/src/stores/context.tsx | 4 ---- 9 files changed, 32 insertions(+), 39 deletions(-) diff --git a/apps/app/src/components/PageEditor/DrawioModal.tsx b/apps/app/src/components/PageEditor/DrawioModal.tsx index 3770cf64429..0494663a7aa 100644 --- a/apps/app/src/components/PageEditor/DrawioModal.tsx +++ b/apps/app/src/components/PageEditor/DrawioModal.tsx @@ -10,7 +10,7 @@ import { } from 'reactstrap'; import { getDiagramsNetLangCode } from '~/client/util/locale-utils'; -import { useDrawioUri } from '~/stores/context'; +import { useRendererConfig } from '~/stores/context'; import { useDrawioModal } from '~/stores/modal'; import { usePersonalSettings } from '~/stores/personal-settings'; import loggerFactory from '~/utils/logger'; @@ -38,7 +38,7 @@ const drawioConfig: DrawioConfig = { export const DrawioModal = (): JSX.Element => { - const { data: drawioUri } = useDrawioUri(); + const { data: rendererConfig } = useRendererConfig(); const { data: personalSettingsInfo } = usePersonalSettings({ // make immutable revalidateIfStale: false, @@ -50,13 +50,13 @@ export const DrawioModal = (): JSX.Element => { const isOpened = drawioModalData?.isOpened ?? false; const drawioUriWithParams = useMemo(() => { - if (drawioUri == null) { + if (rendererConfig == null) { return undefined; } let url; try { - url = new URL(drawioUri); + url = new URL(rendererConfig.drawioUri); } catch (err) { logger.debug(err); @@ -71,19 +71,19 @@ export const DrawioModal = (): JSX.Element => { url.searchParams.append('configure', '1'); return url; - }, [drawioUri, personalSettingsInfo?.lang]); + }, [rendererConfig, personalSettingsInfo?.lang]); const drawioCommunicationHelper = useMemo(() => { - if (drawioUri == null) { + if (rendererConfig == null) { return undefined; } return new DrawioCommunicationHelper( - drawioUri, + rendererConfig.drawioUri, drawioConfig, { onClose: closeDrawioModal, onSave: drawioModalData?.onSave }, ); - }, [closeDrawioModal, drawioModalData?.onSave, drawioUri]); + }, [closeDrawioModal, drawioModalData?.onSave, rendererConfig]); const receiveMessageHandler = useCallback((event: MessageEvent) => { if (drawioModalData == null) { diff --git a/apps/app/src/components/Script/DrawioViewerScript.tsx b/apps/app/src/components/Script/DrawioViewerScript.tsx index 82e95f8a1b1..4cef052cec0 100644 --- a/apps/app/src/components/Script/DrawioViewerScript.tsx +++ b/apps/app/src/components/Script/DrawioViewerScript.tsx @@ -1,9 +1,9 @@ import { useCallback } from 'react'; import type { IGraphViewerGlobal } from '@growi/remark-drawio'; -import Script from 'next/script'; +import Head from 'next/head'; -import { useDrawioUri } from '~/stores/context'; +import { useRendererConfig } from '~/stores/context'; declare global { // eslint-disable-next-line vars-on-top, no-var @@ -11,7 +11,7 @@ declare global { } export const DrawioViewerScript = (): JSX.Element => { - const { data: drawioUri } = useDrawioUri(); + const { data: rendererConfig } = useRendererConfig(); const loadedHandler = useCallback(() => { // disable useResizeSensor and checkVisibleState @@ -32,11 +32,17 @@ export const DrawioViewerScript = (): JSX.Element => { GraphViewer.processElements(); }, []); + if (rendererConfig == null) { + return <>; + } + return ( -