mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 03:06:31 -05:00
fix: forced dark mode for iframe
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
0240f13f94
commit
ff11976868
3 changed files with 16 additions and 6 deletions
|
@ -4,6 +4,7 @@
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
import { useApplicationState } from '../../../../hooks/common/use-application-state'
|
import { useApplicationState } from '../../../../hooks/common/use-application-state'
|
||||||
|
import { DarkModePreference } from '../../../../redux/dark-mode/types'
|
||||||
import { useSendToRenderer } from '../../../render-page/window-post-message-communicator/hooks/use-send-to-renderer'
|
import { useSendToRenderer } from '../../../render-page/window-post-message-communicator/hooks/use-send-to-renderer'
|
||||||
import { CommunicationMessageType } from '../../../render-page/window-post-message-communicator/rendering-message'
|
import { CommunicationMessageType } from '../../../render-page/window-post-message-communicator/rendering-message'
|
||||||
import { useMemo } from 'react'
|
import { useMemo } from 'react'
|
||||||
|
@ -14,16 +15,23 @@ import { useMemo } from 'react'
|
||||||
* @param forcedDarkMode Overwrites the value from the global application states if set.
|
* @param forcedDarkMode Overwrites the value from the global application states if set.
|
||||||
* @param rendererReady Defines if the target renderer is ready
|
* @param rendererReady Defines if the target renderer is ready
|
||||||
*/
|
*/
|
||||||
export const useSendDarkModeStatusToRenderer = (forcedDarkMode: boolean | undefined, rendererReady: boolean): void => {
|
export const useSendDarkModeStatusToRenderer = (
|
||||||
|
rendererReady: boolean,
|
||||||
|
forcedDarkMode: DarkModePreference = DarkModePreference.AUTO
|
||||||
|
): void => {
|
||||||
const darkModePreference = useApplicationState((state) => state.darkMode.darkModePreference)
|
const darkModePreference = useApplicationState((state) => state.darkMode.darkModePreference)
|
||||||
|
|
||||||
|
const darkMode = useMemo(() => {
|
||||||
|
return forcedDarkMode === DarkModePreference.AUTO ? darkModePreference : forcedDarkMode
|
||||||
|
}, [darkModePreference, forcedDarkMode])
|
||||||
|
|
||||||
useSendToRenderer(
|
useSendToRenderer(
|
||||||
useMemo(
|
useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
type: CommunicationMessageType.SET_DARKMODE,
|
type: CommunicationMessageType.SET_DARKMODE,
|
||||||
preference: darkModePreference
|
preference: darkMode
|
||||||
}),
|
}),
|
||||||
[darkModePreference]
|
[darkMode]
|
||||||
),
|
),
|
||||||
rendererReady
|
rendererReady
|
||||||
)
|
)
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
import type { DarkModePreference } from '../../../redux/dark-mode/types'
|
||||||
import { cypressAttribute, cypressId } from '../../../utils/cypress-attribute'
|
import { cypressAttribute, cypressId } from '../../../utils/cypress-attribute'
|
||||||
import { Logger } from '../../../utils/logger'
|
import { Logger } from '../../../utils/logger'
|
||||||
import { isTestMode } from '../../../utils/test-modes'
|
import { isTestMode } from '../../../utils/test-modes'
|
||||||
|
@ -28,7 +29,7 @@ import React, { Fragment, useCallback, useEffect, useMemo, useRef, useState } fr
|
||||||
|
|
||||||
export interface RenderIframeProps extends RendererProps {
|
export interface RenderIframeProps extends RendererProps {
|
||||||
rendererType: RendererType
|
rendererType: RendererType
|
||||||
forcedDarkMode?: boolean
|
forcedDarkMode?: DarkModePreference
|
||||||
frameClasses?: string
|
frameClasses?: string
|
||||||
onRendererStatusChange?: undefined | ((rendererReady: boolean) => void)
|
onRendererStatusChange?: undefined | ((rendererReady: boolean) => void)
|
||||||
adaptFrameHeightToContent?: boolean
|
adaptFrameHeightToContent?: boolean
|
||||||
|
@ -144,7 +145,7 @@ export const RenderIframe: React.FC<RenderIframeProps> = ({
|
||||||
)
|
)
|
||||||
|
|
||||||
useEffectOnRenderTypeChange(rendererType, onIframeLoad)
|
useEffectOnRenderTypeChange(rendererType, onIframeLoad)
|
||||||
useSendDarkModeStatusToRenderer(forcedDarkMode, rendererReady)
|
useSendDarkModeStatusToRenderer(rendererReady, forcedDarkMode)
|
||||||
useSendMarkdownToRenderer(markdownContentLines, rendererReady)
|
useSendMarkdownToRenderer(markdownContentLines, rendererReady)
|
||||||
useSendScrollState(scrollState, rendererReady)
|
useSendScrollState(scrollState, rendererReady)
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
import { DarkModePreference } from '../../redux/dark-mode/types'
|
||||||
import { Logger } from '../../utils/logger'
|
import { Logger } from '../../utils/logger'
|
||||||
import { AsyncLoadingBoundary } from '../common/async-loading-boundary/async-loading-boundary'
|
import { AsyncLoadingBoundary } from '../common/async-loading-boundary/async-loading-boundary'
|
||||||
import { RenderIframe } from '../editor-page/renderer-pane/render-iframe'
|
import { RenderIframe } from '../editor-page/renderer-pane/render-iframe'
|
||||||
|
@ -31,7 +32,7 @@ export const IntroCustomContent: React.FC = () => {
|
||||||
frameClasses={'w-100 overflow-y-hidden'}
|
frameClasses={'w-100 overflow-y-hidden'}
|
||||||
markdownContentLines={value as string[]}
|
markdownContentLines={value as string[]}
|
||||||
rendererType={RendererType.SIMPLE}
|
rendererType={RendererType.SIMPLE}
|
||||||
forcedDarkMode={true}
|
forcedDarkMode={DarkModePreference.DARK}
|
||||||
adaptFrameHeightToContent={true}
|
adaptFrameHeightToContent={true}
|
||||||
/>
|
/>
|
||||||
</AsyncLoadingBoundary>
|
</AsyncLoadingBoundary>
|
||||||
|
|
Loading…
Reference in a new issue