refactor: rename "dark mode" iframe message to "additional configuration"

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2023-04-11 17:00:20 +02:00
parent 1e9e04f829
commit 6c55da4e79
4 changed files with 19 additions and 18 deletions

View file

@ -10,12 +10,12 @@ import { CommunicationMessageType } from '../../../render-page/window-post-messa
import { useMemo } from 'react' import { useMemo } from 'react'
/** /**
* Sends the current dark mode setting to the renderer. * Sends additional configuration options (dark mode, line break, etc.) to the renderer.
* *
* @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
* @param forcedDarkMode Overwrites the value from the global application states if set.
*/ */
export const useSendDarkModeStatusToRenderer = ( export const useSendAdditionalConfigurationToRenderer = (
rendererReady: boolean, rendererReady: boolean,
forcedDarkMode: DarkModePreference = DarkModePreference.AUTO forcedDarkMode: DarkModePreference = DarkModePreference.AUTO
): void => { ): void => {
@ -28,8 +28,8 @@ export const useSendDarkModeStatusToRenderer = (
useSendToRenderer( useSendToRenderer(
useMemo( useMemo(
() => ({ () => ({
type: CommunicationMessageType.SET_DARKMODE, type: CommunicationMessageType.SET_ADDITIONAL_CONFIGURATION,
preference: darkMode darkModePreference: darkMode
}), }),
[darkMode] [darkMode]
), ),

View file

@ -22,7 +22,7 @@ import { CommunicationMessageType } from '../../render-page/window-post-message-
import { useEditorToRendererCommunicator } from '../render-context/editor-to-renderer-communicator-context-provider' import { useEditorToRendererCommunicator } from '../render-context/editor-to-renderer-communicator-context-provider'
import { useEffectOnRenderTypeChange } from './hooks/use-effect-on-render-type-change' import { useEffectOnRenderTypeChange } from './hooks/use-effect-on-render-type-change'
import { useForceRenderPageUrlOnIframeLoadCallback } from './hooks/use-force-render-page-url-on-iframe-load-callback' import { useForceRenderPageUrlOnIframeLoadCallback } from './hooks/use-force-render-page-url-on-iframe-load-callback'
import { useSendDarkModeStatusToRenderer } from './hooks/use-send-dark-mode-status-to-renderer' import { useSendAdditionalConfigurationToRenderer } from './hooks/use-send-additional-configuration-to-renderer'
import { useSendMarkdownToRenderer } from './hooks/use-send-markdown-to-renderer' import { useSendMarkdownToRenderer } from './hooks/use-send-markdown-to-renderer'
import { useSendScrollState } from './hooks/use-send-scroll-state' import { useSendScrollState } from './hooks/use-send-scroll-state'
import React, { Fragment, useCallback, useEffect, useMemo, useRef, useState } from 'react' import React, { Fragment, useCallback, useEffect, useMemo, useRef, useState } from 'react'
@ -145,7 +145,7 @@ export const RenderIframe: React.FC<RenderIframeProps> = ({
) )
useEffectOnRenderTypeChange(rendererType, onIframeLoad) useEffectOnRenderTypeChange(rendererType, onIframeLoad)
useSendDarkModeStatusToRenderer(rendererReady, forcedDarkMode) useSendAdditionalConfigurationToRenderer(rendererReady, forcedDarkMode)
useSendMarkdownToRenderer(markdownContentLines, rendererReady) useSendMarkdownToRenderer(markdownContentLines, rendererReady)
useSendScrollState(scrollState, rendererReady) useSendScrollState(scrollState, rendererReady)

View file

@ -53,8 +53,8 @@ export const IframeMarkdownRenderer: React.FC = () => {
) )
useRendererReceiveHandler( useRendererReceiveHandler(
CommunicationMessageType.SET_DARKMODE, CommunicationMessageType.SET_ADDITIONAL_CONFIGURATION,
useCallback((values) => setDarkModePreference(values.preference), []) useCallback((values) => setDarkModePreference(values.darkModePreference), [])
) )
useRendererReceiveHandler( useRendererReceiveHandler(

View file

@ -3,14 +3,15 @@
* *
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import type { DarkModePreference } from '../../../redux/dark-mode/types' import type { DarkModePreference } from '../../../redux/dark-mode/types';
import type { ScrollState } from '../../editor-page/synced-scroll/scroll-props' import type { ScrollState } from '../../editor-page/synced-scroll/scroll-props';
import type { SlideOptions } from '@hedgedoc/commons' import type { SlideOptions } from '@hedgedoc/commons';
export enum CommunicationMessageType { export enum CommunicationMessageType {
SET_MARKDOWN_CONTENT = 'SET_MARKDOWN_CONTENT', SET_MARKDOWN_CONTENT = 'SET_MARKDOWN_CONTENT',
RENDERER_READY = 'RENDERER_READY', RENDERER_READY = 'RENDERER_READY',
SET_DARKMODE = 'SET_DARKMODE', SET_ADDITIONAL_CONFIGURATION = 'SET_ADDITIONAL_CONFIGURATION',
ENABLE_RENDERER_SCROLL_SOURCE = 'ENABLE_RENDERER_SCROLL_SOURCE', ENABLE_RENDERER_SCROLL_SOURCE = 'ENABLE_RENDERER_SCROLL_SOURCE',
DISABLE_RENDERER_SCROLL_SOURCE = 'DISABLE_RENDERER_SCROLL_SOURCE', DISABLE_RENDERER_SCROLL_SOURCE = 'DISABLE_RENDERER_SCROLL_SOURCE',
SET_SCROLL_STATE = 'SET_SCROLL_STATE', SET_SCROLL_STATE = 'SET_SCROLL_STATE',
@ -27,9 +28,9 @@ export interface NoPayloadMessage<TYPE extends CommunicationMessageType> {
type: TYPE type: TYPE
} }
export interface SetDarkModeMessage { export interface SetAdditionalConfigurationMessage {
type: CommunicationMessageType.SET_DARKMODE type: CommunicationMessageType.SET_ADDITIONAL_CONFIGURATION
preference: DarkModePreference darkModePreference: DarkModePreference
} }
export interface ExtensionEvent { export interface ExtensionEvent {
@ -90,7 +91,7 @@ export type CommunicationMessages =
| NoPayloadMessage<CommunicationMessageType.RENDERER_READY> | NoPayloadMessage<CommunicationMessageType.RENDERER_READY>
| NoPayloadMessage<CommunicationMessageType.ENABLE_RENDERER_SCROLL_SOURCE> | NoPayloadMessage<CommunicationMessageType.ENABLE_RENDERER_SCROLL_SOURCE>
| NoPayloadMessage<CommunicationMessageType.DISABLE_RENDERER_SCROLL_SOURCE> | NoPayloadMessage<CommunicationMessageType.DISABLE_RENDERER_SCROLL_SOURCE>
| SetDarkModeMessage | SetAdditionalConfigurationMessage
| SetBaseUrlMessage | SetBaseUrlMessage
| GetWordCountMessage | GetWordCountMessage
| SetMarkdownContentMessage | SetMarkdownContentMessage
@ -103,7 +104,7 @@ export type CommunicationMessages =
export type EditorToRendererMessageType = export type EditorToRendererMessageType =
| CommunicationMessageType.SET_MARKDOWN_CONTENT | CommunicationMessageType.SET_MARKDOWN_CONTENT
| CommunicationMessageType.SET_DARKMODE | CommunicationMessageType.SET_ADDITIONAL_CONFIGURATION
| CommunicationMessageType.SET_SCROLL_STATE | CommunicationMessageType.SET_SCROLL_STATE
| CommunicationMessageType.SET_BASE_CONFIGURATION | CommunicationMessageType.SET_BASE_CONFIGURATION
| CommunicationMessageType.GET_WORD_COUNT | CommunicationMessageType.GET_WORD_COUNT