mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-19 17:55:17 -04:00
Extract the render ready status into an extra redux state
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
568393eaab
commit
015a5cf496
10 changed files with 92 additions and 38 deletions
21
src/redux/renderer-status/methods.ts
Normal file
21
src/redux/renderer-status/methods.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { store } from '..'
|
||||
import { RendererStatusActionType, SetRendererStatusAction } from './types'
|
||||
|
||||
/**
|
||||
* Dispatches a global application state change for the "renderer ready" state.
|
||||
*
|
||||
* @param rendererReady The new renderer ready state.
|
||||
*/
|
||||
export const setRendererStatus = (rendererReady: boolean): void => {
|
||||
const action: SetRendererStatusAction = {
|
||||
type: RendererStatusActionType.SET_RENDERER_STATUS,
|
||||
rendererReady
|
||||
}
|
||||
store.dispatch(action)
|
||||
}
|
34
src/redux/renderer-status/reducers.ts
Normal file
34
src/redux/renderer-status/reducers.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { RendererStatus, RendererStatusActions, RendererStatusActionType } from './types'
|
||||
import { Reducer } from 'redux'
|
||||
|
||||
const initialState: RendererStatus = {
|
||||
rendererReady: false
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies {@link RendererStatusActions renderer status actions} to the global application state.
|
||||
*
|
||||
* @param state the current state
|
||||
* @param action the action that should get applied
|
||||
* @return The new changed state
|
||||
*/
|
||||
export const RendererStatusReducer: Reducer<RendererStatus, RendererStatusActions> = (
|
||||
state: RendererStatus = initialState,
|
||||
action: RendererStatusActions
|
||||
) => {
|
||||
switch (action.type) {
|
||||
case RendererStatusActionType.SET_RENDERER_STATUS:
|
||||
return {
|
||||
...state,
|
||||
rendererReady: action.rendererReady
|
||||
}
|
||||
default:
|
||||
return state
|
||||
}
|
||||
}
|
22
src/redux/renderer-status/types.ts
Normal file
22
src/redux/renderer-status/types.ts
Normal file
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { Action } from 'redux'
|
||||
|
||||
export enum RendererStatusActionType {
|
||||
SET_RENDERER_STATUS = 'renderer-status/set-ready'
|
||||
}
|
||||
|
||||
export interface RendererStatus {
|
||||
rendererReady: boolean
|
||||
}
|
||||
|
||||
export interface SetRendererStatusAction extends Action<RendererStatusActionType> {
|
||||
type: RendererStatusActionType.SET_RENDERER_STATUS
|
||||
rendererReady: boolean
|
||||
}
|
||||
|
||||
export type RendererStatusActions = SetRendererStatusAction
|
Loading…
Add table
Add a link
Reference in a new issue