mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-24 18:56:32 -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
|
||||
*/
|
||||
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 { CommunicationMessageType } from '../../../render-page/window-post-message-communicator/rendering-message'
|
||||
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 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 darkMode = useMemo(() => {
|
||||
return forcedDarkMode === DarkModePreference.AUTO ? darkModePreference : forcedDarkMode
|
||||
}, [darkModePreference, forcedDarkMode])
|
||||
|
||||
useSendToRenderer(
|
||||
useMemo(
|
||||
() => ({
|
||||
type: CommunicationMessageType.SET_DARKMODE,
|
||||
preference: darkModePreference
|
||||
preference: darkMode
|
||||
}),
|
||||
[darkModePreference]
|
||||
[darkMode]
|
||||
),
|
||||
rendererReady
|
||||
)
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import type { DarkModePreference } from '../../../redux/dark-mode/types'
|
||||
import { cypressAttribute, cypressId } from '../../../utils/cypress-attribute'
|
||||
import { Logger } from '../../../utils/logger'
|
||||
import { isTestMode } from '../../../utils/test-modes'
|
||||
|
@ -28,7 +29,7 @@ import React, { Fragment, useCallback, useEffect, useMemo, useRef, useState } fr
|
|||
|
||||
export interface RenderIframeProps extends RendererProps {
|
||||
rendererType: RendererType
|
||||
forcedDarkMode?: boolean
|
||||
forcedDarkMode?: DarkModePreference
|
||||
frameClasses?: string
|
||||
onRendererStatusChange?: undefined | ((rendererReady: boolean) => void)
|
||||
adaptFrameHeightToContent?: boolean
|
||||
|
@ -144,7 +145,7 @@ export const RenderIframe: React.FC<RenderIframeProps> = ({
|
|||
)
|
||||
|
||||
useEffectOnRenderTypeChange(rendererType, onIframeLoad)
|
||||
useSendDarkModeStatusToRenderer(forcedDarkMode, rendererReady)
|
||||
useSendDarkModeStatusToRenderer(rendererReady, forcedDarkMode)
|
||||
useSendMarkdownToRenderer(markdownContentLines, rendererReady)
|
||||
useSendScrollState(scrollState, rendererReady)
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import { DarkModePreference } from '../../redux/dark-mode/types'
|
||||
import { Logger } from '../../utils/logger'
|
||||
import { AsyncLoadingBoundary } from '../common/async-loading-boundary/async-loading-boundary'
|
||||
import { RenderIframe } from '../editor-page/renderer-pane/render-iframe'
|
||||
|
@ -31,7 +32,7 @@ export const IntroCustomContent: React.FC = () => {
|
|||
frameClasses={'w-100 overflow-y-hidden'}
|
||||
markdownContentLines={value as string[]}
|
||||
rendererType={RendererType.SIMPLE}
|
||||
forcedDarkMode={true}
|
||||
forcedDarkMode={DarkModePreference.DARK}
|
||||
adaptFrameHeightToContent={true}
|
||||
/>
|
||||
</AsyncLoadingBoundary>
|
||||
|
|
Loading…
Reference in a new issue