mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-24 18:56:32 -05:00
refactor: rename "dark mode" iframe message to "additional configuration"
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
ff11976868
commit
9aa0363359
4 changed files with 19 additions and 18 deletions
|
@ -10,12 +10,12 @@ import { CommunicationMessageType } from '../../../render-page/window-post-messa
|
|||
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 forcedDarkMode Overwrites the value from the global application states if set.
|
||||
*/
|
||||
export const useSendDarkModeStatusToRenderer = (
|
||||
export const useSendAdditionalConfigurationToRenderer = (
|
||||
rendererReady: boolean,
|
||||
forcedDarkMode: DarkModePreference = DarkModePreference.AUTO
|
||||
): void => {
|
||||
|
@ -28,8 +28,8 @@ export const useSendDarkModeStatusToRenderer = (
|
|||
useSendToRenderer(
|
||||
useMemo(
|
||||
() => ({
|
||||
type: CommunicationMessageType.SET_DARKMODE,
|
||||
preference: darkMode
|
||||
type: CommunicationMessageType.SET_ADDITIONAL_CONFIGURATION,
|
||||
darkModePreference: darkMode
|
||||
}),
|
||||
[darkMode]
|
||||
),
|
|
@ -22,7 +22,7 @@ import { CommunicationMessageType } from '../../render-page/window-post-message-
|
|||
import { useEditorToRendererCommunicator } from '../render-context/editor-to-renderer-communicator-context-provider'
|
||||
import { useEffectOnRenderTypeChange } from './hooks/use-effect-on-render-type-change'
|
||||
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 { useSendScrollState } from './hooks/use-send-scroll-state'
|
||||
import React, { Fragment, useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||
|
@ -145,7 +145,7 @@ export const RenderIframe: React.FC<RenderIframeProps> = ({
|
|||
)
|
||||
|
||||
useEffectOnRenderTypeChange(rendererType, onIframeLoad)
|
||||
useSendDarkModeStatusToRenderer(rendererReady, forcedDarkMode)
|
||||
useSendAdditionalConfigurationToRenderer(rendererReady, forcedDarkMode)
|
||||
useSendMarkdownToRenderer(markdownContentLines, rendererReady)
|
||||
useSendScrollState(scrollState, rendererReady)
|
||||
|
||||
|
|
|
@ -53,8 +53,8 @@ export const IframeMarkdownRenderer: React.FC = () => {
|
|||
)
|
||||
|
||||
useRendererReceiveHandler(
|
||||
CommunicationMessageType.SET_DARKMODE,
|
||||
useCallback((values) => setDarkModePreference(values.preference), [])
|
||||
CommunicationMessageType.SET_ADDITIONAL_CONFIGURATION,
|
||||
useCallback((values) => setDarkModePreference(values.darkModePreference), [])
|
||||
)
|
||||
|
||||
useRendererReceiveHandler(
|
||||
|
|
|
@ -3,14 +3,15 @@
|
|||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import type { DarkModePreference } from '../../../redux/dark-mode/types'
|
||||
import type { ScrollState } from '../../editor-page/synced-scroll/scroll-props'
|
||||
import type { SlideOptions } from '@hedgedoc/commons'
|
||||
import type { DarkModePreference } from '../../../redux/dark-mode/types';
|
||||
import type { ScrollState } from '../../editor-page/synced-scroll/scroll-props';
|
||||
import type { SlideOptions } from '@hedgedoc/commons';
|
||||
|
||||
|
||||
export enum CommunicationMessageType {
|
||||
SET_MARKDOWN_CONTENT = 'SET_MARKDOWN_CONTENT',
|
||||
RENDERER_READY = 'RENDERER_READY',
|
||||
SET_DARKMODE = 'SET_DARKMODE',
|
||||
SET_ADDITIONAL_CONFIGURATION = 'SET_ADDITIONAL_CONFIGURATION',
|
||||
ENABLE_RENDERER_SCROLL_SOURCE = 'ENABLE_RENDERER_SCROLL_SOURCE',
|
||||
DISABLE_RENDERER_SCROLL_SOURCE = 'DISABLE_RENDERER_SCROLL_SOURCE',
|
||||
SET_SCROLL_STATE = 'SET_SCROLL_STATE',
|
||||
|
@ -27,9 +28,9 @@ export interface NoPayloadMessage<TYPE extends CommunicationMessageType> {
|
|||
type: TYPE
|
||||
}
|
||||
|
||||
export interface SetDarkModeMessage {
|
||||
type: CommunicationMessageType.SET_DARKMODE
|
||||
preference: DarkModePreference
|
||||
export interface SetAdditionalConfigurationMessage {
|
||||
type: CommunicationMessageType.SET_ADDITIONAL_CONFIGURATION
|
||||
darkModePreference: DarkModePreference
|
||||
}
|
||||
|
||||
export interface ExtensionEvent {
|
||||
|
@ -90,7 +91,7 @@ export type CommunicationMessages =
|
|||
| NoPayloadMessage<CommunicationMessageType.RENDERER_READY>
|
||||
| NoPayloadMessage<CommunicationMessageType.ENABLE_RENDERER_SCROLL_SOURCE>
|
||||
| NoPayloadMessage<CommunicationMessageType.DISABLE_RENDERER_SCROLL_SOURCE>
|
||||
| SetDarkModeMessage
|
||||
| SetAdditionalConfigurationMessage
|
||||
| SetBaseUrlMessage
|
||||
| GetWordCountMessage
|
||||
| SetMarkdownContentMessage
|
||||
|
@ -103,7 +104,7 @@ export type CommunicationMessages =
|
|||
|
||||
export type EditorToRendererMessageType =
|
||||
| CommunicationMessageType.SET_MARKDOWN_CONTENT
|
||||
| CommunicationMessageType.SET_DARKMODE
|
||||
| CommunicationMessageType.SET_ADDITIONAL_CONFIGURATION
|
||||
| CommunicationMessageType.SET_SCROLL_STATE
|
||||
| CommunicationMessageType.SET_BASE_CONFIGURATION
|
||||
| CommunicationMessageType.GET_WORD_COUNT
|
||||
|
|
Loading…
Reference in a new issue